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
0
votes
2 answers

Eliminate shift/reduce conflicts caused by production rules with same prefix

Here is the simplified yaac file: %token CONTEXT_ // the corresponding string is "context" %token CONTEXTREF_ //"contextref" %token IS_ //"is" %token ID_L //"id_l" %token ID_L1 //"id_l1" %token LIB_ %start…
Yuan Wen
  • 1,583
  • 3
  • 20
  • 38
0
votes
1 answer

How to remove shift/reduse warning?

I am trying to make a compiler and I am now trying to make the parser. I get a warning on this state : State 89 62 expr: '(' expr . ')' 66 | expr . '+' expr 67 | expr . '-' expr 68 | expr . '*' expr 69 | expr .…
Nwlis
  • 63
  • 6
0
votes
2 answers

Solving shift/reduce conflicts

I'm using PLY to parse this grammar. I implemented a metagrammar for EBNF used in the linked spec, but PLY reports multiple shift/reduce conflicts. Grammar: Rule 0 S' -> grammar Rule 1 grammar -> prod_list Rule 2 grammar -> empty Rule 3 …
Paul Smith
  • 103
  • 3
0
votes
1 answer

How can I eliminate shift-reduce conflicts by the same operator

I intended to use bison to parse some scripting language, in this language I can write code like the following: a = input() b = a + 1 function myfunc a = input() b = a + 1 end function I found that the block a = input() b = a + 1 which…
calvin
  • 2,125
  • 2
  • 21
  • 38
0
votes
1 answer

Sablecc shift/reduce conflicts on productions with identifiers

I'm trying to write a specification file for sablecc for a version of minipython (with postfix/prefix increment and decrement operators), and some productions naturally need to use identifiers, but i get these conflicts during parsing: shift/reduce…
0
votes
0 answers

Bison shift/reduce conflict in simple call expression/lambda grammar

I've got a shift/reduce conflict that I can't figure out why it's occurring, and how to resolve it. Given this grammar: %token IDENTIFIER %start Expression %% CallExpression : Expression "(" ")" ; Lambda : "(" ")" "=>" Expression …
John Doe
  • 3
  • 2
0
votes
1 answer

Bison shift/reduce conflicts

I'm trying describe this syntax on Bison input file: https://courses.engr.illinois.edu/cs421/sp2011/mps/mp2/minijavasyntax.pdf this is my input: %start Program %token KW_CLASS KW_EXTENDS KW_PUBLIC KW_STATIC KW_BOOLEAN KW_STRING KW_FLOAT KW_INT…
Phạm Văn Thông
  • 743
  • 2
  • 7
  • 21
0
votes
2 answers

Bison: Shift/Reduce Conflict resolution when dealing with optional rules

On the grammar of a .y (yacc -- bison) file I've defined the following rules: C : E | D | F | A A : B | B '[' C ']' ; (this is something like B with optional [C]) when I compile the .y file in the appropriate way using a proper lexer file I get…
ysig
  • 447
  • 4
  • 18
0
votes
1 answer

How to remove shift-reduce conflict in yacc grammar?

I have the following grammar: Expression : SimpleExpression {$$ = $1;}; | SimpleExpression LTnum SimpleExpression { MkLeftC($1, $2); $$ = MkRightC($3, $2); } | SimpleExpression LEnum SimpleExpression { MkLeftC($1, $2); $$…
ExeCode
  • 21
  • 1
  • 6
0
votes
1 answer

ML-Yacc error concerning 12 shift/reduce conflicts involving EXP -> EXP BINOP EXP

This is the error: 12 shift/reduce conflicts error: state 34: shift/reduce conflict (shift OR, reduce by rule 11) error: state 34: shift/reduce conflict (shift AND, reduce by rule 11) error: state 34: shift/reduce conflict (shift GE, reduce…
Joe
  • 1,076
  • 3
  • 10
  • 17
0
votes
1 answer

bison fix shift/reduce conflict for signed terminals

Based on this question Where are the shift/reduce conflicts in this Bison code coming from? I'm trying to create a grammar for a syntax like this: -10 + 3 - 2 or +4 - 2 + 1. The first integer obviously has a sign. This is what I already have: %token…
Johannes
  • 1,249
  • 3
  • 17
  • 33
0
votes
1 answer

Bison arrays shift reduce conflicts

I'm new to Bison and I've been trying to create an array and rules for concatenation and more for a long time, and can't figure out a why I get a shift reduce here and how can I resolve it: arr: T_OPEN expr {$$ = (void *)(new…
Shirli
  • 95
  • 13
0
votes
1 answer

shift/reduce errors in my_toy_compiler

I'm trying to use my_toy_compiler of lsegal https://github.com/lsegal/my_toy_compiler but I get 48 shift/reduce errors errors when I try to "compile" it. I resolve 24 shift/reduce errors adding this line to the parser.y file: %left TCEQ TCNE TCLT…
0
votes
1 answer

Shift reduce conflict, financial calculator using compiler

Whenever I add '(' term ')' { $$=$2; } I got shift reduce conflict the operation that I'm trying to do is: (5) + (5), (5.5) + (5), ((5.5) + (5)) - (5), ((5.5) / (5.5)) * (5), etc I'm a bit confused about shift reduce parsing, our professor only…
larca
  • 9
  • 2
  • 7
0
votes
1 answer

Irony Reduce-Reduce Problems

I have been trying to figure out this same issue for almost 2 weeks now. At first it was shift-reduce errors now its reduce-reduce problems. I have tried doing it so many ways and now I have came to the point where I just need help. I've coded many…