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
2
votes
2 answers

Concatenation shift-reduce conflict

I have a simple grammar for JavaCUP's LR(1) parser that recognises concatenation expressions of identifiers and strings. I also want to add some empty function calls as a possible concatenation argument. However, when I try that, it leads to a…
2
votes
2 answers

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…
Stephen Cross
  • 1,003
  • 1
  • 8
  • 19
2
votes
1 answer

Bison shift/reduce conflict / reduce/reduce conflict warnings

When I run this bison code in Ubuntu Linux i get these warnings: - shift/reduce conflict [-Wconflicts-sr] - reduce/reduce conflicts [-Wcolficts-sr] Here's a screenshot for more clarity: https://i.stack.imgur.com/KEDy1.png Edit: reduce/reduce errors…
fortyeight
  • 23
  • 1
  • 4
2
votes
1 answer

shift/reduce conflict with SableCC

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 …
dierre
  • 7,140
  • 12
  • 75
  • 120
2
votes
1 answer

Fix shift/reduce conflict in bison grammar

The bison grammar I wrote for parsing a text file gives me 10 shift/reduce conflicts. The parser.output file doesn't help me enough. The file gives me information as: State 38 conflicts: 5 shift/reduce State 40 conflicts: 4 shift/reduce State 46…
Jackzz
  • 1,417
  • 4
  • 24
  • 53
2
votes
1 answer

shift/reduce Error with Cup

Hi i am writing a Parser for a Programming language my university uses, with jflex and Cup I started with just the first basic structures such as Processes an Variable Declarations. I get the following Errors Warning : *** Shift/Reduce conflict…
2
votes
4 answers

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 …
what
  • 41
  • 4
2
votes
2 answers

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…
user34537
2
votes
2 answers

Why does my ternary operator cause a shift-reduce conflict?

The following is my grammar: arithmetic_expression : expression + expression | expression - expression expression : constant | ID | arithmetic_expression …
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
2
votes
2 answers

Shift/Reduce conflicts in a propositional logic parser in Happy

I'm making a simple propositional logic parser on happy based on this BNF definition of the propositional logic grammar, this is my code { module FNC where import Data.Char import System.IO } -- Parser name, token types and error function…
2
votes
1 answer

shift/reduce conflict in Happy

How can I make correct rules for parsing if-then[-else] case? Here is some grammar: { module TestGram (tparse) where } %tokentype { String } %token one { "1" } if { "if" } then { "then" } else { "else" …
user1374768
  • 288
  • 2
  • 11
2
votes
4 answers

Shift-reduce conflicts in a simple(?) grammar

I am trying to describe a grammar in bison but I am unsure if it can be done. My intended grammar is this: %token A B C D SEP %% items : /* empty */ | items_nonempty ; items_nonempty : item |…
reddish
  • 1,360
  • 2
  • 12
  • 27
1
vote
0 answers

Can the grammar of the concatenation of two lists with common elements be written as an LALR grammar without any collisions

Can the following ABNF rules be written as a bison LALR grammar without any conflicts (shift/reduce or reduce/reduce)? Among them, lowercase letters are non-terminal symbols, and uppercase letters are terminal symbols. s = [*(A / D) D] *(A / B) The…
1
vote
1 answer

How Can I make it able to solve with LALR(1)

*X-> Ya| cYb | Zb | cZa Y-> q | Eplison | XaZ Z-> f | q* I've done with LR(1) parsing table and also proved that this is not LALR(1) but is there any way to make it able so that I can make LALR(1) for this?
1
vote
1 answer

LR(1) Parser: Why adding an epsilon production makes r/r or s/r conflicts

I wanted to make a reader which reads configuration files similar to INI files for mswin. It is for exercise to teach myself using a lexer/parser generator which I made. The grammar is: %lexer HEADER ::= "\\[[0-9a-zA-Z]+\\]" TRUE ::=…
Felix.leg
  • 622
  • 1
  • 4
  • 13
1 2
3
11 12