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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
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

This note was uploaded on 11/23/2010 for the course MATH 104b taught by Professor Ceniceros,h during the Spring '08 term at UCSB.

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 Right Arrow Icon
Ask a homework question - tutors are online