Parsing with an LL(1) Push-down Automaton

 

 

Current token = GET Next Token                        // from lexical analyzer

SET Parse Stack TO Empty stack;
PUSH ENDOFFILE and Start symbol ON Parse stack;

WHILE Parse Stack not empty:
 
   SET Predicted TO POP(Parse Stack)       // get the top symbol off the stack
   IF Predicted is a Token class:
        // Try a match move:
         IF Predicted = Current token
             Current token = GET Next Token                         // matched
             ELSE IF Predicted not equal to Current token:
                ERROR "Expecting x, y found"
                                        // x is Predicted; y is current token
   ELSE IF Predicted is a Non-terminal:
        IF [Parse_table [Predicted, Current token]] = ERROR     // A 999 entry
           ERROR  "Uexpected :" Current token
       ELSE
           PUSH Symbols in RHS [Parse_table [Predicted, Current token]]
                ON Parse Stack             // Push the right hand side symbols