-
Notifications
You must be signed in to change notification settings - Fork 2
/
lex.l
55 lines (51 loc) · 1.32 KB
/
lex.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
%{
#include <llvm-c/Core.h>
#include "datatypes.h"
#include "y.tab.h"
#include "symbol.h"
static int install_id();
static int install_int();
extern int yyerror(char *);
%}
%option noyywrap
%option yylineno
digit [0-9]
alpha [a-zA-Z_]
id {alpha}({alpha}|{digit})*
int {digit}+
token [!$%&()*+,\-./:;<=>?\[\]^{|}~]
%%
[ \t\v\n\f\r] /* skip whitespace */
"//".*[\n] /* skip comments */
{id} {
yylval.sym = symbol_lookup(yytext);
if (!yylval.sym) yylval.sym = symbol_insert(yytext, ID);
return yylval.sym -> token;
}
{int} {
sscanf(yytext, "%u", &yylval.num);
return INT;
}
"+=" { return PA; }
"-=" { return NA; }
"*=" { return TA; }
"/=" { return DA; }
"%=" { return MA; }
"&=" { return AA; }
"^=" { return XA; }
"|=" { return OA; }
"<<=" { return LA; }
">>=" { return RA; }
"||" { return OR; }
"&&" { return AN; }
"==" { return EQ; }
"!=" { return NE; }
"<=" { return LE; }
">=" { return GE; }
"<<" { return LS; }
">>" { return RS; }
"++" { return PP; }
"--" { return NN; }
{token} { return yytext[0]; }
. { yyerror("Unknown character found"); }
%%