Questions tagged [lr-k]

LR(k) is a common type of parser for context-free grammars

An LR parser is a parser for languages defined by a deterministic context-free grammars. $\mathrm{LR}(k)$ denotes a parser that requires at most $k$ symbols of lookahead. LR parsers are efficient, but not every context-free language can be recognized by this type of parser.

53 questions
13
votes
2 answers

Is there any way to distinguish between LL(k) and LR(k) grammar?

I am recently studying about Compilers designing. I came to know about two types of grammar one is LL grammar and other is LR grammar. We also know the facts that every LL grammar is LR that is LL grammar is a proper subset of LR grammar. First one…
Debabratta Jena
  • 359
  • 1
  • 3
  • 9
12
votes
2 answers

How much bigger can an LR(1) automaton for a language be than the corresponding LR(0) automaton?

In an LR(0) parser, each state consists of a collection of LR(0) items, which are productions annotated with a position. In an LR(1) parser, each state consists of a collection of LR(1) items, which are productions annotated with a position and a…
templatetypedef
  • 9,302
  • 1
  • 32
  • 62
8
votes
2 answers

DCFL with prefix property have LR(0) grammar?

There are two important theorems about LR(k) grammars and DCFL. Mentioned here. A language has an LR(1) grammar iff it is DCFL. A language has an LR(0) grammar iff it is DCFL and has prefix property. I have counter example for 2nd theorem, plz see…
user3699192
  • 187
  • 2
  • 17
7
votes
1 answer

Is THEADS the same as FIRST?

I'm reading the paper "A Practical General Method for Constructing LR(k) Parsers" by David Pager, and it contains the following paragraph: We will first of all briefly review the LR(1) parsing and parser construction algorithms. In this paper the…
orlp
  • 13,988
  • 1
  • 26
  • 41
6
votes
1 answer

can every LR(k) grammer be transformed to LR(1)

when i was studying compilers i came across this in Wikipedia every DCFL has a corresponding unambiguous grammar and hence can be parsed by an LR(1) parser which is the most powerful parser then what is the significance of LR(k) parsers are they…
venkat
  • 189
  • 3
  • 17
6
votes
1 answer

Are LR(k) languages and DCFLs equivalent?

In the familiar book of Theory of Computation by M. Sipser, the author proved that for endmarked context-free languages, the set of languages having a LR(k) grammar for a predefined $k \in \mathbb{N}$ (denoted as LR(k) languages) is the set of…
5
votes
1 answer

What is handle in bottom up LR parsing?

I was taking course on compilers by Alex Aiken. You can find the slide discussing handles on this page. On the page of the slide, the instructor defines handle as follows: Assume a rightmost derivation $\require{AMScd}$ \begin{CD} S…
RajS
  • 1,737
  • 5
  • 28
  • 50
4
votes
1 answer

An intuitive explanation for LR grammars?

With LL grammars, there seems to be a very intuitive explanation, in terms of first and follow tables.( The first letter/s encountered in a particular state, can only mean a particular rule). With LR grammars however such an explanation seems to be…
4
votes
1 answer

Are there automatic transformation of grammar algorithms?

From time to time you can write a grammar that creates shift/reduce conflict (for example) but after reading the grammar you notice that if you rewrite the productions the conflict will go away, despite the fact that the rewritten grammar is…
greenoldman
  • 228
  • 1
  • 11
3
votes
1 answer

Is $\{a^nb^n\}\cup\{a^nb^{2n}\}$ LR(k)?

I was reading Knuth's paper "On The Translation of Languages from Left to Right", my particular interest being on RL($k$) languages (not a typo). By the end of the paper, he puts the grammar: $$ S \rightarrow Ac \\ S \rightarrow B \\ A \rightarrow…
paulotorrens
  • 731
  • 3
  • 11
3
votes
1 answer

Item lookaheads versus dot lookaheads for $LR(k)$ with $k \gt 1$?

I was reading "Parsing Techniques: A Practical Guide, Second Edition" by Grune and Jacobs, which details a bunch of different parsing algorithms. In the section on $LR(2)$ parsing, they mention that unlike $LR(1)$ items, which just have an item…
templatetypedef
  • 9,302
  • 1
  • 32
  • 62
3
votes
1 answer

Why can't a LR(0) parser have GOTO and Reduce Items in the same canonical set?

I am talking in reference to this question from this compiler test. I think it is actually true that a GOTO and REDUCE can't be present in the same set, but am having a hard time coming up with an example or counterexample. Pls provide and example…
2
votes
0 answers

Intuitive Explanation on Converting BNF Grammar to LR(1)

Consider the following BNF Grammar G: object-expression ::= id | id ( object-expression ) | object-expression . id | object-expression [ object-expression ] | object-expression . id (…
Grant Miller
  • 143
  • 2
  • 2
  • 11
2
votes
1 answer

Need for an augmented grammar

The question is under the concept of LR parser. Suppose the original grammar is S->AA A->aA|b Is it necessary to add an additional rule S'->S to make it as augmented grammar? In short, I want to know the use of augmented grammar.
Sharanya
  • 23
  • 1
  • 8
2
votes
0 answers

How to find conflicts in LALR parser?

I have a LR analyser and I can't find out how to know whether the grammar is or is not LALR(1). I think that I have to merge states with the same rules. So I have to merge states: $2 - 12, 3 - 13, 4 - 15, 7 - 9 -17, 8 - 16, 10 - 18 $ I think that…
Milano
  • 369
  • 1
  • 5
  • 10
1
2 3 4