I want to make parser for simple calculator but I cant uderstand whu I get error for simple input. Flex file looks like this
%{
#include "exp.tab.h"
#include <string.h>
%}
blanks [ \t\n]+
%%
{blanks} { /* ignore */ }
[0-9]+ {yylval= strtol(yytext, NULL, 10);
return(NUMB);}
%%
Bison file looks like this:
%{
#include <stdio.h>
%}
%token NUMB
%left '+'
%%
exp:
NUMB { $$ = $1; }
| exp '+' exp { $$ = $1 + $3; }
%%
int yyerror(char *s) {
printf("yyerror : %s\n",s);
}
int main(void) {
yyparse();
}
For input
123 + 12
i get error message.Why is this happening?
flex-lexer
is, actually... – Charles