-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathpseudo_code.l
46 lines (42 loc) · 1.29 KB
/
pseudo_code.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
%top{
#include "pseudo_code.h"
#include "pseudo_code.tab.h"
#include <stdlib.h>
#include <string.h>
}
%option noyywrap
%option case-insensitive
%option yylineno
%option nounput
%option noinput
%x STRING
%x COMMENT
%%
"IF" { return IF; }
"THEN" { return THEN; }
"ELSE" { return ELSE; }
"END IF" { return ENDIF; }
"FOR" { return FOR; }
"FROM" { return FROM; }
"TO" { return TO; }
"DO" { return DO; }
"END FOR" { return ENDFOR; }
"READ" { return READ; }
"PRINT" { return PRINT; }
"SWAP" { return SWAP; }
"LEN" { return LEN; }
"FUNC" { return FUNC; }
"END FUNC" { return ENDFUNC; }
"NOT" { return NOT; }
[0-9]+ { yylval.val = atoi(yytext); return INT; }
[A-Z][A-Z0-9]* { yylval.var = StrToVar(yytext); return VAR; }
[+\-*/(){};=,<>!\[\]] { return yytext[0]; }
\" { BEGIN(STRING); }
<STRING>[^\"]+ { yylval.s = strdup(yytext); return STR; }
<STRING>\" { BEGIN(INITIAL); }
"//" { BEGIN(COMMENT); }
<COMMENT>.+ { ; }
<COMMENT>(\r?\n) { BEGIN(INITIAL); return NEWLINE; }
(\r?\n)+ { return NEWLINE; }
. { ; }
%%