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
1
vote
1 answer

Bison shift/reduce conflict cannot fix

I am trying to add more rule for this thing and it keeps giving me this shift/reduce conflict, I don't understand why it does, and I've been trying to fix it for the past 24 hours FuncDecl : RetType ID LPAREN Formals { …
1
vote
1 answer

Shift/reduce conflicts using Sablecc

I'm supposed to write a .grammar file for MiniPython using Sablecc. I'm getting these shift/reduce conflicts: shift/reduce conflict in state [stack: TIf PTpower *] on TMult in { [ PMltp = * TMult PTopower Mltp ] (shift) [ PMlpt = * ]…
1
vote
1 answer

Why do I always have a shift/reduce conflict with my EOF / linebreak nonterminals?

So, I'm still pretty junior when it comes to putting together parsing grammars. I need help dissecting conflicts reported by Menhir when I have shift-reduce conflicts. Take this little grammar as an example: (* {2 Tokens } *) %token EOF %token COLON…
ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
1
vote
1 answer

Bison shift/reduce and reduce/reduce conflict

OK, I have tried to rewrite this Bison grammar three times now and keep running into shift/reduce and reduce/reduce conflicts. The Syntax that I am trying to parse is as follows. The items in the {...} are for one or the other. The items i n the…
1
vote
1 answer

shift/reduce conflicts error

I receive a 20 shift/reduce conflicts error. I handled the operator precedence by declaring them separately. I'm not sure about exprList and propertyList, I tried different versions of them but the error would not change. %#include void…
bo_
  • 35
  • 8
1
vote
1 answer

Shift reduce conflict in YACC program

I have written this YACC program for validate string w.r.t grammar {ckanbm: n ≠ m ∧ k,m,n > 0}. NL is for newline. And tokens are passed by lex which is already there. But this error is given. I think the production rules are ok, but I receive this…
Hailey
  • 157
  • 1
  • 18
1
vote
1 answer

\[$end\] lookaheads in LALR

I am trying to understand, how bison builds tables for this simple grammar: input: rule ; rule: rule '+' '1' | '1' ; I was able to calculate LR(1) transition table and item sets, but I don't understand how state 3 is built and works: State…
1
vote
1 answer

Shift/Reduce conflict in CUP

I'm trying to write a parser for a javascript-ish language with JFlex and Cup, but I'm having some issues with those deadly shift/reduce problems and reduce/reduce problems. I have searched thoroughly and have found tons of examples, but I'm not…
1
vote
0 answers

Bison shift/reduce conflicts warning

I'm having trouble fixing shift/reduce conflicts in my grammar. This is the grammar: body: variable_decl function_list | variable_decl ; variable_decl: variable variable_decl | /* no variables declaration */ variable:…
Mike7
  • 11
  • 3
1
vote
1 answer

How does a parser solves shift/reduce conflict?

I have a grammar for arithmetic expression which solves number of expression (one per line) in a text file. While compiling YACC I am getting message 2 shift reduce conflicts. But my calculations are proper. If parser is giving proper output how…
Nikul Vyas
  • 363
  • 3
  • 7
  • 30
1
vote
2 answers

Bison subscript expression unexpected error

With the following grammar: program: /*empty*/ | stmt program; stmt: var_decl | assignment; var_decl: type ID '=' expr ';'; assignment: expr '=' expr ';'; type: ID | ID '[' NUMBER ']'; expr: ID | NUMBER | subscript_expr; subscript_expr: expr '['…
Emil Laine
  • 41,598
  • 9
  • 101
  • 157
1
vote
1 answer

Shift reduce conflicts in mid rule action bison

I have the following grammar that is giving me three shift reduce conflicts: boolexpression: boolexpression OR boolterm | boolterm ; boolterm: boolterm AND boolfact |…
user5651771
1
vote
0 answers

how to resolve shift/reduce conflict in yacc

I have a problem during my project(making mini C compiler). There is no error and I can scan and parse mini C source code file. But in *.output file I found State 17 conflicts: 2 shift/reduce State 19 conflicts: 2 shift/reduce State 57 conflicts: 8…
김종우
  • 11
  • 1
1
vote
2 answers

How to overcome shift-reduce conflict in LALR grammar

I am trying to parse positive and negative decimals. number(N) ::= pnumber(N1). number(N) ::= nnumber(N1). number(N) ::= pnumber(N1) DOT pnumber(N2). number(N) ::= nnumber(N1) DOT pnumber(N2). pnumber(N) ::= NUMBER(N1). nnumber(N) ::= MINUS…
Pdksock
  • 1,042
  • 2
  • 13
  • 26
1
vote
1 answer

shift/reduce error in yacc

I know this part of my grammar cause error but I don't know how to fix it I even use %left and right but it didn't help. Can anybody please help me to find out what is the problem with this grammar. Thanks in advance for your help. %token VARIABLE…
user1603454
  • 99
  • 1
  • 8