tokin/tökin.l
2025-03-10 17:39:02 +02:00

40 lines
601 B
Text

%{
#include <stdlib.h>
void yyerror(const char *);
#include "y.tab.h"
%}
%%
[a-zA-Z_]([0-9a-zA-Z_])* {
char *identifier = strdup(yytext);
if (identifier == NULL)
yyerror("out of memory");
yylval.text = identifier;
return IDENTIFIER;
}
[0-9]+(\.[0-9]+)? {
char *literal = strdup(yytext);
if (literal == NULL)
yyerror("out of memory");
yylval.text = literal;
return NUMBER;
}
[-+*/()<>=;|^\n] return *yytext;
">=" return GE;
"<=" return LE;
"==" return EQ;
"!=" return NE;
[ \t]+ ;
. { yyerror("invalid character"); return ERROR; }
%%
int yywrap(void) {
return 1;
}