Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting conflicts: 1 shift/reduce
    primarykey
    data
    text
    <p>I'm new to bison and I'm getting a "conflicts: 1 shift/reduce" error. Can anyone shed some light on this?</p> <p>Here's the y file.</p> <p>test.y:</p> <pre><code>%{ #include &lt;stdio.h&gt; #include &lt;string.h&gt; #define YYERROR_VERBOSE #define YYDEBUG 1 void yyerror(const char *str); int yywrap(); %} %union { int integer; char *string; } %token &lt;string&gt; VAR_LOCAL %token &lt;integer&gt; LIT_NUMBER %token &lt;string&gt; LIT_STRING %token WS_LINEBRK //%token SYMB_EQL %token SYMB_PLUS %token SYMB_MINUS %token SYMB_MUL %token SYMB_DIV %% /* // Sample input num = 10 str = "this is a string" */ inputs: /* empty token */ | literal | variable | inputs stmt WS_LINEBRK ; stmt: variable "=" exps ; exps: variable op literal | variable op variable | literal op literal | literal op variable ; op: SYMB_PLUS | SYMB_MINUS | SYMB_MUL | SYMB_DIV ; variable: VAR_LOCAL { printf("variable: %s\n", $1); } ; literal: number | string ; string: LIT_STRING { printf("word: %s\n", $1); } ; number: LIT_NUMBER { printf("number: %d\n", $1); } ; %% void yyerror(const char *str) { fprintf(stderr,"error: %s\n",str); } int yywrap() { return 1; } main() { yyparse(); } </code></pre> <p>Here's the lex file test.l:</p> <pre><code>%{ #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include "y.tab.h" int line_no = 0; %} %% [a-z][a-zA-Z0-9]* { // local variable yylval.string=strdup(yytext); return VAR_LOCAL; } [0-9]+ { //number literal yylval.integer=atoi(yytext); return LIT_NUMBER; } = return SYMB_EQL; \+ return SYMB_PLUS; \- return SYMB_MINUS; \* return SYMB_MUL; \/ return SYMB_DIV; \"[-+\!\.a-zA-Z0-9' ]+\" { // word literal yylval.string=strdup(yytext); return LIT_STRING; } \n { // line break printf("\n"); return WS_LINEBRK; } [ \t]+ /* ignore whitespace */; %% </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload