File tree Expand file tree Collapse file tree 4 files changed +295
-27
lines changed Expand file tree Collapse file tree 4 files changed +295
-27
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ grammar Toy;
5
5
}
6
6
7
7
module
8
- : funDefine+
8
+ : structDefine* funDefine+
9
9
;
10
10
11
11
expression
@@ -17,6 +17,8 @@ expression
17
17
| identifierExpr
18
18
| expression Mul expression
19
19
| expression Add expression
20
+ | expression Dot expression
21
+ | structLiteral
20
22
;
21
23
22
24
identifierExpr
@@ -57,6 +59,14 @@ varDecl returns [std::string idName]
57
59
if ($Equal)
58
60
tensorDataBuffer.clear();
59
61
}
62
+ | Identifier Identifier (Equal expression)?
63
+ {
64
+ $idName = $Identifier.text;
65
+ }
66
+ | Identifier
67
+ {
68
+ $idName = $Identifier.text;
69
+ }
60
70
;
61
71
62
72
type
@@ -75,8 +85,8 @@ prototype returns [std::string idName]
75
85
;
76
86
77
87
declList
78
- : Identifier
79
- | Identifier Comma declList
88
+ : varDecl
89
+ | varDecl Comma declList
80
90
;
81
91
82
92
block
@@ -87,6 +97,23 @@ blockExpr
87
97
: varDecl | returnExpr | expression
88
98
;
89
99
100
+ literalList
101
+ : tensorLiteral
102
+ {
103
+ tensorDataBuffer.clear();
104
+ }
105
+ | tensorLiteral Comma literalList
106
+ ;
107
+
108
+ structLiteral
109
+ :
110
+ | BracketOpen (structLiteral | literalList) (Comma (structLiteral| literalList))* BracketClose
111
+ ;
112
+
113
+ structDefine
114
+ : Struct Identifier BracketOpen (varDecl Semicolon)* BracketClose
115
+ ;
116
+
90
117
ParentheseOpen
91
118
: ' ('
92
119
;
127
154
: ' def'
128
155
;
129
156
157
+ Struct
158
+ : ' struct'
159
+ ;
160
+
130
161
Identifier
131
162
: [a-zA-Z ][a-zA-Z0 -9_]*
132
163
;
159
190
: ' *'
160
191
;
161
192
193
+ Dot
194
+ : ' .'
195
+ ;
196
+
162
197
WS
163
198
: [ \r\n\t] -> skip
164
199
;
You can’t perform that action at this time.
0 commit comments