-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscanner.l
More file actions
71 lines (58 loc) · 2.6 KB
/
scanner.l
File metadata and controls
71 lines (58 loc) · 2.6 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%{
#include <bits/stdc++.h>
#include "ast.h"
#include "parser.tab.hpp"
#define YY_DECL extern "C" int yylex()
/*extern union Node yylval;*/
using namespace std;
int lineno = 0;
%}
%%
"//".* {return COMMENT;}
"class" {return CLASS;}
"Program" {return PROGRAM;}
"int" {yylval.value = strdup(yytext); return INT;}
"boolean" {yylval.value = strdup(yytext); return BOOLEAN;}
"void" {yylval.value = strdup(yytext);return VOID;}
"true" {yylval.boolliteral = new boolLit(yytext);return TRUE;}
"false" {yylval.boolliteral = new boolLit(yytext);return FALSE;}
"callout" {return CALLOUT;}
"return" {return RETURN;}
"break" {return BREAK;}
"continue" {return CONTINUE;}
"if" {return IF;}
"else" {return ELSE;}
"for" {return FOR;}
[a-zA-Z_][a-zA-Z0-9]* {yylval.value = strdup(yytext);return IDEN;}
0[xX][0-9a-fA-F]+ {yylval.intliteral = new integerLit(atoi(yytext)); return HEX_LIT;}
-?[0-9]+ {yylval.intliteral = new integerLit(atoi(yytext)); return INTEGER_LIT;}
"+=" {yylval.value = strdup(yytext);return PE;}
"-=" {yylval.value = strdup(yytext);return ME;}
"=" {yylval.value = strdup(yytext);return EQ;}
"+" {yylval.value = strdup(yytext);return ADD;}
"-" {yylval.value = strdup(yytext);return SUB;}
"*" {yylval.value = strdup(yytext);return MUL;}
"/" {yylval.value = strdup(yytext);return DIV;}
"%" {yylval.value = strdup(yytext);return MOD;}
"<" {yylval.value = strdup(yytext);return LTHAN;}
">" {yylval.value = strdup(yytext);return GT;}
"!" {yylval.value = strdup(yytext);return NOT;}
"{" {return L_FLO;}
"}" {return R_FLO;}
"[" {return L_SQ;}
"]" {return R_SQ;}
"(" {return L_P;}
")" {return R_P;}
"," {;return COMMA;}
";" {return SEMI;}
"!=" {yylval.value = strdup(yytext);return NE; }
"||" {yylval.value = strdup(yytext);return DO; }
">=" {yylval.value = strdup(yytext);return GE; }
"&&" {yylval.value = strdup(yytext);return DA; }
"<=" {yylval.value = strdup(yytext);return LEQ; }
"==" {yylval.value = strdup(yytext);return DE; }
\'.\' {yylval.charliteral = new charLit(yytext);return CHAR_LIT;}
[ \t\r]+ {}
[\n]+ {++lineno;}
\"[^\"]*+\" {yylval.stringliteral = new stringLit(yytext);return STRING_LIT;}
%%