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
Unformatted text preview: PARSING ALGORITHMS FOR LL PARSERS Tabledriven 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 endoffile 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 nonterminal */ 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 nonterminal 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 nonterminal 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.
 Spring '08
 Ceniceros,H
 Numerical Analysis

Click to edit the document details