shift-reduce-conflict

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 them like this: S: S 'b' T | T T: 't' My question is: Is it better to leave the gram...

Shift reduce and reduce reduce conflicts

I'm having a hard time wrapping my head around this and need some help understanding shift reduce and reduce reduce conflicts. I have a grammar which I can't seem to understand why it's problematic. I could attach the grammar, but I want to learn how this really works. First question, what type of parser does MGrammer create? As I under...

How to fix YACC shift/reduce conflicts from post-increment operator?

I'm writing a grammar in YACC (actually Bison), and I'm having a shift/reduce problem. It results from including the postfix increment and decrement operators. Here is a trimmed down version of the grammar: %token NUMBER ID INC DEC %left '+' '-' %left '*' '/' %right PREINC %left POSTINC %% expr: NUMBER | ID | ...

Problem with a shift-reduce conflict in my grammar

I'm trying to write a small parser with Irony. 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: ExpressionTerm := "asd" LogicalExpression := ExpressionTerm | LogicalExpression "AND" LogicalExpres...

Help with Shift/Reduce conflict - Trying to model (X A)* (X B)*

Im trying to model the EBNF expression ("declare" "namespace" ";")* ("declare" "variable" ";")* I have built up the yacc (Im using MPPG) grammar, which seems to represent this, but it fails to match my test expression. The test case i'm trying to match is declare variable; The Token stream from the lexer is KW_Declare KW_Varia...

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 of the following: If the grammar is ambiguous (e.g. if-then-else ambiguity), change the l...

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 '+' for both add and subtract. But this is an example) expr: INTEGER | ...

Why do i have a shift reduce/conflict on the ')' and not '('?

I have syntax like %(var) and %var and (var) My rules are something like optExpr: | '%''('CommaLoop')' | '%' CommaLoop CommaLoop: val | CommaLoop',' val Expr: MoreRules | '(' val ')' The problem is it doesnt seem to be able to tell if ) belongs to %(CommaLoop) or % (val) but it complains on the ) inst...

Telling Bison/Yacc to shift and not reduce to resolve a conflict

I have a situation where there is a rule with a shift/reduce conflict that i understand. I want a rule to never reduce until at the last moment possible (end of line). So I would like to say always shift. How do i do this? ...

CUP generates many shift-reduce confilcts...

Hi everyone, I want to build parser with CUP tool... I've built LALR(1) grammar from language specification but it seems that I've done it wrong. When CUP generates parser it shows many shift-reduce conflicts that unfortunately causes faulty notifications of syntax errors... I guess that resolving SF conflicts in favor of shift causes t...

yacc shift reduce problem

i have what i think is a simple part of my grammar this is getting an error from yacc. i know i need to add a %prec somewhere, but not really sure where. Assignment : Ref '=' Ref | Ref '=' Expression | Ref '=' Value | Ref '=' FunctionCall ; Ref : ID | ID '[' Expression ']' ; Value : ...

Shift / reduce conflicts in grammar of arithmetic expression with n-ary sums / products

Parsing binary sums / products are easy, but I'm having troubles defining a grammar that parses a + b * c + d + e as sum(a, prod(b, c), d, e) My initial (naive) attempt generated 61 shift / reduce conflicts. I'm using java cup (but I suppose a solution for any other parser generator would be easily translated). ...

How to solve a shift/reduce conflict?

Hi, I'm using CUP to create a parser that I need for my thesis. I have a shift/reduce conflict in my grammar. I have this production rule: command ::= IDENTIFIER | IDENTIFIER LPAREN parlist RPAREN; and I have this warning: Warning : *** Shift/Reduce conflict found in state #3 between command ::= IDENTIFIER (*) and command :...

shift/reduce conflict with SableCC

Hi guys! I'm at my first experience with SableCC and grammar definition. I have the following grammar (a part of it): query = {atop} attroperator | {query_par} l_par query r_par | {query_and} [q1]:query logic_and [q2]:query | {query_or} [q1]:query logic_or [q2]:query | {query_not} ...

Bison Shift/Reduce conflict for simple grammar

I'm building a parser for a language I've designed, in which type names start with an upper case letter and variable names start with a lower case letter, such that the lexer can tell the difference and provide different tokens. Also, the string 'this' is recognised by the lexer (it's an OOP language) and passed as a separate token. Fina...

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 very similar. Example: Warning : *** Shift/Reduce conflict found in state #150 between a...