Calculator/calc.l

32 lines
865 B
Text
Raw Permalink Normal View History

2023-11-26 15:56:00 +01:00
%{
#include <stdlib.h>
#include "calc.tab.h"
#include "calculator.h"
%}
%option outfile="calc.yy.cpp" header-file="calc.yy.h"
%option case-sensitive
%option array
D [0-9]
E [Ee][+-]?{D}+
%%
pi { return MATHPI; }
sin { return FCESIN; }
cos { return FCECOS; }
exp { return FCEEXP; }
log { return FCELOG; }
[a-zA-Z]+ { yylval.svalue = strdup (yytext); return IDENT; }
{D}+ { yylval.svalue = strdup (yytext); return INTEGER; }
{D}*\.{D}+({E})? { yylval.svalue = strdup (yytext); return DOUBLE; }
{D}*\.{D}*({E})? { yylval.svalue = strdup (yytext); return DOUBLE; }
\{.*\}
[ \t]+ /* ignored */
\n { return ENDLINE; }
. { return yytext[0]; }
%%
void prevent_unused (void) {
(void) yyunput;
/* (void) input; */
}