Interpreting LL Parsing Table
Computed parse table in 'choice' matrix, as in Building LL Parsing Table
This is the top-down parser:
var stack : Stack[GrammarSymbol]
stack.push(EOF);
stack.push(StartNonterminal);
lex = new Lexer(inputFile)
while (true) {
X = stack.pop
t = lex.curent
if isTerminal(X)
if (t==X)
if (X==EOF) return success
else lex.next // eat token t
else
parseError("Expected " + X)
else // non-terminal
cs = choice(X)(t)
cs match {
case {i} => // exactly one choice
rhs = p(X,i) // choose correct right-hand side
stack.push(reverse(rhs))
case {} => parseError("Expected element of " + unionOfAll(choice(X)))
case _ => crash("wrong parse table, not LL(1)")
}
}
When we write recursive descent procedures by hand, the stack is implicit in the use of recursive procedures.