-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlyScriptLexer.g4
82 lines (67 loc) · 1.23 KB
/
FlyScriptLexer.g4
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
lexer grammar FlyScriptLexer;
@members {
int nesting = 0;
}
Type_void: 'void';
Type_string: 'string';
Type_float: 'float';
Type_int: 'int';
Type_boolean: 'boolean';
//KeyWorld: 'if' | 'then' | 'else' | 'return' ;
K_If: 'if';
K_Then: 'then';
K_Else: 'else';
K_While: 'while';
K_Break: 'break';
K_Return: 'return';
Kv_True: 'true';
Kv_False: 'false';
LCurlyPar: '{';
RCurlyPar: '}';
LSquarePar: '[';
RSquarePar: ']';
PLUS : '+';
SUBTRACT : '-';
MULTIPLY : '*';
DIVIDE : '/';
NOT : '!';
AssignEqual: '=';
JudgeEqual: '==';
NotEqual: '!=';
GreaterOrEqual: '>=';
Greater: '>';
LesserOrEqual: '<=';
Lesser: '<';
OrBoolean: '||';
AndBoolean: '&&';
Or: '|';
And: '&';
Comma: ',';
Semicolon: ';';
ID : LETTER (LETTER | [0-9])* ;
fragment
LETTER : [a-zA-Z] ;
INT : [0-9]+ ;
WS : [ \t\n\r]+ -> skip ;
SL_COMMENT
: (('//' .*? '\n') | ('/**' .*? '**/')) -> skip
;
DQUOTE: '"' -> pushMode(IN_STRING);
LPAR: '(' {
nesting++;
pushMode(DEFAULT_MODE);
};
RPAR: ')' {
if (nesting > 0) {
nesting--;
popMode();
}
};
mode IN_STRING;
TEXT: ~[\\"]+ ;
BACKSLASH_PAREN: '\\(' {
nesting++;
pushMode(DEFAULT_MODE);
};
ESCAPE_SEQUENCE: '\\' . ;
DQUOTE_IN_STRING: '"' -> type(DQUOTE), popMode;