This last topic of the semester was devoted to pointing out one other major trend in compiling, so that you won't be caught by surprise if asked about it or if you read about it: bottom up parsing (also known as LR parsing):
The major difference between the parsing techniques between LL and LR grammars is that LR grammars must be used for bottom up parsing whereas LL grammars are used for top-down parsing.
How does this change the compiler? The only thing different is the parser portion, because LL and LR are parsing techniques. The scanner remains the same, and the semantic analyzer remains largely the same. If the same grammars are used for both LL and LR parsing, the same parse tree will result from either parser given the same input string.
A final note is that LR parsing is so detailed and complex to manage that it virtually cannot be done by hand. Instead, parser tools, such as yacc, bison, and occs are used to generate LR parsers.
Grammar 2 1. <expression> --> <expression> + <term> 2. <expression> --> <expression> - <term> 3. <expression> --> <term> 4. <term> --> <term> * <factor> 5. <term> --> <term> / <factor> 6. <term> --> <factor> 7. <factor> --> <factor> ^ <primary> 8. <factor> --> <primary> 9. <primary> --> identifier 10. <primary> --> integer_literal 11. <primary> --> ( <expression> )
This grammar is LR(1). That is, strings in the language of this grammar can be parsed bottom up using one token of lookahead with no backtracking. Try parsing the string 3 + a * b.