-
Notifications
You must be signed in to change notification settings - Fork 6
/
RiddleLexer.g4
86 lines (82 loc) · 1.65 KB
/
RiddleLexer.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
83
84
85
86
lexer grammar RiddleLexer;
//关键字
Var:'var'; //可变变量
Val:'val'; //不可变变量
For:'for';
While:'while';
Continue:'continue';
Break:'break';
If:'if';
Else:'else';
Func:'fun'; //函数定义
Return: 'return' ;
Import: 'import' ;
Package: 'package';
Class: 'class';
Public: 'public';
Protected: 'protected';
Private: 'Private' ;
Override: 'override';
True:'true';
False:'false';
Static:'static';
Const:'const';
Null:'null';
Try:'try';
Catch:'catch';
//可见字符
//基本运算符
LeftBracket: '(';
RightBracket: ')';
LeftSquare: '[';
RightSquare: ']';
LeftCurly: '{';
RightCurly: '}';
Colon: ':';
Semi: ';';
Comma: ',';
Equal: '==';
Assign: '=';
Greater: '>';
Less: '<';
LeftLeft: '<<';
RightRight: '>>';
RightRightRight:'>>>';
Add: '+';
Sub: '-';
Star: '*';
Div: '/';
Mod: '%';
Not: '!';
And: '&';
Or: '|';
Xor: '^';
Dot: '.';
DoubleQuotes: '"';
Quotes: '\'';
Endl:'\n';
//标识符
Identifier: [A-Za-z_] [A-Za-z_0-9]*;
//十六进制
Hexadecimal: '0x' [1-9A-F] HEX_DIGIT*;
//十进制
Decimal: '0' | [1-9] DIGIT*;
//八进制
Octal: '0' [1-7] OCTAL_DIGIT*;
//二进制
Binary: '0b' '1' BINARY_DIGIT*;
Float: Decimal Dot IntegerSequence;
IntegerSequence: DIGIT+;
HEX_DIGIT: [0-9A-F];
OCTAL_DIGIT: [0-7];
BINARY_DIGIT: [0-1];
DIGIT: [0-9];
STRING
: '"' (ESC | ~["\\\r\n])* '"'
;
fragment ESC
: '\\' (["\\/] | [A-Za-z])
;
LINE_COMMENT : '//' ~[\r\n]* -> skip ;
BLOCK_COMMENT : '/*' .*? '*/' -> skip ;
WHITESPACE : [ \t\r\n]+ -> skip ;