SLIDE 8 Shift/reduce parsing a la Yacc
- The parser generated by yacc effectively traces out this tree for us, left-to-
right, bottom to top, pushing tokens onto an internal stack, and calling a production rule every time it can reduce the right hand side of a production into the nonterminal on the left. At the bottom, with two productions
– integer: NUMBER { /* This code is called when the scanner
returns a number */ }
– expression: integer { /* This code is called next, since the right-
hand-side of the rule only requires that we've had an integer */}
– What happens next depends on what has been recently seen; if
what's on the parser's internal stack was just missing an expression to complete the right hand side of a production, another rule will fire – otherwise, the scanner gets to fetch the next token, in the hope that something will match soon.
- What we need to construct our tree is to build it inductively inside the
production's semantic action blocks (plain old C).