Questions tagged [lr-grammar]

LR(k) grammars are grammars that can be parsed bottom-up from the left-to-right, producing a rightmost derivation, using k tokens of lookahead. LR(k) parsers are among the most powerful deterministic parsers available, but are often too large to use in practice.

178 questions
0
votes
1 answer

Effect of yacc operator associativity declaration on expressions that have just a few tokens

When you have a grammar like this one: B: 'a' A 'a' | 'b' A 'b' A: 'a' 'a' | 'a' The %right 'a' declaration causes aa.a not to be accepted because a shift happens instead of a reduce at '.', and %left 'a' doesn't accept neither aa.aa nor…
user2373145
  • 332
  • 2
  • 14
0
votes
1 answer

Is a context-free grammar that can be transformed into a LR parsing table unambiguous?

I know that in general it is undecidable whether a context-free grammar is unambiguous. However, this does not imply that this cannot be decided for a subset of context-free grammars. A grammar is used to transform an input text into a parse tree.…
0
votes
1 answer

SLR (1) confusion

S → ( S ) S | . based on the definition, 0, 2 and 4 have shift/reduce conflict. The follow set of S is ")". For SLR(1) in state 2, "(" is not in the follow set of S, but why is this a SLR (1)? Can you also explain the shift / reduce conflict…
user3230613
  • 133
  • 1
  • 5
0
votes
1 answer

Why does a LR(1) DFA doesn't have a Shift/Reduce conflict?

Given this grammar: For the LR(0) DFA I can clearly see why this is a Shift/Reduce conflict: (partial DFA) But I can't understand why the LR(1) DFA solves the problem? (partial DFA) For me this is still a shift reduce conflict since the lookahead…
Piranha
  • 801
  • 1
  • 8
  • 22
0
votes
0 answers

What kind of parsing supported by ANTLR4?

I was recently using antlr4 for one of my projects. But I have no idea what kind of parsing method they are using. While i was searching some resources i found a research paper which says ANTLR4 uses a parser called ALL(*). But i have no idea about…
tnishada
  • 1,315
  • 1
  • 16
  • 24
0
votes
1 answer

Find an equivalent LR grammar

I am trying to find an LR(1) or LR(0) grammar for pascal. Here is a part of my grammar which is not LR(0) as it has shift/reduce conflict. EXPR --> AEXPR | AEXPR realop AEXPR AEXPR --> TERM | SIGN TERM | AEXPR addop TERM TERM --> TERM mulop FACTOR |…
0
votes
1 answer

How to choose which rule to use in CFG derivation?

I'm having a hard time with this textbook and my professor sees answering questions as unfair to the students who already know the material coming into the class (getting feedback from this guy is a data mining process in and of itself). Anyways, my…
0
votes
3 answers

How does a LR Automaton actually work?

In this LR(0) automaton There are transitions for the non terminals as well, which I don't understand. If the input is aab. Then you are going to end up in the state which is just A->a·. If you were to visualise the state that were reached by…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
0
votes
0 answers

Asking for a grammar LR(1) and one not LR(1) for testing

I wrote a little LR(1) parser generator in Java that given a context-free grammar in input (better put it's productions) and a input word prints whether 1) The Grammar is not LR(1) 2) The word is accepted by the grammar 3) The word is rejected by…
Crysis85
  • 345
  • 3
  • 17
0
votes
1 answer

Is there a rule of thumb for which symbol to shift first when generating LR(0) parser table?

I'm reading about LR(0) parser from this book: Modern Compiler Implementation in Java. Below is how the parsing table looked like based on the book. http://postimg.org/image/hyowddu1h/ Start symbol: S --> E$ Productions: (1) E --> T + E (2) E -->…
sw2
  • 357
  • 6
  • 13
0
votes
2 answers

Translation of if then else in compiler grammar

... IF LP assignment-expression RP marker statement { backpatch($3.tlist,$5.instr); $$.nextList = mergeList($3.flist,$6.nextList); } |IF LP assignment-expression RP marker statement ELSE Next statement { backpatch($3.tlist,$5.instr); …
sonus21
  • 5,178
  • 2
  • 23
  • 48
0
votes
1 answer

Not sure if this LR(1) grammar has shift/reduce conflict

I'm trying to solve question on LR(1) grammar : S->AA A->Aa A-> b I got stuck in state 4 when : S-> AA. ,$ A-> A.a ,$ A->.Aa ,$ A->.a ,$ a and A shifted to other state and A is reduced in the same state should I consider this grammar is not…
0
votes
1 answer

SLR(1) and LALR(1), about Parse Table and Reduced State

I ask a question some days ago SLR(1) and LALR(1) and Reduce, i do lot's of search and contact to some professor, but i couldn't summarize that the solution of 2nd problem is right or false. we have 2 question on entrance exam in 2 different year.…
user4012783
0
votes
1 answer

difficulty solving this example in LR parsing?

The Grammar is: S → ( L ) | id L → S | L , S I'm trying to Compute CLOSURE and GOTO on the given grammer using LR parsing. Our teacher solved this, but in the first step he didn't use the second production L-->S|L,S, I don't know why. So I solved…
Caffe Latte
  • 1,693
  • 1
  • 14
  • 32
0
votes
1 answer

Questions about LR parsers

Instead of saying "Rightmost derivation in reverse", why don't they say "Leftmost reduction"? Do they mean the same thing? It is extremely confusing for me to read. What is a closure set, and how does it play a part in the parsing process? …
user3251270
  • 107
  • 1
  • 8
1 2 3
11
12