-
Notifications
You must be signed in to change notification settings - Fork 0
/
micro.lex
74 lines (60 loc) · 1.57 KB
/
micro.lex
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%{
#include "AST.hpp"
#include "CodeObject.hpp"
#include "LLString.hpp"
#include "Identifier.hpp"
#include "SymbolTable.hpp"
#include "SymbolTableStack.hpp"
#include "micro.h"
extern "C" int yylex();
%}
LETTER [A-Za-z]
DIGIT [0-9]
QUOTE \"
OPERATOR "+"|"-"|"*"|"/"|"="|"!"|"<"|">"|"("|")"|";"|","|"<"|">"
ASSIGN_OP ":="
COMMENT --
%%
{COMMENT}[^\n]*
{OPERATOR} { return yytext[0]; }
{ASSIGN_OP} { return ASSIGN_OP; }
PROGRAM { return PROGRAM; }
BEGIN { return _BEGIN; }
END { return END; }
FUNCTION { return FUNCTION; }
READ { return READ; }
WRITE { return WRITE; }
IF { return IF; }
ELSE { return ELSE; }
ENDIF { return ENDIF; }
WHILE { return WHILE; }
ENDWHILE { return ENDWHILE; }
RETURN { return RETURN; }
INT { return INT; }
VOID { return VOID; }
STRING { return STRING; }
FLOAT { return FLOAT; }
TRUE { return TRUE; }
FALSE { return FALSE; }
FOR { return FOR; }
ENDFOR { return ENDFOR; }
CONTINUE { return CONTINUE; }
BREAK { return BREAK; }
{DIGIT}+ {
yylval.intVal = atoi(yytext);
return INTLITERAL;
}
{QUOTE}[^"]*{QUOTE} {
yylval.stringList = new LLString(strdup(yytext));
return STRINGLITERAL;
}
{LETTER}({LETTER}|{DIGIT})* {
yylval.stringList = new LLString(strdup(yytext));
return IDENTIFIER;
}
{DIGIT}*"."{DIGIT}+ {
yylval.flVal = atof(yytext);
return FLOATLITERAL;
}
.|\n
%%