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

Irony Shift Reduce Problems

I have been trying to figure out how to fix some shift reduce conflicts I have. I have looked around and found different topics on fixing it but it seems like no matter what I do I just can't seem to find a way to fix these issues. I am trying to…
0
votes
1 answer

Shift/reduce conflict despite precedence rules

The language I'm writing a parser for has three constructs that are relevant here: the ord operator, represented by TOK_ORD, which casts character expressions into integer expressions, and [ ] and ., which are used for index and field access,…
user2752467
  • 864
  • 5
  • 16
0
votes
2 answers

shift/reduce errors BISON

I get 2 shift/reduce errors when trying to compile my grammar: program : declaration_list ; declaration_list : declaration_list declaration | declaration ; declaration : var_declaration | fun_declaration ; var_declaration: type_specifier…
0
votes
1 answer

Shift/reduce conflict with infix sections

I'm having trouble with a yacc-like implementation (using ocamlyacc, in particular) of a grammar that includes ordinary infix operations plus infix sections, like in Haskell. I desire all of these to be grammatical: (+1) (1+) (+) (1+1) However, I…
dubiousjim
  • 4,722
  • 1
  • 36
  • 34
0
votes
1 answer

Unary precedence in Bison

I am continuously getting shift/reduce conflicts when by parser tries to sort out whether something is a unary or binary operator. %token tHEX tOCT tDEC tRUNE %token tBOOL INTERPRETEDSTRING RAWSTRING tIDENTIFIER %token…
0
votes
1 answer

How do I rewrite a context free grammar so that it is LR(1)?

For the given context free grammar: S -> G $ G -> PG | P P -> id : R R -> id R | epsilon How do I rewrite the grammar so that it is LR(1)? The current grammar has shift/reduce conflicts when parsing the input "id : .id", where "." is the input…
0
votes
1 answer

Bison grammar occasionally passes, occasionally fails

I'm working extensively with Bison grammars for the first time. I have my grammar set up, and a little test suite to correlate results. Occasionally, the test suite passes: Reducing stack by rule 101 (line 613): $1 = nterm mathenv () -> $$ =…
user213345
0
votes
1 answer

shift/reduce because of a recursion rule

I'm trying to write a mini-compiler of a given language using flex & bison. It was working fine until I found out I forgot about a rule which has recursion in it, the rule being: liste_data : liste_data declar | declar; As I added it, I had…
Isma
  • 13
  • 6
0
votes
1 answer

Shift reduce error with empty rule in bison

I have below yacc grammar: OPTIONS:OPTIONS OPTION {printf("%s\n", "Options enabled");} | OPTION {printf("%s\n", "First option");} | ; OPTION: DEBUG …
0
votes
1 answer

Persistent Shift - Reduce Conflict in Goldparser

I'm really stuck with a Shift-Reduce conflict in Goldparser. I wrote a PHP-like grammar that theoretically should be able to parse the following script: public $Test = null; protected $bDemo = true; function Main() { } private function…
Elmue
  • 7,602
  • 3
  • 47
  • 57
0
votes
1 answer

ifequal construct grammar implementation

I have to create grammar that recognizes this: ifequal(exp1, exp2) statement1 smaller statement2 larger statement3 statement1 is executed if two expressions are equal, second if first is smaller third if it is larger. I tried to make…
Dejan
  • 3,046
  • 3
  • 28
  • 43
0
votes
2 answers

How to solve this S/R conflict

Here's a simplification of my working EBNF grammar: %token NEWLINE BLOCK_MARK A %start file file: block+ NEWLINE*; block: BLOCK_MARK line; line: A+; Both \n and EOF spit out NEWLINE as a token (so that a single ending NEWLINE isn't required before…
kaoD
  • 1,534
  • 14
  • 25
0
votes
1 answer

i am trying to build a parser for mini java where i am getting shift/reduce conflicts in the expression grammar part.I can't resolve this conflict

this is part of y.ouput file state 65 15 Expression: Expression . "&&" Expression 16 | Expression . "<" Expression 17 | Expression . "+" Expression 18 | Expression . "-" Expression 19 | Expression . "*"…
Gourav Saha
  • 43
  • 3
  • 10
0
votes
1 answer

shift/reduce conflict with if ... else statement

I'm trying to make a parser about a java like language, but with else statement, a shift/reduce conflict appears. I tried bison bison_file.y --report=state and the result about the conflict is: State 62 31 statement: if_statement . 65…
0
votes
1 answer

How does an LALR(1) grammar differentiate between a variable and a function call?

Given the following input: int x = y; and int x = y(); Is there any way for an LALR(1) grammar to avoid a shift/reduce conflict? The shift/reduce conflict is deciding to reduce at y or continue to (. (This is assuming that a variable name can be…
sdasdadas
  • 23,917
  • 20
  • 63
  • 148