-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab9.l
75 lines (45 loc) · 1.64 KB
/
lab9.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
/*
NAME: Ruby Hollomon
LAB TITLE: Lab 9
DATE: April 18, 2023
PURPOSE: LEX code for Shaun Cooper's CS370 Compilers & Automata Theory. Tokenizes given CMINUS+
input for use by YACC.
*/
%{
int mydebug=0;
int lineno = 1;
#include "ast.h"
#include "symtable.h"
#include "emit.h"
#include "y.tab.h"
%}
%%
int { return(T_INT);}
void { return (T_VOID); }
if { return(T_IF);}
else { return(T_ELSE);}
while { return(T_WHILE);}
return { return(T_RETURN);}
read { return(T_READ);}
write { return(T_WRITE);}
\".*\" {yylval.string=strdup(yytext);
return(T_STRING);}
"<=" { return(T_LE);}
">=" { return(T_GE);}
"<" { return(T_LESS);}
">" { return(T_GREATER);}
"==" { return(T_EQUIV);}
"!=" { return(T_NOTEQUIV);}
[a-zA-Z]+[a-zA-Z0-9_]* { yylval.string=strdup(yytext);
return(T_ID);}
[0-9][0-9]* { yylval.value=atoi((const char *)yytext);
return(T_NUM);}
[ \t] {}
[;=\-+*/\%&|(),\[\]{}<>] { return (*yytext);}
\n {
lineno++;
}
\/\/.*\n { lineno++; }
%%
int yywrap(void)
{ return 1;}