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

Parsing a function call (e.g. `exp '(' exp ')'`) in Bison: results in shift/reduce errors (precedence issue)

I'm trying to parse a function call (currently just one argument, but I'll allow for several when I get it working). Suppose exp is defined as %left '+' %precedence CALL exp: exp '+' exp { ... } | exp '(' exp ')' %prec CALL { ... } | …
Doot
  • 555
  • 5
  • 15
0
votes
2 answers

reduce-reduce, shift-reduce conflicts in a grammar

expression -> expression OPER expression expression -> PREFIX expression expression -> expression POSTFIX expression -> expression ‘?’ expression ‘:’ expression expression -> expression ‘[’ expression ‘]’ expression -> expression ‘(’ expression…
0
votes
1 answer

Shift-reduce and reduce-reduce conflicts with LR

This is the grammar: expr-> expr OPER expr expr->PREFIX expr expr->expr POSTFIX expr->expr ‘?’ expr ‘:’ expr expr->expr‘[’ expr ‘]’ expr->expr‘(’ expr ‘)’ expr->ID expr->CONSTANT expr->‘(’ expr‘) I cannot find the shift-reduce and reduce-reduce…
0
votes
1 answer

Where is the shift/reduce conflict in this yacc grammar?

I'm writing a parser for a language called C-. I have to write the grammar so its not ambiguous and I can't use any %prec statements in Bison. I've corrected all but 1 shift/reduce conflict and I can't figure out where it is. Any ideas? My .output…
0
votes
1 answer

Bison shift/reduce conflict ambigous

when i try to use$ bison --output=calcy.c -d calc.y i get this msg: calc.y: conflicts: 2 shift/reduce and this is my code program:DEBUT corps FIN ; corps:liste_declaration liste_instruction ; liste_declaration: |…
Ahmed Laggoun
  • 85
  • 1
  • 11
0
votes
1 answer

Java cup: Shift/Reduce conflict

I'm trying to write a parser using JFlex and Cup, but I have some issues dealing with recursive pointed notation like function call with recursive properties access like : var x = obj.property1.functionCall(p1, p2).property2; Here is the related…
Polla Toube
  • 178
  • 3
  • 10
0
votes
1 answer

Beaver parser generator shift-reduce conflicts connected to dangling else

I am feeding a (generated) grammar to Beaver parser generator. Multiple shift-reduce conflicts are caused by it seems like the dangling else problem in this rules: Condition = IF LPAR Expression.expression RPAR Statement.trueStatement…
0
votes
2 answers

LALR(1) shift/reduce error using % for both percent and mod

I started a project with a grammar that used % (and the word mod) for modulus operators, and now I would like to add % as a trailing unary operator to divide by 100. A few notes, I don't work with a C-based language, I have implemented my own…
Marius
  • 3,372
  • 1
  • 30
  • 36
0
votes
1 answer

Solving small shift reduce conflict

I have had a shift-reduce conflict and reduced it to a couple of lines: start : instruction_A; instruction_A : instruction_A instruction | ; instruction : RETURN 'X' …
Afonso Matos
  • 2,406
  • 1
  • 20
  • 30
0
votes
1 answer

Shift/reduce conflit ply yacc

i'm doing a ply yacc compiler and i'm having the following warning : WARNING: 9 shift/reduce conflicts Here are my rules to create a syntaxic tree. def p_programme_statement(p): ''' programme : statement ''' p[0] = AST.ProgramNode(p[1]) def…
David
  • 221
  • 3
  • 13
0
votes
1 answer

Shift-Reduce Conflict in YACC for a rule starting with Action

%token A B %% start: {printf("Starting…\n");} A A | A B; My book says that there is a shift-reduce conflict when the token is A because yacc converts to code to this. %token A B %% start: empty A A | A B; empty: {printf("Starting…\n");} ; I…
BoraKurucu
  • 39
  • 1
  • 1
  • 8
0
votes
1 answer

Creating shift-reduce / reduce-reduce free grammars

I'm trying to implement a simple Java like language parser in sablecc, although I'm constantly running into shift-reduce / reduce-reduce problems when implementing if, while and block statements. For instance, I've considered the following: stmts =…
0
votes
0 answers

Bison shift/reduce conflict with anonymous function call

My language allows anonymous function declaration like (x: int):int => { return x * x - x }. To call this simply write (expression). But I also have to enclose an expression within parentheses for precedence, for example x*(y+z). Now bison raises…
Chitholian
  • 432
  • 1
  • 10
  • 19
0
votes
1 answer

Shift/reduce conflict with ambiguous grammar

I've been stuck with some ambiguous grammar for a while now as yacc reports 6 shift/reduce conflicts. I've looked in the y.output file and have tried to understand how to look at the states and figure out what to do to fix the ambiguous grammar but…
David
  • 3
  • 1
0
votes
0 answers

how to solve shift-reduce conflict in yacc

I wrote the c-minor compiler with yacc and it now says it has 2 shift-reduce conflict and it shows these 2 lines: line has var '-=' line has var '+=' expression : var '=' expression |var '+=' expression |var '−='…