Iam trying to develop a program for a calculator using lex and yacc. I keeping getting 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 similiar problems but they had infinite recursions but this one doesn't have .
calc.l
%{
#include"y.tab.h"
%}
digits [0-9]*
%%
{digits} {return DIGITS}
%%
int yywrap()
{
}
calc.y
%{
#include<stdio.h>
%}
%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()
{
}