Download presentation
Presentation is loading. Please wait.
1
Syntax Analysis - 3 Chapter 4
3
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 and 4.9.4)
4
Introduction to LR Parsing: Simple LR
5
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.
6
Items and the LR(0) Automaton
How does a shift-reduce parser know when to shift and when to reduce?
7
Closure of Item Sets For example CLOSURE({E' → · E})
11
Use of the LR(0) Automaton & Algorithm
12
The LR-Parsing Algorithm
13
Structure of the LR Parsing Table
15
Behavior of the LR Parser
Example 4.45 self study
16
Constructing SLR-Parsing Tables
17
Viable Prefixes
18
4.7.4 Constructing LALR Parsing Tables
19
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.
20
4.9.1 The Parser Generator Yacc
22
The Declarations Part
24
The Translation Rules Part
28
4. 9. 2 Using Yacc with Ambiguous Grammars (self study) 4. 9
4.9.2 Using Yacc with Ambiguous Grammars (self study) Creating Yacc Lexical Analyzers with Lex (self study)
29
4.9.4 Error Recovery in Yacc
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.