-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
37 lines (32 loc) · 816 Bytes
/
lexer.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
%{
#include <math.h>
#include "parser.h"
extern "C" int yylex();
%}
%option noyywrap
%%
"# solver = entity" { return ENTITY; }
"# solver = population" { return POPULATION; }
espece { return TYPE; }
diametre { return DIAM; }
taille { return SIZE; }
vitesse { return SPEED; }
init { return INIT; }
[A-Za-z_][A-Za-z_0-9]* { yylval.sval = strdup(yytext);
return ID; }
[0-9]+\.[0-9]+ { yylval.fval = atof(yytext);
return FLOAT; }
[0-9]+ { yylval.ival = atoi(yytext);
return INT; }
\/\/.* { } // Ignore comments
"," { return COMMA; }
";" { return SEMI; }
"(" { return OPARAN; }
")" { return CPARAN; }
"=" { return EQUAL; }
"->" { return ARROW; }
"+" { return PLUS; }
"[" { return OBRACKET; }
"]" { return CBRACKET; }
[ \t\n] { } // Ignore whitespace
%%