Syntax Analysis - 3 Chapter 4
Topics 4.6 Introduction to LR Parsing: Simple LR 4.7 More Powerful LR Parsers(self study) 4.7.4 Constructing LALR Parsing Tables (only the method) 4.8 Using Ambiguous Grammars (self study) 4.9 Parser Generators (only 4.9.1 and 4.9.4)
Introduction to LR Parsing: Simple LR
Why LR Parsers? LR parsers are table-driven, much like the nonrecursive LL parsers. LR parsing is attractive for a variety of reasons: LR parsers can be constructed to recognize virtually all programming language constructs for which context-free grammars can be written. The LR-parsing method is the most general nonbacktracking shift-reduce parsing method known (primitive shift-reduce methods (see the bibliographic notes). An LR parser can detect a syntactic error as soon as it is possible to do so on a left-to-right scan of the input. For a grammar to be LR(k), we must be able to recognize the occurrence of the right side of a production in a right-sentential form, with k input symbols of lookahead. For LL(k) grammars where we must be able to recognize the use of a production seeing only the first k symbols of what its right side derives.
Items and the LR(0) Automaton How does a shift-reduce parser know when to shift and when to reduce?
Closure of Item Sets For example CLOSURE({E' → · E})
Use of the LR(0) Automaton & Algorithm
The LR-Parsing Algorithm
Structure of the LR Parsing Table
Behavior of the LR Parser Example 4.45 self study
Constructing SLR-Parsing Tables
Viable Prefixes
4.7.4 Constructing LALR Parsing Tables
Parser Generators This section shows how a parser generator can be used to facilitate the construction of the front end of a compiler. use the LALR parser generator Yacc Yacc stands for "yet another compiler-compiler“. Yacc is available as a command on the UNIX system, and has been used to help implement many production compilers.
4.9.1 The Parser Generator Yacc
The Declarations Part
The Translation Rules Part
4. 9. 2 Using Yacc with Ambiguous Grammars (self study) 4. 9 4.9.2 Using Yacc with Ambiguous Grammars (self study) 4.9.3 Creating Yacc Lexical Analyzers with Lex (self study)
4.9.4 Error Recovery in Yacc