-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.lex
More file actions
89 lines (69 loc) · 1.5 KB
/
Copy pathscanner.lex
File metadata and controls
89 lines (69 loc) · 1.5 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* definitions*/
%{
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
#include "external_file.hpp"
#include "parser.tab.hpp"
#include "output.hpp"
%}
%option yylineno
%option noyywrap
id ([a-zA-Z][a-zA-Z0-9]*)
num (0|[1-9][0-9]*)
string \"([^\n\r\"\\]|\\[rnt"\\])+\"
comm (\/\/[^\r\n]*[\r|\n|\r\n]?)
ignore (\x20|\r|\n|\t)
%%
{ignore} ;
void return VOID;
int return INT;
byte return BYTE;
bool return BOOL;
and return AND;
or return OR;
not return NOT;
true return TRUE;
false return FALSE;
return return RETURN;
if return IF;
else return ELSE;
while return WHILE;
break return BREAK;
b return B;
default return DEFAULT;
{id} {Ter* temp = new Ter(string(yytext),"ID");
yylval = static_cast<Node*>(temp);
return ID;};
{num} {yylval =
new Ter(string(yytext),
"NUM");
return NUM;};
{string} {yylval = new Ter(string(yytext),
"STRING");
return STRING;};
{comm} ;
\: return COLON;
\; return SC;
, return COMMA;
\( return LPAREN;
\) return RPAREN;
\[ return LBRACK;
\] return RBRACK;
\{ return LBRACE;
\} return RBRACE;
== return RELOPEQ;
!= return RELOPNEQ;
\<= return RELOPSEQ;
>= return RELOPLEQ;
\< return RELOPSML;
> return RELOPLRG;
= return ASSIGN;
\+ return BINOPADD;
- return BINOPSUB;
\* return BINOPMUL;
\/ return BINOPDIV;
. {output::errorLex(yylineno); st.set_prints(false); exit(0);}
%%