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

reduce/reduce conflict in CUP

I am implementing a parser for a subset of Java using Java CUP. The grammar is like vardecl ::= type ID type ::= ID | INT | FLOAT | ... exp ::= ID | exp LBRACKET exp RBRACKET | ... stmt ::= ID ASSIGN exp SEMI This works fine, but when I…
0
votes
1 answer

Bison how to describe optional syntax in grammar without shift-reduce conflicts?

I have a file that is described with a grammar. It has a section that can consist of one or two kinds of contents, and it can be in arbitrary order: ... type_a_thing type_b_thing type_b_thing type_a_thing .... Or…
waszil
  • 390
  • 2
  • 5
  • 15
0
votes
1 answer

shift-reduce conflicts with expressions

I am writing a grammar for a complete programming language of my own design. This language has several types of expressions that are combined in different ways in different situations. I have a pretty good idea of how I want it to work, but I am…
0
votes
1 answer

Happy/YACC reducing when it should shift

I'm working on a parser and I'm really frustrated. In the language, we can have an expression like: new int[3][][] or new int[3] Most of it parses correctly, except for the empty arrays at the end. In my parser I have: Expression : int …
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
0
votes
1 answer

Resolve conflict in bison grammar with space separated expression lists + if/then/else

I have the following yacc/bison/happy grammar: %token if TokenIf then TokenThen else TokenElse true TokenTrue false TokenFalse %left APP %right IF %% Hungry : NoHungry |…
Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38
0
votes
1 answer

Conflicts in writing a parser with Bison

I am trying to write a parser with Bison. I get the warning: warning: 5 shift/reduce conflicts [-Wconflicts-sr] My rules: %% Prog : F {}; F : {}; F : D F {}; D : R ID LP Fr RP LB Ss RB {}; R : T {}; R : VOID {}; Fr : …
SuzLy
  • 133
  • 1
  • 10
0
votes
1 answer

How to solve bison reduce/reduce conflict in my code?

I'm new to bison.. I've wrote a grammar rule for if, else if and else statement.. I got reduce reduce conflict though.. Can anyone help ? I've tried everything I've found but as I told I'm new and I don't understand exactly what happens.. Here's my…
user6058265
0
votes
1 answer

How to detect shift/reduce conflicts in bison?

I am new in Bison. I've made my .y file but in the compilation I get this error: warning: 42 shift/reduce conflicts [-Wconflicts-sr] I've opened the .output file that is produced and I've seen the following but can't understand it and can't figure…
user6058265
0
votes
0 answers

Small Shift/Reduce conflict in CUP

I'm having a minor problem in trying to figure out how to resolve a conflict in my CUP parser project. I understand why the error is occurring, VariableDeclStar's first terminal can be ID, as well as Type, which brings up the conflict, however I…
Hacker Zen
  • 11
  • 3
0
votes
1 answer

Why does this give 1 shift/reduce conflict in yacc / bison

I want to parse a simple syntax I derived from the /etc/hosts.allow format. I'm getting a shift/reduce conflict on yacc. Can I ignore the shift/reduce conflict warning or can I amend it somehow?: %token ALLOW %token DENY %token COMMENT %token…
Krischu
  • 1,024
  • 2
  • 15
  • 35
0
votes
1 answer

Shift/Reduce IF-ELSE conflict in my grammar

I'm trying to write a small parser. Unfortunately I get a "shift-reduce conflict". Grammars are not my strong point, and I only need to get this one small thingy done. Here's the reduced grammar that produces the error: stmts_opt -> stmts ; stmts…
AbdelKh
  • 499
  • 7
  • 19
0
votes
1 answer

Shift/reduce conflict with args and kwargs - PLY

I'm writing parser for Python-like language, which allows to pass two types of arguments (positional and named) to functions. And, like in Python, named argument must be passed after positional. I wrote a grammar for it, but it has shift/reduce…
J. Doe
  • 3
  • 1
  • 2
0
votes
2 answers

warning: rule useless in parser due to conflicts: $@1: /* empty */

I have this warning when I put code {printf("something");} in the middle of the rule, if I put at the end of the rule, I don´t have the error and everything works fine. This throw the warning in the tittle and throw 1 shift/reduce…
Martinii
  • 1
  • 2
0
votes
2 answers

Conflicts in Parser for Propositional logic with IF-THEN-ELSE ternary operator

I want to implement the Parser for proposition logic which has the following operators in decreasing order of precedence: NOT p p AND q p OR q IF p THEN q p IFF q IF p THEN q ELSE r The main issue is with the IF-THEN-ELSE operator. Without it, I…
Deepak Saini
  • 2,810
  • 1
  • 19
  • 26
0
votes
0 answers

shift/reduce conflict - identifier

I have a shift-reduce conflict in this part of code.... ::= | ::= '.' Identifier | '[' ']' | '^' |