flex-bison-in-action/analyzers/polynomials/polynomials.l

21 lines
501 B
Plaintext

%{
#include "polynomials.tab.h"
#include <string.h>
void yyerror(const char *s);
%}
%option noyywrap
%%
[ \t]+ { /* skip whitespace */ }
\n { return 0; /* EOF */ }
[0-9]+ { yylval.num = atoi(yytext); return NUMBER; }
[a-zA-Z] { yylval.var = yytext[0]; return VARIABLE; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return MULTIPLY; }
"(" { return LPAREN; }
")" { return RPAREN; }
. { yyerror("Unexpected character"); }
%%