-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.jflex
89 lines (75 loc) · 2.59 KB
/
scan.jflex
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
%%
%class Scanner
%unicode
%line
%column
%byaccj
%{
/* store a reference to the parser object */
private Parser yyparser;
/* constructor taking an additional parser */
public Scanner (java.io.Reader r, Parser yyparser) {
this (r);
this.yyparser = yyparser;
}
/* return the current line number.*/
public int getLine() {
return yyline;
}
/* return the current column number.*/
public int getColumn() {
return yycolumn;
}
%}
%%
("/*" (.*[\r\n])|.* "*/") { /* allow multi line comments */ }
("//" .*) { /* single line comment */ }
PROGRAM { yyparser.yylval = new Node(yytext());
return Parser.PROGRAM;}
BEGIN { yyparser.yylval = new Node(yytext());
return Parser.BEGIN; }
END { yyparser.yylval = new Node(yytext());
return Parser.END; }
INT { yyparser.yylval = new Node(yytext());
return Parser.INT; }
FLOAT { yyparser.yylval = new Node(yytext());
return Parser.FLOAT; }
STRING { yyparser.yylval = new Node(yytext());
return Parser.STRING; }
PRINT { yyparser.yylval = new Node(yytext());
return Parser.PRINT; }
"(" { yyparser.yylval = new Node(yytext());
return Parser.OPEN_PAREN; }
")" { yyparser.yylval = new Node(yytext());
return Parser.CLOSE_PAREN; }
"==" { yyparser.yylval = new Node(yytext());
return Parser.REL_OP; }
"!=" { yyparser.yylval = new Node(yytext());
return Parser.REL_OP; }
"<=" { yyparser.yylval = new Node(yytext());
return Parser.REL_OP; }
">=" { yyparser.yylval = new Node(yytext());
return Parser.REL_OP; }
"<" { yyparser.yylval = new Node(yytext());
return Parser.REL_OP; }
">" { yyparser.yylval = new Node(yytext());
return Parser.REL_OP; }
[a-zA-Z][a-zA-Z0-9]* { yyparser.yylval = new Node(yytext());
return Parser.ID; }
[0-9]+ { yyparser.yylval = new Node(yytext(), "INT");
return Parser.NUM; }
[0-9]+\.[0-9]+ { yyparser.yylval = new Node(yytext(), "FLOAT");
return Parser.NUM; }
\"[a-zA-Z0-9]*\" { yyparser.yylval = new Node(yytext(), "STRING");
return Parser.TEXT; }
\= { yyparser.yylval = new Node(yytext());
return Parser.ASSIGN; }
\+ { yyparser.yylval = new Node(yytext());
return Parser.PLUS; }
\- { yyparser.yylval = new Node(yytext());
return Parser.MINUS; }
\; { yyparser.yylval = new Node(yytext());
return (int) yycharat(0); }
\. { yyparser.yylval = new Node(yytext());
return (int) yycharat(0); }
[ \t\n\r] { }