-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGravis.g4
115 lines (97 loc) · 1.44 KB
/
Gravis.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
grammar Gravis;
/*
* parser rules
*/
file_input: stmt* EOF;
stmt: def_stmt | link_stmt;
link_stmt: dotted_name '>>' dotted_name;
def_stmt: NAME '=' node_def;
node_def
: input_def
| output_def
| const_def
| if_def
| opr_def
| subspace_def
| self_subspace_def
;
input_def: 'input';
output_def: 'output';
const_def: 'const' '[' NUMBER ']';
if_def: 'if' '[' comp_op ']';
opr_def: 'opr' '[' arith_op ']';
subspace_def: 'subspace' '[' stmt+ ']';
self_subspace_def: 'subspace' '[' 'self' ']';
dotted_name: node_inst ('.' NAME)?;
node_inst: NAME | node_def;
comp_op: '<'|'>'|'=='|'>='|'<='|'!=';
arith_op: '+'|'-'|'*'|'/'|'%';
/*
* lexer rules
*/
NUMBER
: INTEGER
| FLOAT
;
INTEGER
: NON_ZERO_DIGIT DIGIT*
| '0'+
;
fragment NON_ZERO_DIGIT
: [1-9]
;
fragment DIGIT
: [0-9]
;
FLOAT
: INT_PART FRACTION
;
fragment INT_PART
: DIGIT+
;
fragment FRACTION
: '.' DIGIT+
;
DOT : '.';
OPEN_PAREN : '[';
CLOSE_PAREN : ']';
ASSIGN : '=';
RIGHT_SHIFT : '>>';
ADD : '+';
MINUS : '-';
MUL : '*';
DIV : '/';
MOD : '%';
LESS_THAN : '<';
GREATER_THAN : '>';
EQUALS : '==';
GT_EQ : '>=';
LT_EQ : '<=';
NOT_EQ : '!=';
INPUT : 'input';
OUTPUT : 'output';
IF : 'if';
OPR : 'opr';
SUBSPACE : 'subspace';
SELF : 'self';
WHITESPACE
: ( SPACES | COMMENT ) -> skip
;
fragment SPACES
: [ \t\n\r]+
;
fragment COMMENT
: '#' ~[\r\n\f]*
;
NAME
: ID_START ID_CONTINUE*
;
fragment ID_START
: '_'
| [A-Z]
| [a-z]
;
fragment ID_CONTINUE
: ID_START
| [0-9]
;