-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.l
More file actions
47 lines (43 loc) · 1.75 KB
/
parse.l
File metadata and controls
47 lines (43 loc) · 1.75 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
%{
#include "parse.tab.h"
#include <stdio.h>
#include <string.h>
%}
%option noyywrap
%%
"PROGRAM" { return(PROGRAM); }
"VAR" { return(VAR); }
"BEGIN" { return(START); }
"END" { return(END); }
"INTEGER" { return(INTEGER); }
"PRINT" { return(PRINT); }
\. { return(PERIOD); }
\: { return(COLON); }
\; { return(SEMICOLON); }
\, { return(COMMA); }
\( { return(LPAREN); }
\) { return(RPAREN); }
\+ { return(ADD); }
\- { return(SUBT); }
\* { return(MULT); }
\/ { return(DIV); }
\= { return(EQ); }
\' { return(QUOTE); }
'.*' {
char text[strlen(yytext)];
for(int ind = 0; ind <= strlen(yytext); ++ind) {
if(yytext[ind] == '\'') {
text[ind] = '\"';
}
else {
text[ind] = yytext[ind];
}
}
yylval.s = strdup(text);
return(STRING);
}
[0-9]+ { yylval.s = strdup(yytext);
return(NUM); }
[a-zA-Z_][a-zA-Z0-9_]* { yylval.s = strdup(yytext);
return(IDENTIFIER); }
%%