-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.l
More file actions
executable file
·47 lines (42 loc) · 1.64 KB
/
scanner.l
File metadata and controls
executable file
·47 lines (42 loc) · 1.64 KB
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
%{
#include "y.tab.h"
#include <stdlib.h>
#include "utils.h"
#include <llvm-c/Core.h>
void yyerror(LLVMModuleRef module, LLVMBuilderRef builder, const char* s);
%}
DIGIT [0-9]
ID [A-Za-z][A-Za-z0-9]*
%option noyywrap
%%
if { return IF; }
else { return ELSE; }
while { return WHILE; }
do { return DO; }
for { return FOR; }
print { return PRINT; }
int { return INT_TYPE; }
float { return FLOAT_TYPE; }
bool { return BOOL_TYPE; }
true { return TRUE; }
false { return FALSE; }
{DIGIT}+ { yylval.value = atoi(yytext); return VAL; }
{DIGIT}+.{DIGIT}+ { yylval.value = atof(yytext); return VAL2; }
{ID} { yylval.id = string_int_get(&global_ids, yytext); return ID; }
[ \t\r\n]+ /* discard whitespace */
[-*/+%><=;\{\}\(\)] { return *yytext; }
&& { return AND; }
\|\| { return OR; }
\++ { return INC; }
-- { return DEC; }
\+= { return INCX; }
-= { return DECX; }
\*= { return MULX; }
\/= { return DIVX; }
%= { return MODX; }
\>= { return GE; }
\<= { return LE; }
== { return EQ; }
!= { return NE; }
. yyerror(NULL, NULL, "Unexpected character");
%%