
Parse array [ num dotdot num ] of integer using the grammar:
type simple
| id
|
array [ simple ] of type
simple integer | char | num dotdot num
Initially, the token array is the lookahead symbol and the known part of the parse tree consists of the root, labeled with the starting non- terminal type. For a match to occur, non-terminal type must derive a string that starts with the lookahead symbol array . In the grammar, there is just one production of such type, so we select it, and construct the children of the root labeled with the right side of the production. In this way we continue, when the node being considered on the parse tree is for a terminal and the terminal matches the lookahead symbol, then we advance in both the parse tree and the input. The next token in the input becomes the new lookahead symbol and the next child in the parse tree is considered.
|