Questions tagged [shift-reduce-conflict]

Shift Reduce is an LR parser paradigm. A shift/reduce conflict occurs when there is ambiguity in the grammar being parsed.

When parsing using an LALR parser a stack is maintained of the tokens that have been seen, then given what is on input and what is on the stack, either the next token is shifted onto the stack or a production is made and the necessary tokens are popped off the stack and reduced to the appropriate production. A shift reduce conflict occurs when given the tokens on the stack and given the input, both a shift and a reduce action should occur according to the grammar.

This ambiguity is often mitigated through the use of precedence instructions to the parser.

167 questions
3
votes
1 answer

Why doesn't YACC generate shift-reduce conflict?

Trying to understand shift-reduce conflicts and fix them. I have following YACC code, for which I was expecting shift-reduce conflict but Bison doesn't generate any such warnings %% lang_cons: /* empty */ | declaraion // SEMI_COLON …
3
votes
2 answers

yacc shift-reduce for ambiguous lambda syntax

I'm writing a grammar for a toy language in Yacc (the one packaged with Go) and I have an expected shift-reduce conflict due to the following pseudo-issue. I have to distilled the problem grammar down to the following. start: stmt_list expr: …
d11wtq
  • 34,788
  • 19
  • 120
  • 195
3
votes
2 answers

Resolving reduce/reduce conflicts

We have a CFG grammar and we construct LR(1) Parsing Table. We see that one cell on the parsing table have a reduce - reduce conflict. Is it possible to solve this conflict by using more input symbols of lookahead at each step? I am asking this…
3
votes
2 answers

How rewrite grammar to eliminate shift-reduce conflict (in Haskell Happy parser)

I'm trying to define grammar for methods (java like) using Happy LALR parser generator 1. MD ::= some_prefix { list(VD) list(S) } 2. VD ::= T I 3. S ::= I = E | I [ E ] = E | etc... 4. T ::= I | byte | int | etc... 5. E ::= INT | E +…
warunapww
  • 966
  • 4
  • 18
  • 38
3
votes
1 answer

Bison shift/reduce conflict - tiger compiler

I have written a yacc file according to Tiger Book(appendix A, Tiger manual). But there are still some shift/reduce conflicts. I do not know how to resolve these conflicts. % yacc --version bison (GNU Bison) 3.0.2 You can use this cmd to reproduce…
songhir
  • 3,393
  • 3
  • 19
  • 27
3
votes
2 answers

bison shift/reduce problem moving add op into a subexpr

Originally in the example there was this expr: INTEGER | expr '+' expr { $$ = $1 + $3; } | expr '-' expr { $$ = $1 - $3; } ; I wanted it to be 'more simple' so i wrote this (i realize it would do…
user34537
3
votes
1 answer

Bison shift-reduce conflict

A stripped down version of the grammar with the conflict: body: variable_list function_list; variable_list: variable_list variable | /* empty */ ; variable: TYPE identifiers ';' ; identifiers: identifiers ',' IDENTIFIER |…
mcu17818
  • 35
  • 1
  • 5
2
votes
2 answers

How to resolve a shift-reduce conflict in unambiguous grammar

I'm trying to parse a simple grammar using an LALR(1) parser generator (Bison, but the problem is not specific to that tool), and I'm hitting a shift-reduce conflict. The docs and other sources I've found about fixing these tend to say one or more…
Geoff Romer
  • 2,358
  • 1
  • 18
  • 19
2
votes
1 answer

How to avoid a shift reduce conflict in a LALR grammar for parsing nested lists?

I would like to create a LALR grammar to parse nested lists, but I get always a shift/reduce conflict. I have the list1 which is a list of type1 items and list2: ::= | ; ::= A | B | ; And I have a…
ceving
  • 21,900
  • 13
  • 104
  • 178
2
votes
4 answers

When is an ambiguous grammar or production rule OK? (bison shift/reduce warnings)

There are certainly plenty of docs and howtos on resolving shift/reduce errors. The bison docs suggest the correct solution is usually to just %expect them and deal with it. When you have things like this: S: S 'b' S | 't' You can easily resolve…
jettero
  • 835
  • 2
  • 13
  • 26
2
votes
1 answer

Packrat parser conflict

Suppose I try to parse a string abc with a Packrat Parser: lazy val abc: PackratParser[AnyRef] = ab ~ "c" lazy val ab: PackratParser[AnyRef] = (ab | abc) ~ "b" | "a" def parse(in: String) = parseAll(abc, in) Here I use left recursion…
Nutel
  • 2,244
  • 2
  • 27
  • 50
2
votes
2 answers

Shift/reduce conflict example for a C compiler

Here is a part of C compiler: Exp : INTNUMBER { $$ = $1; } | lvalue { $$ = $1; } | REALNUMBER { $$ = $1; } | CHARVALUE {…
Kadaj13
  • 1,423
  • 3
  • 17
  • 41
2
votes
1 answer

Solving shift/reduce conflict in expression grammar

I am new to bison and I am trying to make a grammar parsing expressions. I am facing a shift/reduce conflight right now I am not able to solve. The grammar is the following: %left "[" "(" %left "+" %% expression_list : expression_list ","…
Exagon
  • 4,798
  • 6
  • 25
  • 53
2
votes
1 answer

resolve grammar ambiguity

I'll post the rules of the grammar in question to start. interface_sections : main_interface bind_buttons bind_functions bind_panel_items ; /* Components of a gui program */ bind_buttons : T_BEGIN T_BIND T_BUTTONS …
2
votes
1 answer

How to resolve shift reduce conflicts in my grammar?

I'm writing a compiler from (reduced) Pascal into ARM asm. I'm at the second step of the process - after writing lexical analyzer now I'm working on syntax analysis with java cup. I have written my grammar, but got 5 S/R conflicts, which are all…
Uros K
  • 3,274
  • 4
  • 31
  • 45
1
2
3
11 12