-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.l
More file actions
50 lines (45 loc) · 1.62 KB
/
lexer.l
File metadata and controls
50 lines (45 loc) · 1.62 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
48
49
50
%{
#include "parser.h"
%}
%%
[ \t\n]+ ; // Ignore whitespace
"void" return VOID;
"int" return INT;
"return" return RETURN;
"if" return IF;
"else" return ELSE;
"while" return WHILE;
"continue" return CONTINUE;
"break" return BREAK;
"==" return EQ;
"!=" return NE;
"<=" return LE;
">=" return GE;
"<" return LT;
">" return GT;
"&&" return AND;
"||" return OR;
"&" return BIT_AND;
"|" return BIT_OR;
"^" return BIT_XOR;
"!" return NOT;
"~" return BIT_NOT;
"+" return PLUS;
"-" return MINUS;
"*" return MUL;
"/" return DIV;
"%" return MOD;
[0-9]+ yylval.ival = atoi(yytext); return NUMBER;
[a-zA-Z_][a-zA-Z0-9_]* yylval.identifier = strdup(yytext); return IDENTIFIER;
";" return SEMICOLON;
"," return COMMA;
"(" return LPAREN;
")" return RPAREN;
"{" return LBRACE;
"}" return RBRACE;
"=" return ASSIGN;
. return yytext[0]; // Return single character tokens as is
%%
int yywrap(void) {
return 1;
}