Questions tagged [lr1]

LR parsers are a type of bottom-up parsers that efficiently handle deterministic context-free languages in guaranteed linear time. The name LR is often followed by a numeric qualifier, as in LR(1). An LR(1) parser can handle many but not all common grammars.

29 questions
0
votes
1 answer

what's the matter with this grammar

s : cmd | cmd SOMETHING cmd :WORD WORD and SOMETHING are non null terminals it's an LR1 grammar so bison should parse it without problems. however i faced an unexpected problem in runtime: the program prompts for input twice, so for example…
Amine Hajyoussef
  • 4,381
  • 3
  • 22
  • 26
0
votes
1 answer

Why does this Grammar work in LALR(1) but not LR(1)

By all accounts, LR(1) should be more powerful in every way compared to LALR(1) since LR(1) builds a canonical collection of LR(1) items, and LALR(1) is just a better SLR(1) parser. Then why does this grammar work successfully in an LALR(1) parser,…
0
votes
0 answers

LR(1) parsing, problem with look ahead symbols

I understand the concept of LR(1) parsing and lookahead symbols. I have the solution to the exercise and it does not agree with my solution. I'm trying to fill the LR(1) parsing table for the grammar below: S->xAz S->BAx A->Ay A->e B->yB B->y Ι…
Nikos
  • 23
  • 3
0
votes
1 answer

LR(1) table construction confusion

I'm confused on how to parse this grammar using LR(1): S -> A A -> A(A) | empty I'm aware there is left recursion but I was told it isn't necessary to remove it for LR(1). My item sets look like this: (the comma separates the grammar from the…
Ryan Foster
  • 103
  • 9
0
votes
1 answer

How to Parse a given LALR(1) Grammar

I'm having trouble parsing the following grammar using the LALR method. s -> y y -> dX | ydX X -> e | Zd z -> F | epsilon I'm ok at the beginning, here is item state 0: (the , seperates the lookahead states) s -> .y, $ y -> .dX, $d y -> .ydX,…
Ryan Foster
  • 103
  • 9
0
votes
1 answer

Which productions are considered in LR(1) lookahead?

I'm currently looking at two closure calculation examples using the tool at http://jsmachines.sourceforge.net/machines/lr1.html Example 1 S -> A c A -> b B B -> A b Here, in the initial state ends up with a closure of: [S -> .A c, $]; [A -> .b B,…
0
votes
0 answers

Bison : shift-reduce conflicts even though %left %right directive

I know that most of the shift/reduce conflicts can be solved by using %left or %right directives. But even with that, I am getting conflicts. Following is a block of my grammar: expression: variable '=' expression | expression…
Chaitanya Patel
  • 390
  • 1
  • 4
  • 15
0
votes
0 answers

LR(1) Automata: difference between items

I have a doubt regarding the LR(1) automata construction: Is the state with the kernel [A->b., x] (state_1) equivalent to the state with the kernel [A->b.,x/y] (state_2)? Like, if I'm on the state [A->.b, x] and shift_b from this state, do I need to…
Frank
  • 241
  • 1
  • 2
  • 8
0
votes
0 answers

How to create Lr(1) parser for very simple programming language

I need to create the parser for code with variables, simple conditions, cycles and functions, something like: f=1; i=1; while(i<10){ f=f*i; i=i+1; } print(f); I read a lot of theory, but I didn't find any working example of Lr(1) Parser for…
Manunich
  • 26
  • 3
0
votes
1 answer

Dealing with infinite loops when constructing states for LR(1) parsing

I'm currently constructing LR(1) states from the following grammar. S->AS S->c A->aA A->b where A,S are nonterminals and a,b,c are terminals. This is the construction of I0 I0: S' -> .S, epsilon --------------- S -> .AS, epsilon S ->…
Bruce
  • 1
0
votes
1 answer

How do I rewrite a context free grammar so that it is LR(1)?

For the given context free grammar: S -> G $ G -> PG | P P -> id : R R -> id R | epsilon How do I rewrite the grammar so that it is LR(1)? The current grammar has shift/reduce conflicts when parsing the input "id : .id", where "." is the input…
0
votes
0 answers

LR(1) - How to compute Lookaheads

I have trouble understanding how to compute the lookaheads. Lets say that I have this extend grammar: S'-> S S -> L=R | R L -> *R | i R -> L I wrote the State 0 so: S'-> .S, {$} S -> .L=R, {$} S -> .R, {$} L -> .*R, {=,$} L -> .i, {=,$} R -> .L…
Pascal NoPascensor
  • 171
  • 1
  • 1
  • 14
0
votes
1 answer

printing parse Tree as a dynamic list in c language

I have written a code in C to implement LR(1) parse table, however now I am facing a problem in printing the parse tree. How do we do that in C? The tree can have variable children and since the parsing algorithm is bottom-up, I am not sure where to…
-1
votes
1 answer

LR(1) items and LALR(1) Parsing table how to do this?

From the grammar given below create LR(1) items and merge the sets of items having give the set of LALR(1) items. I am not sure how to construct from this grammar B -> id | id ( B ) | B . id | B [ B ] | B . id ( B ) Answer so far: i0- B' -> .B, $ |…
dan123
  • 1
1
2