From ca8f17077af731cea01234530bf8c528481c7876 Mon Sep 17 00:00:00 2001 From: Oxore Date: Sat, 4 Jan 2025 22:56:24 +0300 Subject: Initial commit --- simple-c/lexer.l | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 simple-c/lexer.l (limited to 'simple-c/lexer.l') diff --git a/simple-c/lexer.l b/simple-c/lexer.l new file mode 100644 index 0000000..be983d1 --- /dev/null +++ b/simple-c/lexer.l @@ -0,0 +1,37 @@ +%{ +#include "parser.h" +#define YY_USER_ACTION yylloc.first_line = yylloc.last_line = yylineno; +%} + +%option noyywrap + +DIGIT [0-9] + +%% + +"-" { return MINUS; } +"+" { return PLUS; } +"*" { return MULT; } +"/" { return DIV; } +"=" { return EQUAL; } +"(" { return L_PAREN; } +")" { return R_PAREN; } + +(\.{DIGIT}+)|({DIGIT}+(\.{DIGIT}*)?([eE][+-]?[0-9]+)?) { + yylval.dval = atof(yytext); + return NUMBER; +} + +[ \t]+ { /* ignore spaces */ } + +"\n" { return END; } + +. { + printf( + "Error at line %d: unrecognized symbol \"%s\"\n", + yylloc.first_line, + yytext); + exit(0); +} + +%% -- cgit v1.2.3