I am trying to write a yacc program to find out whether an Arithmetic Expression is valid or not. My program seems to be running properly but I am getting a warning in console.
warning: 2 shift/reduce conflicts [-Wconflicts-sr]
lex code
%{
#include "y.tab.h"
%}
%%
[0-9]+ { return NUMBER; }
[_a-zA-Z][_a-zA-Z0-9]* { return ID; }
[-+*/] { return OPERATOR; }
.|\n { return *yytext; }
%%
int yywrap(){
return 1;
}
yacc code
%{
#include<stdio.h>
int yylex();
void yyerror(const char*);
%}
%token NUMBER ID OPERATOR
%%
E : E '\n' { return 0; }
| E OPERATOR E
| '(' E ')'
| NUMBER
| ID
;
%%
void yyerror(const char* s){
printf("%s\n", s);
}
int main(){
if(yyparse() == 0)
printf("Valid Arithmetic Expression\n");
else
printf("Invalid Arithmetic Expression\n");
}
How can I get rid of this?