-
Notifications
You must be signed in to change notification settings - Fork 2
/
lexer.lex
executable file
·130 lines (126 loc) · 4.83 KB
/
lexer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%{
#include <stdio.h>
#include <string.h>
#include "AST.h"
#include "parser.hpp"
#define SAVE_TOKEN yylval.str = strdup(yytext);
void showError();
%}
%option noyywrap
%option never-interactive
numbers ([0-9])+
identifier ([a-zA-Z_][a-zA-Z_0-9]*)
string_const (\"(\\.|[^"])*\")
comment "//".*"\n"
%%
[ \t\n] ;
"true" {return B_TRUE;}
"false" {return B_FALSE;}
":" {return (COLON);}
";" {return (SEMICOLON);}
"." {return (DOT);}
"{" { return L_BRACE; }
"}" { return R_BRACE; }
"(" { return L_PARAN; }
")" { return R_PARAN; }
"]" { return R_SQR; }
"[" { return L_SQR; }
"," { return COMMA; }
"Λ" {return CONJUN;}
"V" {return DISJUN;}
"scope" {return SCOPE;}
"return" { return RETURN; }
"func" { return FUNC;}
"if" { return IF; }
"else" { return ELSE; }
"while" { return WHILE; }
"where" {return WHERE_C;}
"def" {return DEF;}
"do" {return DO;}
"reg" {return REG_64;}
"reg_16" {return REG_16;}
"reg_32" {return REG_32;}
"reg_id" {return REG_64_ID;}
"reg_16_id" {return REG_16_ID;}
"reg_32_id" {return REG_32_ID;}
"mem" {return MEM;}
"Const" {return CONST;}
"fp" {return REG_64_FP;}
"sp" {return REG_64_SP;}
"r0" {return REG_64_RAX;}
"r1" {return REG_64_RBX;}
"pc" {return REG_64_PC;}
"NULL" {return NULL_PTR;}
"global" {return GLOBAL;}
"local" {return LOCAL;}
"init" {return INIT;}
"rule" {return RULE;}
"IsType" {return ISTYPE;}
"TypeOf" {return TYPEOF;}
"tuple" {return TUPLE;}
"char" {return CHAR;}
"pair" {return PAIR;}
"var" {return VAR;}
"uint32" {return UINT32;}
"uint64" {return UINT64;}
"bool" {return BOOL;}
"file" {return FILE_IO;}
"line" {return FILE_LINE;}
"int" {return INT;}
"addr" {return ADDR_INT;}
"double" {return DOUBLE;}
"dict" {return DICT;}
"vector" {return VECT;}
"set" {return SET;}
"inst" {return INST;}
"ssanode" {return SSANODE;}
"loop" {return LOOP;}
"module" {return MODULE;}
"basicblock" {return BASICBLOCK;}
"func" {return FUNC;}
"at" {return T_AT;}
"before" {return T_BEFORE;}
"after" { return T_AFTER;}
"entry" {return T_ENTRY;}
"exit" {return T_EXIT;}
"iter" {return T_ITER;}
"for" {return FORLOOP;}
"usage" {return USAGE;}
"Call" {return OP_CALL;}
"Mov" {return OP_MOV;}
"Add" {return OP_ADD;}
"Sub" {return OP_SUB;}
"Mul" {return OP_MUL;}
"Div" {return OP_DIV;}
"Nop" {return OP_NOP;}
"Load" {return OP_LOAD;}
"Store" {return OP_STORE;}
"Return" {return OP_RETURN;}
"GetPtr" {return OP_GETPTR;}
"Cmp" {return OP_CMP;}
"Branch" {return OP_BRANCH;}
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return MULT; }
"/" { return DIV; }
"!" { return NOT; }
"||" { return L_OR; }
"&&" { return L_AND; }
"|" {return OR;}
"&" {return AND;}
"^" {return XOR;}
">=" { return GE; }
"<=" { return LE; }
"==" { return EQ; }
"!=" { return NEQ; }
"=" { return INIT_OP; }
">" { return GT; }
"<" { return LT; }
{string_const} {SAVE_TOKEN; return (STR_CONST);}
{identifier} {SAVE_TOKEN; return (IDENTIFIER);}
{numbers} {yylval.number = atoi(yytext); return (NUM);}
{comment} {/*do nothing*/}
%%
void showError(){
printf("Other input");
}