shift-reduce-conflict

How to remove shift/reduse warning?

霸气de小男生 提交于 2019-12-12 04:45:15
问题 I am trying to make a compiler and I am now trying to make the parser. I get a warning on this state : State 89 62 expr: '(' expr . ')' 66 | expr . '+' expr 67 | expr . '-' expr 68 | expr . '*' expr 69 | expr . '/' expr 70 | expr . '%' expr 74 | expr . '&' expr 75 | expr . '|' expr 77 cond: expr . 78 | '(' expr . ')' 82 | expr . '=' expr 83 | expr . "<>" expr 84 | expr . '<' expr 85 | expr . '>' expr 86 | expr . ">=" expr 87 | expr . "<=" expr "<>" shift, and go to state 91 ">=" shift, and go

yacc shift-reduce for ambiguous lambda syntax

家住魔仙堡 提交于 2019-12-10 10:57:16
问题 I'm writing a grammar for a toy language in Yacc (the one packaged with Go) and I have an expected shift-reduce conflict due to the following pseudo-issue. I have to distilled the problem grammar down to the following. start: stmt_list expr: INT | IDENT | lambda | '(' expr ')' { $$ = $2 } lambda: '(' params ')' '{' stmt_list '}' params: expr | params ',' expr stmt: /* empty */ | expr stmt_list: stmt | stmt_list ';' stmt A lambda function looks something like this: map((v) { v * 2 },

How to solve a shift/reduce conflict?

两盒软妹~` 提交于 2019-12-09 16:15:48
问题 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 ::= IDENTIFIER (*) LPAREN parlist RPAREN under symbol LPAREN Now, I actually wanted it to shift so I'm pretty ok with it, but my professor told me to find a way to solve the

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

霸气de小男生 提交于 2019-12-08 20:16:00
问题 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 | expr '+' expr | expr '-' expr | expr '*' expr | expr '/' expr | INC expr %prec PREINC | DEC expr %prec PREINC | expr INC %prec POSTINC | expr DEC %prec POSTINC | '(' expr ')' ; %% Bison

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

江枫思渺然 提交于 2019-12-08 09:12:14
问题 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 pointer for the parser. This grammar produces the language satisfying the regular expression (id:(id)*)+ 回答1: It's easy enough to produce an LR(1) grammar for the same language. The trick is finding one which has a similar parse tree, or at least from

How to resolve a shift/reduce conflict forcing a shift or a reduce?

别等时光非礼了梦想. 提交于 2019-12-06 01:08:39
When there is a shift/reduce conflict in Yacc/Bison, is it possible to force the conflict to be solved exactly as you want? In other words: is it possible explicitly force it to prioritize the shift or the reduce? For what I have read, if you are happy with the default resolution you can tell the generator to not complain about it . I really don't like this because it is obfuscating your rational choice. Another option is to rewrite the grammar to fix the issue. I don't know if this is always possible and often this makes it much harder to understand. Finally, I have read the precedence rules

Shift/reduce conflicts in bison

元气小坏坏 提交于 2019-12-05 17:14:23
问题 I'm new to Bison and I'm having trouble with shift/reduce conflicts... I'm trying to load from file to array data[] : struct _data { char name[50]; char surname[50]; int year; } data[1000]; Here is part of my bison code: %token ID NUM NL EOF %% File : List EOF ; List : Record | List Record ; Record : Name Surname Year NL { count++; } | NL { count++; } | /*empty*/ ; Name : ID { strcpy(data[count].name, yytext); } ; Surname: ID { strcpy(data[count].surname, yytext); } ; Year : NUM { data[count]

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

别等时光非礼了梦想. 提交于 2019-12-05 06:14:42
问题 %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

How to solve a shift/reduce conflict?

蹲街弑〆低调 提交于 2019-12-04 04:40:51
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 ::= IDENTIFIER (*) LPAREN parlist RPAREN under symbol LPAREN Now, I actually wanted it to shift so I'm pretty ok with it, but my professor told me to find a way to solve the conflict. I'm blind. I've always read about the if/else conflict but to me this doesn't seem the case. Can

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

房东的猫 提交于 2019-12-03 20:26:01
%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? 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 not inherit any such thing even though it produces PLUS and MINUS . Associativity and predecence are