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
2
votes
1 answer

The need of S'->S in LR parsing

I was told that without the added rule S->S' we might accept words that doesn't exists in the grammar language, can someone think on a good example to this? Moreover, do you have an example for a reduction in SLR parsing that goes to more than one…
idansc
  • 91
  • 1
  • 3
2
votes
1 answer

Pass values as arguments to rules

When implementing real world (TM) languages, I often encounter a situation like this: (* language Foo *) type A = ... (* parsed by parse_A *) type B = ... (* parsed by parse_B *) type collection = { as : A list ; bs : B list } (* parser…
choeger
  • 3,562
  • 20
  • 33
2
votes
2 answers

Parsing special cases

If I understand correctly, parsing turns a sequence of symbols into a tree. My question is, is it possible to use some standard procedure (LR, LL, PEG, ..?) to parse the following two examples or is it necessary to write a specialized parser by…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
2
votes
1 answer

Is there an LR(0) parsing algorithm that handles S/R and R/R conflicts?

If there's conflicts, each entry in an LR(0) action table might have one shift, and several reduce actions; while parsing, I imagine it's possible to try all actions by splitting the stack. Does this way of parsing have a name?
ebsddd
  • 1,028
  • 9
  • 20
2
votes
2 answers

deciding whether the grammar is LR(0) or not

I am new to the subject of compilation and have just started an exercise for Bottom -up parsing. I have stuck on the following problem. build a LR(0) parsing table for following grammar: 1) E –> E + T 2) E –> T 3) T –> (E) 4) T –> id I0 : E'…
neerajDorle
  • 540
  • 7
  • 21
2
votes
1 answer

Is there a general way to convert an unambiguous context-free-grammar into a LALR(1) grammar?

I am trying to create a LALR(1) parser for the following grammar and find some shift/reduce conflicts. S := expr expr := lval | ID '[' expr ']' OF expr lval := ID | lval '[' expr ']' So the parser can not parse the string "ID[ID]" correctly. My…
2
votes
1 answer

LR Parser GOTO Function and Epsilon

I'm trying to learn compiler construction and I just read through the Dragon Book chapter on SLR parsers. So, I decided to make a simple grammar and try to hand code the parser. The grammar looks like this: S -> A A -> (A)A A -> e, where e is the…
pongad
  • 33
  • 4
2
votes
1 answer

Is Wikipedia's example on FOLLOW() sets in LR(1) parsing wrong?

I can't tell if I'm misunderstanding what's going on, or if Wikipedia's explanation is incorrect. Wikipedia says: FOLLOW(k,B) of an item set k and an nonterminal B is the union of the follow sets of all items in K where '•' is followed by B. Their…
user541686
  • 205,094
  • 128
  • 528
  • 886
2
votes
1 answer

In the context of writing a parser based on the LR(0) algorithm what are magic and tau steps?

A task that I have to do specifies: Start by defining the non-deterministic machine which performs shift-reduce stages with the help of magic or tau steps However, I can't find any references to what a magic or tau step is in Compilers:…
Froskoy
  • 2,967
  • 5
  • 20
  • 21
1
vote
1 answer

LALR, LR(1) and SLR

Since LR (1) grammars are broader than LALR or SLR grammars, I have doubts regarding the proof of LR grammars. If a grammar is SLR or LALR, then does that mean that the grammar is also LR (1)? In fact, since the method that uses lookaheads is more…
xXMarcoXx
  • 11
  • 4
1
vote
0 answers

checking if the following grammar is LR(0) and LR(1)

I have the following grammar: S -> A A -> B | B[*] B -> [AB] AB -> *,AB | epsilon S,A,B,AB are variables and [ ] , * are terminals Is it: LR(0)? LR(1)? and how can I prove it?
CS2000
  • 51
  • 4
1
vote
1 answer

SLR(1) and LALR(1) grammar conflicts

Suppose you have a grammar G and we find an LR(1) automaton for it. We can transform it into a LALR(1) or SLR(1) parser by doing state-merging and transforming rules but conflicts may appear. My question is the following: must all problems appear in…
Zan
  • 288
  • 1
  • 11
1
vote
1 answer

Should a merge failure stop the LR(1) to LALR(1) conversion

Let's say I have got a set of LR(1) states and I want to try to convert it to LALR(1). I did the first step of finding states that have got the same LR(0) core and now I'm doing the merge process. However one of such set of states can't be merged,…
Felix.leg
  • 622
  • 1
  • 4
  • 13
1
vote
1 answer

Is there a type of parser generator that handles all deterministic context-free grammars?

I need a way of generating parsers for all deterministic context-free grammars. I know that every deterministic context-free grammar can be parsed by some LR(k) parser. The problem is that I need to generate parsers for grammars of unknown k. So, to…
1
vote
0 answers

LR-Parsing-Table: What determines next state in reduce-actions?

as far as I know (read) about generating LR-Parsing tables is that the columns (= token), where the reduce-action is written into a cell for a certain state, depends on the Terminals, that are in the FOLLOW-set of the reduced symbol. Is that…
von spotz
  • 875
  • 7
  • 17