source: java/Framclipse/com.framsticks.framclipse/src/com/framsticks/framclipse/FramScript.xtext @ 437

Last change on this file since 437 was 437, checked in by Mateusz Poszwa, 9 years ago

Added Framclipse as developed by Bartosz Kukawka and Tomek Maciejewski in 2010

  • Property svn:eol-style set to native
File size: 6.2 KB
Line 
1grammar com.framsticks.framclipse.FramScript with org.eclipse.xtext.common.Terminals
2
3import "http://www.eclipse.org/emf/2002/Ecore" as ecore
4
5generate framScript "http://www.framsticks.com/framclipse/FramScript"
6
7Model :
8        (Neuro|Expdef|Style|Show|Script|Include) ;
9       
10FramclipseClass :
11        (Neuro|Expdef|Style|Show|Script|Property|State) ;
12       
13Neuro :
14        'class:'
15//      'name:' name=ID
16        headers+=NeuroHeader+
17        code=CodeSection
18        (propertyImports+=PropertyIncludeDeclaration |
19        properties+=Property)*
20        ;
21
22Expdef :
23        'expdef:'
24        headers+=Header+
25        code=CodeSection
26        (propertyImports+=PropertyIncludeDeclaration |
27        properties+=Property |
28        states+=State)*
29        ;
30       
31Style :
32        'style:'
33        headers+=Header+
34        code=CodeSection
35        (propertyImports+=PropertyIncludeDeclaration |
36        properties+=Property)*
37        ;
38       
39Show :
40        'show:'
41        headers+=ShowHeader+
42        code=CodeSection
43        (propertyImports+=PropertyIncludeDeclaration |
44        properties+=Property)*
45        ;
46       
47Script :
48        'script:'
49        headers+=Header+
50        code=CodeSection
51        ;
52       
53Property :
54        'prop:'
55        headers += PropertyHeader*
56        'id:' name=ID
57        headers += PropertyHeader+
58        ;
59       
60State :
61        'state:'
62        headers += PropertyHeader*
63        'id:' name=ID
64        headers += PropertyHeader+
65        ;
66       
67Include : {Include}
68        code=Code?
69        (properties+=Property |
70        states+=State)*
71;
72       
73Header :
74        name=ID value=HEADER_VALUE ;
75       
76NeuroHeader returns Header :
77{IntHeader}             name=('prefinputs:' | 'prefoutput:' | 'preflocation:' | 'vhints:') intValue=IntValue |
78{IconHeader}    name='icon:' icon=Icon |
79{IconHeader}    name='icon:~' icon=Icon '~' |
80                                Header ;
81                               
82Icon :
83        INT (',' INT)+ ;
84       
85PropertyHeader returns Header :
86        TypeHeader |
87        FlagsHeader |
88        Header ;
89       
90ShowHeader returns Header :
91        name='expdef:' value=ID |
92        Header ;
93       
94FlagsHeader returns Header :
95{IntHeader}     name='flags:' intValue=INT ;
96       
97TypeHeader :
98        name='type:' type=PropertyType ;
99       
100PropertyType :
101        name=ID (min=Number (max=Number default=Number?)? enums+=ENUM_LITERAL* )? ;
102       
103terminal ENUM_LITERAL :
104        '~' !('~'|'\r'|'\n')+ ;
105
106Number :
107        '-'? (INT | DOUBLE) ;
108       
109CodeSection returns Code :
110        'code:~' Code '~' ;
111
112Code :
113        (includes += IncludeDeclaration |
114        globals += Global |
115        functions += Function)+;
116       
117Global returns VariableDeclarations :
118        'global' vars+=VariableDeclaration (',' vars+=VariableDeclaration)* ';' ;
119       
120Function :
121        'function' name=ID (',' aliases+=ID)* '(' (params+=VariableDeclaration (',' params+=VariableDeclaration)*)? ')' code=Block ;
122       
123IncludeDeclaration :
124        '@include' importURI=STRING ;
125       
126PropertyIncludeDeclaration :
127        '#include' importURI=STRING ;
128       
129Block :
130{Block} '{' statements+=Statement* '}' ;
131       
132Statement :     
133        ( VariableDeclarationStatement |
134        ExpressionStatement |
135        DoStatement |
136        ContinueStatement |
137        BreakStatement |
138        ReturnStatement |
139        GotoStatment ) ';' |
140        IncludeDeclaration |
141        Block |
142        SwitchStatement |
143        LabeledStatement |
144        IfStatement |
145        WhileStatement |
146        ForStatement |
147{EmptyStatement} ';' ;
148
149VariableDeclarationStatement returns VariableDeclarations :
150        'var' vars+=VariableDeclaration (',' vars+=VariableDeclaration)* ;
151
152VariableDeclaration :
153        name=ID ('=' value=Expression)?;
154       
155IfStatement :
156        'if' '(' condition=Expression ')' if=Statement ('else' else=Statement)? ;
157       
158ForStatement :
159        'for' '(' init=Assignment? ';' condition=Expression? ';' step=Assignment? ')' body=Statement ;
160       
161WhileStatement :
162        'while' '(' condition=Expression ')' body=Statement ;
163       
164DoStatement :
165        'do' body=Statement 'while' condition=ParExpression ;
166       
167LabeledStatement :
168        name=ID ':' body=Statement ;
169       
170GotoStatment :
171        'goto' dest=[LabeledStatement] ;
172       
173ReturnStatement :
174{ReturnStatement} 'return' (expr=Expression)? ;
175       
176ContinueStatement :
177{ContinueStatement}     'continue' (dest=[LabeledStatement])? ;
178       
179BreakStatement :
180{BreakStatement} 'break' (dest=[LabeledStatement])? ;
181       
182SwitchStatement :
183        'switch' condition=ParExpression '{' labels+=SwitchGroup* '}' ;
184       
185SwitchGroup :
186        label=SwitchLabel body=SwitchBlock ;
187       
188SwitchBlock returns Block :
189{Block} statements+=Statement* ;
190
191SwitchLabel:
192        'case' expr = Expression ':' |
193{DefaultSwitchLabel} 'default' ':' ;
194       
195ExpressionStatement :
196        Assignment ;
197       
198AssignmentOperator :
199        '=' | '+=' | '-=' | '*=' | '/=' ;
200       
201ParExpression returns Expression:
202        '(' Expression ')' ;
203       
204Assignment :
205        Expression ( {Assignment.left=current} op=AssignmentOperator right=Assignment)? ;
206
207Expression :
208        UnaryExpression ({Expression.left=current} op=Operator right=Expression)? |
209        WildcardExpression ;
210       
211UnaryExpression  :
212        QualifiedExpression2 ({UnaryExpression.arg=current} op = IncrementOperator)? |
213        op = (IncrementOperator | UnaryOperator) arg = QualifiedExpression2 |
214        Literal ;
215       
216QualifiedExpression2 returns QualifiedExpression :
217        QualifiedExpression |
218        (PropertyAccess|StateAccess) ({QualifiedExpression.parent=current}'.' child=QualifiedExpression )? ;
219       
220QualifiedExpression :
221        ArrayElementExpression ({QualifiedExpression.parent=current}'.' child=QualifiedExpression )? ;
222       
223ArrayElementExpression :
224        TerminalExpression ({ArrayElementExpression.array=current} ('[' indexes+=Expression ']')+ )? ;
225 
226TerminalExpression:
227                                Invocation |
228                                Array |
229                                Vector |
230{VariableRef}   var=[VariableDeclaration];
231                               
232Invocation :
233        function=[Function] '(' (args+=Expression (',' args+=Expression)*)? ')' ;
234       
235WildcardExpression :
236        value=ID '.*' ;
237       
238PropertyAccess returns QualifiedExpression :
239        ('Fields.'|'ExpParams.'|'ShowParams.'|'VisParams.') property=[Property] ;
240       
241StateAccess returns QualifiedExpression :
242        'ExpState.' state=[State] ;
243       
244Literal:
245{IntLiteral}    value=IntValue |
246{DoubleLiteral} value=DoubleValue |
247{StringLiteral} value=STRING |
248{HexLiteral}    value=HEX |
249{NullLiteral}   'null' ;
250
251Array :
252        '[' elements+=Expression (',' elements+=Expression)* ']' ;
253
254Vector  :
255        '(' elements+=Expression (',' elements+=Expression)* ')' ;
256
257Operator :
258        '+' | '-' | '*'| '/' |
259        '&'| '|' | '%' |
260        '==' | '!=' | '>=' | '<=' | '<' | '>' |
261        '&&' | '||' ;
262       
263UnaryOperator :
264        '!' | '+' | '-' | 'typeof';
265       
266IncrementOperator :
267        '++' | '--' ;
268       
269IntValue returns ecore::EInt hidden() :
270        ('+'|'-')? INT ;
271       
272DoubleValue hidden() :
273        ('+'|'-')? DOUBLE ;
274       
275terminal DOUBLE :
276        ('0'..'9')*'.'('0'..'9')+ ('e' INT)? |
277        INT 'e' INT ;
278       
279terminal HEX :
280        '0x' (('0'..'9')|('a'..'f')|('A'..'F'))+ ;
281       
282terminal HEADER_VALUE :
283        ':' !('~'|' '|'\t'|'\r'|'\n') !('\n'|'\r')* ('\r'? '\n') |
284        ':~' -> '~'('\r'? '\n')
285        ;
286       
287terminal SL_COMMENT : ('//' | '# ')  !('\n'|'\r')* ('\r'? '\n')?;
288
Note: See TracBrowser for help on using the repository browser.