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.
Questions tagged [lr-grammar]
178 questions
1
vote
1 answer
Difference between LL and LR Parsing
Currently studying context free grammars and methods for parsing them. From my understanding, context free grammars can be parsed via top down/LL or bottom up/LR.
Is it correct understood that, LL parsers require grammars to have strictly…

84d7dc197
- 23
- 3
1
vote
1 answer
How does LR parsing select a qualifying grammar production (to construct the parse tree from the leaves)?
I am reading a tutorial of the LR parsing. The tutorial uses an example grammar here:
S -> aABe
A -> Abc | b
B -> d
Then, to illustrate how the parsing algorithm works, the tutorial shows the process of parsing the word "abbcde" below.
I…

zell
- 9,830
- 10
- 62
- 115
1
vote
1 answer
Repetitions Grammar parsing S -> ( E ';' )+
I know how to parse grammars like this:
E -> E '*' E
E -> E '+' E
E -> N
N -> '0'
N -> '1'
But what if I have the following example grammar (with a "regex repitition"):
E -> 'e'
S -> ( E ';' )+ // '+' used like in regexes
How can i parse such…

Hexception
- 722
- 10
- 25
1
vote
2 answers
LR(k) parsers, with k infinite, not restricted to deterministic context-free languages?
Is a theoretical LR parser with infinite lookahead capable of parsing (unambiguous) languages which can be desribed by a context-free grammar?
Normally LR(k) parsers are restricted to deterministic context-free languages. I think this means that…

user764754
- 3,865
- 2
- 39
- 55
1
vote
1 answer
Is it possible that going from LR(1) to LALR(1) introduces shift/reduce conflicts?
I am studying for a final in Language Theory and one question asks the following:
If you have a parsing table T in LR(1) and a parsing table T' in LALR(1) for the same grammar. Is it possible that T' introduces new shift/reduce conflicts that were…

acasla
- 131
- 1
- 9
1
vote
2 answers
Trying to write a parser
I'm trying to parse a syntax using the Shunting Yard (SY) algorithm. The syntax includes the following commands (they're are many many others though!)
a + b // a and b are numbers
setxy c d //c,d can be numbers
setxy c+d b+a //all…

djs22
- 1,148
- 3
- 14
- 30
1
vote
1 answer
Chomsky Hierarchy: LR(k) grammars vs Deterministic CFGs?
We are learning the chomsky hiearchy in my introduction to computer science course. My professor has mention lrk grammars multiple times, but they're not taught in the book. From my understanding, they are a subset of deterministic context free…

maddie
- 1,854
- 4
- 30
- 66
1
vote
1 answer
How do I preform 'lookahead' in an OCaml lexer / how do I rollback a lexeme?
Well, I'm writing my first parser, in OCaml, and I immediately somehow managed to make one with an infinite-loop.
Of particular note, I'm trying to lex identifiers according to the rules of the Scheme specification (I have no idea what I'm doing,…

ELLIOTTCABLE
- 17,185
- 12
- 62
- 78
1
vote
0 answers
Finding reduce-reduce conflict examples
While many questions are asking to help solve reduce-reduce conflicts, I don't have any of those and I am actually asking your help to find some.
I am writing documentation and exercices about LR(1) parser conflicts. While I could find some…

Olivier Melançon
- 21,584
- 4
- 41
- 73
1
vote
1 answer
What do the different kinds of LR Parsers use as lookahead?
Is it correct, that LR(0)-Parsers simply reduces, if there is no transition for the next input-symbol (because it has no lookahead) ?
Is it correct, that SLR(1)-Parsers use the FOLLOW-Set of the productions as lookahead?
Is it correct, that…

von spotz
- 875
- 7
- 17
1
vote
0 answers
LR(0) parsing conflicts (shift/shift somehow)
I come with a question while doing one of the exercises for my parsing course in the university. The question specifically goes to constructing a parsing table using canonical LR items.
The given grammar production rules go as follow:
S -> NP VP …

sunny11
- 31
- 1
- 5
1
vote
1 answer
How to identify whether a grammar is LR(n), LL(n)
For a language that is not LL(1) or LR(1) how can one try to find out if some number n exists such that the grammar can be LL(n) or LR(n)?
You check if a grammar is LR(0) by looking at the canonical collection of LR(0) items. Then, assuming it…

Eternal_Light
- 676
- 1
- 7
- 21
1
vote
2 answers
If the grammar is ambiguous then there exists exactly one handle for each sentential form.?
there can be two productions from which we can do the reduction. After giving precedence and associations as required there will be one handle only.so is this statement true??

siddharth
- 579
- 1
- 8
- 18
1
vote
1 answer
SLR parsing conflicts with epsilon production
Consider the following grammar
S -> aPbSQ | a
Q -> tS | ε
P -> r
While constructing the DFA we can see there shall be a state which contains Items
Q -> .tS
Q -> . (epsilon as a blank string)
since t is in follow(Q) there appears to be…

Shubham Singh rawat
- 129
- 1
- 6
1
vote
3 answers
Are LL(1) parsers more efficient for a prefix encoding and LR(1) more efficient for postfix?
This is a hand coded pedal to the metal question and not ANTLR vs BISON.
Also, this is for parsing a binary format. There is no lexical analysis.

Olsonist
- 2,051
- 1
- 20
- 35