-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEX_PART.l
76 lines (57 loc) · 1.79 KB
/
LEX_PART.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
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
%{
#include<stdio.h>
#include"y.tab.h"
char *new_cstr(char*);
char *varname, *numStr, *string_const;
%}
%%
"int" {ECHO; return INT;}
"char" {ECHO; return CHAR;}
"struct" {ECHO; return STRUCT;}
"union" {ECHO; return UNION;}
"for" {ECHO; return FOR;}
"while" {ECHO; return WHILE;}
"if" {ECHO; return IF;}
"else" {ECHO; return ELSE;}
"switch" {ECHO; return SWITCH;}
"case" {ECHO; return CASE;}
"break" {ECHO; return BREAK;}
"continue" {ECHO; return CONTINUE;}
"return" {ECHO; return RETURN;}
[0-9]+ {ECHO; return NUMBER;}
[a-zA-Z]+[a-zA-Z0-9]* {ECHO; varname=new_cstr(yytext); return IDENTIFIER;}
"++" {ECHO; return INCOP;}
"--" {ECHO; return DECOP;}
"+" {ECHO; return PLUS;}
"-" {ECHO; return MINUS;}
"*" {ECHO; return MUL;}
"/" {ECHO; return DIV;}
"<=" {ECHO; return LE;}
">=" {ECHO; return GE;}
"<" {ECHO; return LT;}
">" {ECHO; return GT;}
"==" {ECHO; return EE;}
"!=" {ECHO; return NE;}
"&&" {ECHO; return AND;}
"||" {ECHO; return OR;}
"!" {ECHO; return NOT;}
"&" {ECHO; return AMP;}
"=" {ECHO; return EQ;}
"(" {ECHO; return OP;}
")" {ECHO; return CP;}
"{" {ECHO; return OB;}
"}" {ECHO; return CB;}
"[" {ECHO; return OSB;}
"]" {ECHO; return CSB;}
"," {ECHO; return COMMA;}
";" {ECHO; return SEMICOLON;}
":" {ECHO; return COLON;}
"/*".*"*/"[ \t\n]* {ECHO; ;}
\".*\" {ECHO; string_const = new_cstr(yytext); return S_LIT;}
[ \t\n]+ {ECHO;}
. {ECHO;}
%%
int yywrap()
{
return 1;
}