-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlexer.l
executable file
·40 lines (37 loc) · 950 Bytes
/
lexer.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
%{
#include "parser.tab.h"
%}
%option warn noyywrap noinput nounput yylineno
%%
"else" {return ELSE;}
"if" {return IF;}
"int" {return INT;}
"return" {return RETURN;}
"void" {return VOID;}
"while" {return WHILE;}
"+" {return ADD;}
"-" {return SUB;}
"*" {return MUL;}
"/" {return DIV;}
"<" {return LT;}
"<=" {return LTE;}
">" {return GT;}
">=" {return GTE;}
"==" {return EQ;}
"!=" {return NEQ;}
"=" {return ASSIGN;}
";" {return SEMI;}
"," {return COMMA;}
"(" {return ROUND_OPEN;}
")" {return ROUND_CLOSE;}
"[" {return SQUARE_OPEN;}
"]" {return SQUARE_CLOSE;}
"{" {return CURLY_OPEN;}
"}" {return CURLY_CLOSE;}
[a-zA-Z]+ {yylval.string = strdup(yytext); return ID;}
[0-9]+ {yylval.integer = atoi(yytext); return NUM;}
"\n" {++yylineno;}
[ \t\b]+ /* discard whitespace */
"//".* /* discard comments */
. { fprintf(stderr, "unknown character: %c", yytext[0]); }
%%