I am trying to develop a calculator program using lex and yacc. I save the following error:
calc.y: warning: 5 nonterminals useless in grammar [-Wother]
calc.y: warning: 8 rules useless in grammar [-Wother]
calc.y:8.1: fatal error: start symbol I does not derive any sentence
I : E '\n' {printf("%d\n",$1);}
I looked at similar problems, but they had endless recursions, but that wasn’t.
calc.l
%{
#include"y.tab.h"
%}
digits [0-9]*
%%
{digits} {return DIGITS}
%%
int yywrap()
{
}
calc.y
%{
%}
%token DIGITS
%%
I : E '\n' {printf("%d\n",$1);}
;
E : E '+' F {$$ = $1 + $3;}
| E '-' F {$$ = $1 - $3;}
;
F : F '*' G {$$ = $1 * $3;}
| F '/' G {$$ = $1 / $3;}
G :'('E')'
| DIGITS
;
%%
int main()
{
yyparse();
}
int yyerror()
{
}
source
share