-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRipacola.xtext
195 lines (135 loc) · 4.87 KB
/
Ripacola.xtext
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
grammar org.ripacola.lang.Ripacola hidden(WS, SL_COMMENT, INCLUDE)
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate ripacola "http://www.ripacola.org/lang/Ripacola"
Program:
declarations+=Declaration*;
Declaration: TypeDeclaration ';'
| ParameterDeclaration ';'
| ActorDeclaration ';'
| NetDeclaration ';'
;
/* ****************************************************************
** TYPE Decls
**************************************************************** */
TypeDeclaration: 'type' name=ID
| 'type' name=ID '=' target=Type
;
ParameterDeclaration: 'parameter' name=ID ':' type=SimpleType '=' value=Expression;
/* ****************************************************************
** ACTOR Decls
**************************************************************** */
ActorDeclaration: 'actor' name=ID '(' (ios+=ActorIO (',' ios+=ActorIO)*)? ')';
ActorIO: ('in'|'out') 'param' name=ID ':' type=Type
| ('in'|'out') 'data' name=ID '[' expr=Expression ']' ':' type=Type
| 'state' name=ID ':' type=Type
;
NetDeclaration: 'net' bindings+=NetBinding ('and' bindings+=NetBinding)*
// TODO: net rec
;
NetBinding: name=NetPattern '=' expr=NetExpression
// TODO | ID patterns+=NetPattern ('=' NetPattern)* '=' NetExpression
;
NetPattern: {NetPattern} ID
| '(' patterns+=NetPattern (',' patterns+=NetPattern)* ')'
| {NetPattern} '(' ')'
;
NetExpression: (exprs+=SimpleNetExpression)+
| 'function' pattern=NetPattern '->' expr=NetExpression
| 'let' binding=NetBinding 'in' expr=NetExpression
// TODO: let rec
;
SimpleNetExpression: {SimpleNetExpression} ID
| {SimpleNetExpression} '(' ')'
| '(' exprs+=NetExpression (',' exprs+=NetExpression)* ')'
;
/* ****************************************************************
** Expressions
**************************************************************** */
Expression: Addition | '-' Expression;
Addition returns Expression:
Multiplication ({Addition.left=current} op=('+' | '-') right=Multiplication)*;
Multiplication returns Expression:
Primary ({Multiplication.left=current} op=('*' | '/' | 'mod') right=Primary)*;
Primary returns Expression: {Expression} ScalarConstant
| '(' Expression ')'
| var=ID ('[' indexes+=ArrayIndex ']')*
;
ArrayInit:
ArrayExt1 | ArrayExt2 | ArrayExt3 | '[' ArrayComprehension ']'
;
ArrayExt1:
'[' indexes+=Expression (',' indexes+=Expression)* ']'
;
ArrayExt2:
'[' indexes+=ArrayExt1 (',' indexes+=ArrayExt1)* ']'
;
ArrayExt3:
'[' indexes+=ArrayExt2 (',' indexes+=ArrayExt2)* ']'
;
ArrayComprehension:
'[' Expression | '|' ranges+=IndexRange (',' ranges+=IndexRange)* ']'
;
IndexRange: ID '=' from=ArrayIndex 'to' to=ArrayIndex;
ArrayIndex: Expression;
/* ****************************************************************
** CONSTANTS
**************************************************************** */
ScalarConstant:
INTCONST | BOOLEANCONST | FLOATCONST
;
Array1Constant:
'[' ScalarConstant (',' ScalarConstant)* ']'
;
Array2Constant:
'[' Array1Constant (',' Array1Constant)* ']'
;
/* ****************************************************************
** Type Expressions
**************************************************************** */
Type: TypeProduct | TypeProduct '->' target=Type;
TypeProduct: named+=NamedType ('*' named+=NamedType)*;
NamedType: ArrayType (ID ('[' Size ']')?)?;
ArrayType: SimpleType ('array' '[' Size ']' ('[' Size ']')? )?;
//SimpleType:
// ('signed'|'unsigned') '<' size=Size '>'
// |{SimpleType} 'int' ('<' ( sign=('_signed' | '_unsigned') ',')? size=Size '>')?
// | ref=[TypeDeclaration]
//;
SimpleType: WireType | IntType
| base=[TypeDeclaration]
;
WireType: ('signed'|'unsigned') '<' size=Size '>';
IntType: {IntType} 'int' ('<' ( sign=('_signed' | '_unsigned') ',')? size=Size '>')?;
Size: INTCONST | SIZEVAR;
ArraySize: INTCONST;
VarType: Type
| {VarType} '{' Ctors '}'
| {VarType} '{' IntRange '}'
;
Ctors:
ID (',' Ctors)?
;
IntRange: INTCONST ',..,' INTCONST;
/* ****************************************************************
** TERMINALS
**************************************************************** */
/* terminal */ VAR: ID;
/* terminal */ ATTR: ID;
terminal INTCONST returns ecore::EInt: DIGIT+;
terminal FIXINTCONST: (RADIX)? DIGIT+;
terminal FLOATCONST returns ecore::EFloat: DIGIT+ ('.' DIGIT*)? (("e"|"E")("+"|"-")DIGIT+)?;
terminal BOOLEANCONST returns ecore::EBoolean: ('true'|'false');
terminal RADIX: 'Ox' | 'Ob';
terminal ID: (LETTER|ULETTER ) (ULETTER | LETTER | DIGIT | '_' | "'" )*;
terminal LETTER: ('a'..'z');
/* terminal */ SIZEVAR: ID;
terminal ULETTER: ('A'..'Z');
terminal DIGIT: ('0'..'9');
terminal STRING:
'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"'
;
//terminal ML_COMMENT : '/*' -> '*/';
terminal SL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')? ;
terminal INCLUDE: '#include' !('\n'|'\r')* ('\r'? '\n')? ;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ANY_OTHER: .;