{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

parsing

# parsing - PARSING ALGORITHMS FOR LL PARSERS Table-driven...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PARSING ALGORITHMS FOR LL PARSERS Table-driven predictive parsing algorithm (for LL parsers) Input: A string of tokens and a parsing table M for grammar G . ( S denotes the start symbol of grammar G , and \$ denotes the end-of-file symbol) push(\$); push( S ); lookahead = get next token(); repeat X = top of stack(); if ( X is a terminal or X == \$) then if ( X == lookahead) then pop( X ); lookahead = get next token(); else error(); else /* X is a non-terminal */ if ( M [ X ,lookahead] == X → Y 1 Y 2 ··· Y k ) then pop( X ); push( Y k ); push( Y k − 1 ); ··· ; push( Y 1 ); else error(); until ( X == \$) The FIRST set construction To build FIRST( X ) for all grammar symbols X , apply the following rules until no more terminals or ǫ can be added to any FIRST set: 1. if X is a terminal, FIRST( X ) is { X } 2. if X → ǫ is a production then add ǫ to FIRST( X ) 3. if X is a nonterminal and X → Y 1 Y 2 ··· Y k is a production then put every symbol in FIRST( Y 1 ) other than ǫ to FIRST( X ) 4. if X is a non-terminal and X → Y 1 Y 2 ··· Y k is a production, then put terminal a in FIRST( X ) if a is in FIRST( Y i ) and ǫ is in FIRST( Y j ) for all 1 ≤ j < i 5. if X is a non-terminal and X → Y 1 Y 2 ··· Y k is a production, then put ǫ to FIRST( X ) if ǫ...
View Full Document

{[ snackBarMessage ]}

### Page1 / 6

parsing - PARSING ALGORITHMS FOR LL PARSERS Table-driven...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online