-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcminus.l
54 lines (40 loc) · 849 Bytes
/
cminus.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
40
41
42
43
44
45
46
47
48
49
50
%{
#include "y.tab.h"
extern YYSTYPE yylval;
%}
%option noyywrap
%%
[' '\t]+
"else" {return ELSE;}
"if" {return IF;}
"int" {return INT;}
"return" {return RETURN;}
"void" {return VOID;}
"while" {return WHILE;}
[a-zA-Z]+[0-9]* {strcpy(yylval.s,yytext);
return ID;
}
[0-9]+ {yylval.n=atoi(yytext);
return NUM;
}
"<=" {return LTE;}
">=" {return GTE;}
"==" {return EQUAL;}
"!=" {return NOTEQUAL;}
"\(" {return yytext[0];}
"\)" {return yytext[0];}
"\[" {return yytext[0];}
"\]" {return yytext[0];}
"\{" {return yytext[0];}
"\}" {return yytext[0];}
"\+" {return yytext[0];}
"\-" {return yytext[0];}
"\*" {return yytext[0];}
"\/" {return yytext[0];}
"<" {return yytext[0];}
">" {return yytext[0];}
";" {return yytext[0];}
"," {return yytext[0];}
"=" {return yytext[0];}
"\n" {yylineno++;}
%%