shift-reduce-conflict

Persistent Shift - Reduce Conflict in Goldparser

别等时光非礼了梦想. 提交于 2021-01-29 17:50:49
问题 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 Run() { } At the top I want to assign the global variables and after that come the function definitions. To narrow down the problem I reduced my large grammar to the following lines which can reproduce the error. Obviously this is incomplete. The functions have

Shift/reduce conflict despite precedence rules

五迷三道 提交于 2020-01-07 07:19:21
问题 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, respectively, just like in C. Here's an excerpt from my precedence rules: %right TOK_ORD %left PREC_INDEX PREC_MEMBER My grammar has a nonterminal expr , which represents expressions. Here's some relevant snippets from the grammar ( TOK_IDENT is a

Shift/reduce conflict despite precedence rules

你。 提交于 2020-01-07 07:19:20
问题 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, respectively, just like in C. Here's an excerpt from my precedence rules: %right TOK_ORD %left PREC_INDEX PREC_MEMBER My grammar has a nonterminal expr , which represents expressions. Here's some relevant snippets from the grammar ( TOK_IDENT is a

Concatenation shift-reduce conflict

别等时光非礼了梦想. 提交于 2020-01-04 06:22:09
问题 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 shift/reduce conflict. Grammar: precedence left PLUS; e ::= e exp | exp; exp ::= concat | literal; concatenation ::= exp PLUS exp | LPAREN exp RPAREN; literal ::= IDENTIFIER | STRING | IDENTIFIER LPAREN RPAREN; // THIS PRODUCES THE ERROR Input: x + x +

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

对着背影说爱祢 提交于 2019-12-29 09:34:47
问题 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 | Hungry NoHungry %prec APP | if Hungry then Hungry else Hungry %prec IF NoHungry : true | false bison -v tells me there are two conflicts in the following situation: State 12 2 Hungry: Hungry . NoHungry 3 | if Hungry then Hungry else Hungry . true shift, and go to state 2 false shift, and go to state 3 true [reduce using rule

Shift/Reduce conflict in CUP

我是研究僧i 提交于 2019-12-24 20:11:17
问题 I'm trying to write a parser for a javascript-ish language with JFlex and Cup, but I'm having some issues with those deadly shift/reduce problems and reduce/reduce problems. I have searched thoroughly and have found tons of examples, but I'm not able to extrapolate these to my grammar. My understanding so far is that these problems are because the parser cannot decide which way it should take because it can't distinguish. My grammar is the following one: start with INPUT; INPUT::= PROGRAM;

Using precedence in Bison for unary minus doesn't solve shift/reduce conflict

断了今生、忘了曾经 提交于 2019-12-21 06:00:45
问题 I'm devising a very simple grammar, where I use the unary minus operand. However, I get a shift/reduce conflict. In the Bison manual, and everywhere else I look, it says that I should define a new token and give it higher precedence than the binary minus operand, and then use "%prec TOKEN" in the rule. I've done that, but I still get the warning. Why? I'm using bison (GNU Bison) 2.4.1. The grammar is shown below: %{ #include <string> extern "C" int yylex(void); %} %union { std::string token;

Bison shift/reduce conflict / reduce/reduce conflict warnings

风格不统一 提交于 2019-12-19 04:55:08
问题 When i run this bison code in Ubuntu Linux i get these warnings : 1shift/reduce conflict [-Wconflicts-sr] 2 reduce/reduce conflicts [-Wcolficts-sr] Here's a screenshot for more clarity: http://i.imgur.com/iznzSsn.png Edit: reduce/reduce errors are in line 86 : typos_dedomenwn line 101: typos_synartisis and the shift/reduce error is in: line 129: entoli_if I can't find how to fix them could someone help? Here's the bison code bellow : %{ #include <stdio.h> #include <stdlib.h> #include <string

Bison shift-reduce conflict - Unable to resolve

一笑奈何 提交于 2019-12-17 20:16:07
问题 The grammar is as follows: 1. program -> declaration-list 2. declaration-list -> declaration-list declaration | declaration 3. declaration -> var-declaration | fun-declaration 4. var-declaration -> type-specifier ID ; | type-specifier ID [ NUM ] ; 5. type-specifier -> int | void 6. fun-declaration -> type-specifier ID ( params ) compound-stmt 7. params -> param-list | void 8. param-list -> param-list , param | param 9. param -> type-specifier ID | type-specifier ID [ ] 10. compound-stmt -> {

Why does this simple grammar have a shift/reduce conflict?

给你一囗甜甜゛ 提交于 2019-12-12 08:16:43
问题 %token <token> PLUS MINUS INT %left PLUS MINUS THIS WORKS: exp : exp PLUS exp; exp : exp MINUS exp; exp : INT; THIS HAS 2 SHIFT/REDUCE CONFLICTS: exp : exp binaryop exp; exp : INT; binaryop: PLUS | MINUS ; WHY? 回答1: This is because the second is in fact ambiguous. So is the first grammar, but you resolved the ambiguity by adding %left . This %left does not work in the second grammar, because associativity and precedence are not inherited from rule to rule. I.e. the binaryop nonterminal does