modified once more. After removing the recursions, and writing a code for infix expression :
it also contains precedence checking, and no recursive grammar and no start Non terminal and also an error message.
%{
#include<stdio.h>
%}
%token ALPHA NUMBER PLUS MINUS MUL DIV LPAR RPAR
%%
expr : expr PLUS term { printf("its an infix expression"); }
| expr MINUS term
| term
;
term : term MUL factor
| term DIV factor
| factor
;
factor : LPAR expr RPAR
| NUMBER
| ALPHA
;
%%
main()
{
yyparse();
}
int yyerror (char *s)
{
printf("Not an infix expression");
}
is this okay now ?
No it isn’t. Apart from all the conflicts, it doesn’t define any operator precedence. There are plenty of correct examples of LR expression grammars available on the Internet.
EDIT: Unary minus goes in the missing
primaryrule. Fromfactorit usually goes like this: