This repository was archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminijava.jflex
More file actions
60 lines (58 loc) · 2 KB
/
minijava.jflex
File metadata and controls
60 lines (58 loc) · 2 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
package syntax;
%%
%include Jflex.include
%include JflexCup.include
// Macros
WS = [ \t\f] | \R
EOLComment = "//" .*
C89Comment = "/*" [^*]* ("*" ([^*/] [^*]*)?)* "*/"
Ignore = {WS}+ | {EOLComment} | {C89Comment}
Integer = 0 | [1-9] [0-9]*
Identifier = [:jletter:] [:jletterdigit:]*
Println = "System" {WS}* "." {WS}* "out" {WS}* "." {WS}* "println"
Boolean = "true" | "false"
%%
// Mots Clés
"class" { return TOKEN(CLASS); }
"main" { return TOKEN(MAIN); }
{Println} { return TOKEN(PRINTLN); }
"public" { return TOKEN(PUBLIC); }
"static" { return TOKEN(STATIC); }
"String" { return TOKEN(STRING); }
"void" { return TOKEN(VOID); }
"return" { return TOKEN(RETURN); }
"if" { return TOKEN(IF); }
"else" { return TOKEN(ELSE); }
"while" { return TOKEN(WHILE); }
"new" { return TOKEN(NEW); }
"this" { return TOKEN(THIS); }
"extends" { return TOKEN(EXTENDS); }
"boolean" { return TOKEN(BOOLEAN); }
"int" { return TOKEN(INT); }
"length" { return TOKEN(LENGTH); }
// Operateurs
"&&" { return TOKEN(AND); }
"<" { return TOKEN(LESS); }
"+" { return TOKEN(PLUS); }
"-" { return TOKEN(MINUS); }
"*" { return TOKEN(TIMES); }
"!" { return TOKEN(NOT); }
"=" { return TOKEN(EQ); }
// Ponctuations
";" { return TOKEN(SEP); }
"{" { return TOKEN(LC); }
"}" { return TOKEN(RC); }
"(" { return TOKEN(LP); }
")" { return TOKEN(RP); }
"[" { return TOKEN(LB); }
"]" { return TOKEN(RB); }
"," { return TOKEN(COMMA); }
"." { return TOKEN(POINT); }
// literals
{Integer} { return TOKEN(LIT_INT, Integer.parseInt(yytext())); }
{Boolean} { return TOKEN(LIT_BOOL, new String(yytext())); }
{Identifier} { return TOKEN(IDENT, new String(yytext())) ; }
// Ignore
{Ignore} {}
// Ramasse Miette
[^] { WARN("Unknown char '"+yytext()+"' "); return TOKEN(error); }