Difference between revisions of "Bottom-Up Parsing/Exercise 17: LALR(1)"

From Wiki**3

< Bottom-Up Parsing
(Solução)
(Solução)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Problema ==
 
== Problema ==
  
Consider the following grammar, where '''R''' is the initial symbol and '''{ a, b, c }''' is the set of terminal symbols:  
+
Consider the following grammar, where '''X''' is the initial symbol and '''{ a, b, c }''' is the set of terminal symbols:  
 
<source lang="text">
 
<source lang="text">
X -> X Y c | X a | a
+
X X Y c | X a | a
Y -> a | b
+
Y a | b
 
</source>
 
</source>
 
# Compute the set of LALR(1) states for the grammar. Build the corresponding LALR(1) parse table.
 
# Compute the set of LALR(1) states for the grammar. Build the corresponding LALR(1) parse table.
Line 11: Line 11:
  
 
== Solução ==
 
== Solução ==
Note-se que a solução apresentada é para SLR(1) e LALR(1) (a vermelho).
+
Note-se que a solução apresentada é para SLR(1) e LALR(1) (a vermelho -- no estado 1, tem-se '''$ab''' como lookahead).
  
 
{{CollapsedCode|Solução completa|
 
{{CollapsedCode|Solução completa|

Latest revision as of 15:04, 8 May 2024

Problema

Consider the following grammar, where X is the initial symbol and { a, b, c } is the set of terminal symbols:

X → X Y c | X a | a
Y → a | b
  1. Compute the set of LALR(1) states for the grammar. Build the corresponding LALR(1) parse table.
  2. Compact the parse table, eliminating and propagating reductions.
  3. Show the parsing process for input aabc (including the actions/gotos and the input and stack states). In case of conflict, assume YACC's behavior.

Solução

Note-se que a solução apresentada é para SLR(1) e LALR(1) (a vermelho -- no estado 1, tem-se $ab como lookahead).

Solução completa

XYc.jpg