0% found this document useful (0 votes)
13 views1 page

Compiler Design (All Modules) - 12

Uploaded by

ag2896323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Compiler Design (All Modules) - 12

Uploaded by

ag2896323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

 Parsers analyze code structure based on grammar rules.

 Top-down parsers start from the start symbol and work their way down, matching code elements against
grammar productions.
 Starts from the top (start symbol) of a grammar that defines the valid structures of the language (like a
programming language).
 Works its way down, matching the code elements (tokens) against the grammar's production rules.
 Imagine checking if a sentence follows grammar rules (subject-verb-object) by starting with the entire sentence
and verifying its components.

3. Recursive Descent Parsing:

 A widely used top-down parsing technique.


 Each non-terminal has a corresponding function that:
o Checks if the current code sequence matches the production rule associated with the non-terminal.
o If yes, it recursively calls functions for other non-terminals in the production rule, moving down the
parse tree.
o If not, an error is reported.

Key Points (Recursive Descent Parsing):

 Simple and intuitive approach.


 Can be inefficient for complex grammars due to redundant function calls.
 Error handling can be challenging.

4. Predictive Parsing:

 A special type of top-down parsing with more efficiency.


 Uses a parsing table to predict the next grammar rule based on the current token and lookahead symbols (limited
number of tokens following the current one).
 If a prediction can't be made, an error occurs.

Key Points (Predictive Parsing):

 Faster than recursive descent parsing for certain grammars.


 Requires a more complex parsing table generation process.
 Not all CFGs can be parsed predictively.

Q4: Bottom up Parsing

Ans: Bottom Up Parsing

Bottom-up parsing, another key technique in parsers, takes a different approach to analyzing code structure compared to
top-down parsing. Here's a breakdown of the key concepts:

Basic Idea:

 Starts from the bottom (tokens) and works its way up, combining tokens into larger structures according to
grammar rules.
 Imagine building a house brick by brick, following a blueprint (grammar) to create the final structure.

Shift-Reduce Parsing:

 Uses a stack and a parser table.


 Shift: When a token matches the expected token in the current parsing state, it's shifted onto the stack (like
adding a brick).

You might also like