make sure the new instruction Data pointer is set to NULL
[mesa.git] / src / mesa / shader / slang_shader.syn
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.2
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * \file slang_shader.syn
27 * slang shader syntax
28 * \author Michal Krol
29 */
30
31 /*
32 * usage:
33 * syn2c slang_shader.syn > slang_shader_syn.h
34 *
35 * when modifying or extending this file, several things must be taken into consideration:
36 * - when adding new operators that were marked as reserved in the initial specification,
37 * one must only uncomment particular lines of code that refer to operators being added;
38 * - when adding new shader target, one must reserve new value for shader_type register and
39 * use it in .if constructs for symbols that are exclusive for that shader;
40 * - some symbols mimic output of other symbols - the best example is the "for" construct:
41 * expression "for (foo(); ; bar())" is seen as "for (foo(); true; bar())" by the output
42 * processor - hence, special care must be taken when rearranging output of essential symbols;
43 * - order of single-quoted tokens does matter in alternatives - so do not parse "<" operator
44 * before "<<" and "<<" before "<<=";
45 * - all double-quoted tokens are internally preprocessed to eliminate problems with parsing
46 * strings that are prefixes of other strings, like "sampler1D" and "sampler1DShadow";
47 */
48
49 .syntax translation_unit;
50
51 /* revision number - increment after each change affecting emitted output */
52 .emtcode REVISION 1
53
54 /* external declaration */
55 .emtcode EXTERNAL_NULL 0
56 .emtcode EXTERNAL_FUNCTION_DEFINITION 1
57 .emtcode EXTERNAL_DECLARATION 2
58
59 /* declaration */
60 .emtcode DECLARATION_FUNCTION_PROTOTYPE 1
61 .emtcode DECLARATION_INIT_DECLARATOR_LIST 2
62
63 /* function type */
64 .emtcode FUNCTION_ORDINARY 0
65 .emtcode FUNCTION_CONSTRUCTOR 1
66 .emtcode FUNCTION_OPERATOR 2
67
68 /* operator type */
69 .emtcode OPERATOR_ASSIGN 1
70 .emtcode OPERATOR_ADDASSIGN 2
71 .emtcode OPERATOR_SUBASSIGN 3
72 .emtcode OPERATOR_MULASSIGN 4
73 .emtcode OPERATOR_DIVASSIGN 5
74 /*.emtcode OPERATOR_MODASSIGN 6*/
75 /*.emtcode OPERATOR_LSHASSIGN 7*/
76 /*.emtcode OPERATOR_RSHASSIGN 8*/
77 /*.emtcode OPERATOR_ORASSIGN 9*/
78 /*.emtcode OPERATOR_XORASSIGN 10*/
79 /*.emtcode OPERATOR_ANDASSIGN 11*/
80 .emtcode OPERATOR_LOGICALXOR 12
81 /*.emtcode OPERATOR_BITOR 13*/
82 /*.emtcode OPERATOR_BITXOR 14*/
83 /*.emtcode OPERATOR_BITAND 15*/
84 .emtcode OPERATOR_EQUAL 16
85 .emtcode OPERATOR_NOTEQUAL 17
86 .emtcode OPERATOR_LESS 18
87 .emtcode OPERATOR_GREATER 19
88 .emtcode OPERATOR_LESSEQUAL 20
89 .emtcode OPERATOR_GREATEREQUAL 21
90 /*.emtcode OPERATOR_LSHIFT 22*/
91 /*.emtcode OPERATOR_RSHIFT 23*/
92 .emtcode OPERATOR_MULTIPLY 24
93 .emtcode OPERATOR_DIVIDE 25
94 /*.emtcode OPERATOR_MODULUS 26*/
95 .emtcode OPERATOR_INCREMENT 27
96 .emtcode OPERATOR_DECREMENT 28
97 .emtcode OPERATOR_PLUS 29
98 .emtcode OPERATOR_MINUS 30
99 /*.emtcode OPERATOR_COMPLEMENT 31*/
100 .emtcode OPERATOR_NOT 32
101
102 /* init declarator list */
103 .emtcode DECLARATOR_NONE 0
104 .emtcode DECLARATOR_NEXT 1
105
106 /* variable declaration */
107 .emtcode VARIABLE_NONE 0
108 .emtcode VARIABLE_IDENTIFIER 1
109 .emtcode VARIABLE_INITIALIZER 2
110 .emtcode VARIABLE_ARRAY_EXPLICIT 3
111 .emtcode VARIABLE_ARRAY_UNKNOWN 4
112
113 /* type qualifier */
114 .emtcode TYPE_QUALIFIER_NONE 0
115 .emtcode TYPE_QUALIFIER_CONST 1
116 .emtcode TYPE_QUALIFIER_ATTRIBUTE 2
117 .emtcode TYPE_QUALIFIER_VARYING 3
118 .emtcode TYPE_QUALIFIER_UNIFORM 4
119
120 /* type specifier */
121 .emtcode TYPE_SPECIFIER_VOID 0
122 .emtcode TYPE_SPECIFIER_BOOL 1
123 .emtcode TYPE_SPECIFIER_BVEC2 2
124 .emtcode TYPE_SPECIFIER_BVEC3 3
125 .emtcode TYPE_SPECIFIER_BVEC4 4
126 .emtcode TYPE_SPECIFIER_INT 5
127 .emtcode TYPE_SPECIFIER_IVEC2 6
128 .emtcode TYPE_SPECIFIER_IVEC3 7
129 .emtcode TYPE_SPECIFIER_IVEC4 8
130 .emtcode TYPE_SPECIFIER_FLOAT 9
131 .emtcode TYPE_SPECIFIER_VEC2 10
132 .emtcode TYPE_SPECIFIER_VEC3 11
133 .emtcode TYPE_SPECIFIER_VEC4 12
134 .emtcode TYPE_SPECIFIER_MAT2 13
135 .emtcode TYPE_SPECIFIER_MAT3 14
136 .emtcode TYPE_SPECIFIER_MAT4 15
137 .emtcode TYPE_SPECIFIER_SAMPLER1D 16
138 .emtcode TYPE_SPECIFIER_SAMPLER2D 17
139 .emtcode TYPE_SPECIFIER_SAMPLER3D 18
140 .emtcode TYPE_SPECIFIER_SAMPLERCUBE 19
141 .emtcode TYPE_SPECIFIER_SAMPLER1DSHADOW 20
142 .emtcode TYPE_SPECIFIER_SAMPLER2DSHADOW 21
143 .emtcode TYPE_SPECIFIER_STRUCT 22
144 .emtcode TYPE_SPECIFIER_TYPENAME 23
145
146 /* structure field */
147 .emtcode FIELD_NONE 0
148 .emtcode FIELD_NEXT 1
149 .emtcode FIELD_ARRAY 2
150
151 /* operation */
152 .emtcode OP_END 0
153 .emtcode OP_BLOCK_BEGIN_NO_NEW_SCOPE 1
154 .emtcode OP_BLOCK_BEGIN_NEW_SCOPE 2
155 .emtcode OP_DECLARE 3
156 .emtcode OP_ASM 4
157 .emtcode OP_BREAK 5
158 .emtcode OP_CONTINUE 6
159 .emtcode OP_DISCARD 7
160 .emtcode OP_RETURN 8
161 .emtcode OP_EXPRESSION 9
162 .emtcode OP_IF 10
163 .emtcode OP_WHILE 11
164 .emtcode OP_DO 12
165 .emtcode OP_FOR 13
166 .emtcode OP_PUSH_VOID 14
167 .emtcode OP_PUSH_BOOL 15
168 .emtcode OP_PUSH_INT 16
169 .emtcode OP_PUSH_FLOAT 17
170 .emtcode OP_PUSH_IDENTIFIER 18
171 .emtcode OP_SEQUENCE 19
172 .emtcode OP_ASSIGN 20
173 .emtcode OP_ADDASSIGN 21
174 .emtcode OP_SUBASSIGN 22
175 .emtcode OP_MULASSIGN 23
176 .emtcode OP_DIVASSIGN 24
177 /*.emtcode OP_MODASSIGN 25*/
178 /*.emtcode OP_LSHASSIGN 26*/
179 /*.emtcode OP_RSHASSIGN 27*/
180 /*.emtcode OP_ORASSIGN 28*/
181 /*.emtcode OP_XORASSIGN 29*/
182 /*.emtcode OP_ANDASSIGN 30*/
183 .emtcode OP_SELECT 31
184 .emtcode OP_LOGICALOR 32
185 .emtcode OP_LOGICALXOR 33
186 .emtcode OP_LOGICALAND 34
187 /*.emtcode OP_BITOR 35*/
188 /*.emtcode OP_BITXOR 36*/
189 /*.emtcode OP_BITAND 37*/
190 .emtcode OP_EQUAL 38
191 .emtcode OP_NOTEQUAL 39
192 .emtcode OP_LESS 40
193 .emtcode OP_GREATER 41
194 .emtcode OP_LESSEQUAL 42
195 .emtcode OP_GREATEREQUAL 43
196 /*.emtcode OP_LSHIFT 44*/
197 /*.emtcode OP_RSHIFT 45*/
198 .emtcode OP_ADD 46
199 .emtcode OP_SUBTRACT 47
200 .emtcode OP_MULTIPLY 48
201 .emtcode OP_DIVIDE 49
202 /*.emtcode OP_MODULUS 50*/
203 .emtcode OP_PREINCREMENT 51
204 .emtcode OP_PREDECREMENT 52
205 .emtcode OP_PLUS 53
206 .emtcode OP_MINUS 54
207 /*.emtcode OP_COMPLEMENT 55*/
208 .emtcode OP_NOT 56
209 .emtcode OP_SUBSCRIPT 57
210 .emtcode OP_CALL 58
211 .emtcode OP_FIELD 59
212 .emtcode OP_POSTINCREMENT 60
213 .emtcode OP_POSTDECREMENT 61
214
215 /* parameter qualifier */
216 .emtcode PARAM_QUALIFIER_IN 0
217 .emtcode PARAM_QUALIFIER_OUT 1
218 .emtcode PARAM_QUALIFIER_INOUT 2
219
220 /* function parameter */
221 .emtcode PARAMETER_NONE 0
222 .emtcode PARAMETER_NEXT 1
223
224 /* function parameter array presence */
225 .emtcode PARAMETER_ARRAY_NOT_PRESENT 0
226 .emtcode PARAMETER_ARRAY_PRESENT 1
227
228 .errtext INVALID_EXTERNAL_DECLARATION "error 2001: invalid external declaration"
229 .errtext INVALID_OPERATOR_OVERRIDE "error 2002: invalid operator override"
230 .errtext LBRACE_EXPECTED "error 2003: '{' expected but '$err_token$' found"
231 .errtext LPAREN_EXPECTED "error 2004: '(' expected but '$err_token$' found"
232 .errtext RPAREN_EXPECTED "error 2005: ')' expected but '$err_token$' found"
233
234 /* tells whether the shader that is being parsed is a built-in shader or not */
235 /* 0 - normal behaviour */
236 /* 1 - accepts constructor and operator definitions and __asm statements */
237 /* the implementation will set it to 1 when compiling internal built-in shaders */
238 .regbyte parsing_builtin 0
239
240 /* holds the type of shader that is being parsed, possible values are listed below */
241 /* FRAGMENT_SHADER 1 */
242 /* VERTEX_SHADER 2 */
243 /* shader type is set by the caller before parsing */
244 .regbyte shader_type 0
245
246 /*
247 <variable_identifier> ::= <identifier>
248 */
249 variable_identifier
250 identifier .emit OP_PUSH_IDENTIFIER;
251
252 /*
253 <primary_expression> ::= <variable_identifier>
254 | <intconstant>
255 | <floatconstant>
256 | <boolconstant>
257 | "(" <expression> ")"
258 */
259 primary_expression
260 floatconstant .or boolconstant .or intconstant .or variable_identifier .or primary_expression_1;
261 primary_expression_1
262 lparen .and expression .and rparen;
263
264 /*
265 <postfix_expression> ::= <primary_expression>
266 | <postfix_expression> "[" <integer_expression> "]"
267 | <function_call>
268 | <postfix_expression> "." <field_selection>
269 | <postfix_expression> "++"
270 | <postfix_expression> "--"
271 */
272 postfix_expression
273 postfix_expression_1 .and .loop postfix_expression_2;
274 postfix_expression_1
275 function_call .or primary_expression;
276 postfix_expression_2
277 postfix_expression_3 .or postfix_expression_4 .or
278 plusplus .emit OP_POSTINCREMENT .or
279 minusminus .emit OP_POSTDECREMENT;
280 postfix_expression_3
281 lbracket .and integer_expression .and rbracket .emit OP_SUBSCRIPT;
282 postfix_expression_4
283 dot .and field_selection .emit OP_FIELD;
284
285 /*
286 <integer_expression> ::= <expression>
287 */
288 integer_expression
289 expression;
290
291 /*
292 <function_call> ::= <function_call_generic>
293 */
294 function_call
295 function_call_generic .emit OP_CALL .and .true .emit OP_END;
296
297 /*
298 <function_call_generic> ::= <function_call_header_with_parameters> ")"
299 | <function_call_header_no_parameters> ")"
300 */
301 function_call_generic
302 function_call_generic_1 .or function_call_generic_2;
303 function_call_generic_1
304 function_call_header_with_parameters .and rparen .error RPAREN_EXPECTED;
305 function_call_generic_2
306 function_call_header_no_parameters .and rparen .error RPAREN_EXPECTED;
307
308 /*
309 <function_call_header_no_parameters>::= <function_call_header> "void"
310 | <function_call_header>
311 */
312 function_call_header_no_parameters
313 function_call_header .and function_call_header_no_parameters_1;
314 function_call_header_no_parameters_1
315 "void" .or .true;
316
317 /*
318 <function_call_header_with_parameters>::= <function_call_header> <assignment_expression>
319 | <function_call_header_with_parameters> ","
320 <assignment_expression>
321 */
322 function_call_header_with_parameters
323 function_call_header .and assignment_expression .and .true .emit OP_END .and
324 .loop function_call_header_with_parameters_1;
325 function_call_header_with_parameters_1
326 comma .and assignment_expression .and .true .emit OP_END;
327
328 /*
329 <function_call_header> ::= <function_identifier> "("
330 */
331 function_call_header
332 function_identifier .and lparen;
333
334 /*
335 <function_identifier> ::= <constructor_identifier>
336 | <identifier>
337
338 note: <constructor_identifier> has been deleted
339 */
340 function_identifier
341 identifier;
342
343 /*
344 <unary_expression> ::= <postfix_expression>
345 | "++" <unary_expression>
346 | "--" <unary_expression>
347 | <unary_operator> <unary_expression>
348
349 <unary_operator> ::= "+"
350 | "-"
351 | "!"
352 | "~" // reserved
353 */
354 unary_expression
355 postfix_expression .or unary_expression_1 .or unary_expression_2 .or unary_expression_3 .or
356 unary_expression_4 .or unary_expression_5/* .or unary_expression_6*/;
357 unary_expression_1
358 plusplus .and unary_expression .and .true .emit OP_PREINCREMENT;
359 unary_expression_2
360 minusminus .and unary_expression .and .true .emit OP_PREDECREMENT;
361 unary_expression_3
362 plus .and unary_expression .and .true .emit OP_PLUS;
363 unary_expression_4
364 minus .and unary_expression .and .true .emit OP_MINUS;
365 unary_expression_5
366 bang .and unary_expression .and .true .emit OP_NOT;
367 /*unary_expression_6
368 tilde .and unary_expression .and .true .emit OP_COMPLEMENT;*/
369
370 /*
371 <multiplicative_expression> ::= <unary_expression>
372 | <multiplicative_expression> "*" <unary_expression>
373 | <multiplicative_expression> "/" <unary_expression>
374 | <multiplicative_expression> "%" <unary_expression> // reserved
375 */
376 multiplicative_expression
377 unary_expression .and .loop multiplicative_expression_1;
378 multiplicative_expression_1
379 multiplicative_expression_2 .or multiplicative_expression_3/* .or multiplicative_expression_4*/;
380 multiplicative_expression_2
381 star .and unary_expression .and .true .emit OP_MULTIPLY;
382 multiplicative_expression_3
383 slash .and unary_expression .and .true .emit OP_DIVIDE;
384 /*multiplicative_expression_4
385 percent .and unary_expression .and .true .emit OP_MODULUS;*/
386
387 /*
388 <additive_expression> ::= <multiplicative_expression>
389 | <additive_expression> "+" <multiplicative_expression>
390 | <additive_expression> "-" <multiplicative_expression>
391 */
392 additive_expression
393 multiplicative_expression .and .loop additive_expression_1;
394 additive_expression_1
395 additive_expression_2 .or additive_expression_3;
396 additive_expression_2
397 plus .and multiplicative_expression .and .true .emit OP_ADD;
398 additive_expression_3
399 minus .and multiplicative_expression .and .true .emit OP_SUBTRACT;
400
401 /*
402 <shift_expression> ::= <additive_expression>
403 | <shift_expression> "<<" <additive_expression> // reserved
404 | <shift_expression> ">>" <additive_expression> // reserved
405 */
406 shift_expression
407 additive_expression/* .and .loop shift_expression_1*/;
408 /*shift_expression_1
409 shift_expression_2 .or shift_expression_3;*/
410 /*shift_expression_2
411 lessless .and additive_expression .and .true .emit OP_LSHIFT;*/
412 /*shift_expression_3
413 greatergreater .and additive_expression .and .true .emit OP_RSHIFT;*/
414
415 /*
416 <relational_expression> ::= <shift_expression>
417 | <relational_expression> "<" <shift_expression>
418 | <relational_expression> ">" <shift_expression>
419 | <relational_expression> "<=" <shift_expression>
420 | <relational_expression> ">=" <shift_expression>
421 */
422 relational_expression
423 shift_expression .and .loop relational_expression_1;
424 relational_expression_1
425 relational_expression_2 .or relational_expression_3 .or relational_expression_4 .or
426 relational_expression_5;
427 relational_expression_2
428 lessequals .and shift_expression .and .true .emit OP_LESSEQUAL;
429 relational_expression_3
430 greaterequals .and shift_expression .and .true .emit OP_GREATEREQUAL;
431 relational_expression_4
432 less .and shift_expression .and .true .emit OP_LESS;
433 relational_expression_5
434 greater .and shift_expression .and .true .emit OP_GREATER;
435
436 /*
437 <equality_expression> ::= <relational_expression>
438 | <equality_expression> "==" <relational_expression>
439 | <equality_expression> "!=" <relational_expression>
440 */
441 equality_expression
442 relational_expression .and .loop equality_expression_1;
443 equality_expression_1
444 equality_expression_2 .or equality_expression_3;
445 equality_expression_2
446 equalsequals .and relational_expression .and .true .emit OP_EQUAL;
447 equality_expression_3
448 bangequals .and relational_expression .and .true .emit OP_NOTEQUAL;
449
450 /*
451 <and_expression> ::= <equality_expression>
452 | <and_expression> "&" <equality_expression> // reserved
453 */
454 and_expression
455 equality_expression/* .and .loop and_expression_1*/;
456 /*and_expression_1
457 ampersand .and equality_expression .and .true .emit OP_BITAND;*/
458
459 /*
460 <exclusive_or_expression> ::= <and_expression>
461 | <exclusive_or_expression> "^" <and_expression> // reserved
462 */
463 exclusive_or_expression
464 and_expression/* .and .loop exclusive_or_expression_1*/;
465 /*exclusive_or_expression_1
466 caret .and and_expression .and .true .emit OP_BITXOR;*/
467
468 /*
469 <inclusive_or_expression> ::= <exclusive_or_expression>
470 | <inclusive_or_expression> "|" <exclusive_or_expression> // reserved
471 */
472 inclusive_or_expression
473 exclusive_or_expression/* .and .loop inclusive_or_expression_1*/;
474 /*inclusive_or_expression_1
475 bar .and exclusive_or_expression .and .true .emit OP_BITOR;*/
476
477 /*
478 <logical_and_expression> ::= <inclusive_or_expression>
479 | <logical_and_expression> "&&" <inclusive_or_expression>
480 */
481 logical_and_expression
482 inclusive_or_expression .and .loop logical_and_expression_1;
483 logical_and_expression_1
484 ampersandampersand .and inclusive_or_expression .and .true .emit OP_LOGICALAND;
485
486 /*
487 <logical_xor_expression> ::= <logical_and_expression>
488 | <logical_xor_expression> "^^" <logical_and_expression>
489 */
490 logical_xor_expression
491 logical_and_expression .and .loop logical_xor_expression_1;
492 logical_xor_expression_1
493 caretcaret .and logical_and_expression .and .true .emit OP_LOGICALXOR;
494
495 /*
496 <logical_or_expression> ::= <logical_xor_expression>
497 | <logical_or_expression> "||" <logical_xor_expression>
498 */
499 logical_or_expression
500 logical_xor_expression .and .loop logical_or_expression_1;
501 logical_or_expression_1
502 barbar .and logical_xor_expression .and .true .emit OP_LOGICALOR;
503
504 /*
505 <conditional_expression> ::= <logical_or_expression>
506 | <logical_or_expression> "?" <expression> ":"
507 <conditional_expression>
508 */
509 conditional_expression
510 logical_or_expression .and .loop conditional_expression_1;
511 conditional_expression_1
512 question .and expression .and colon .and conditional_expression .and .true .emit OP_SELECT;
513
514 /*
515 <assignment_expression> ::= <conditional_expression>
516 | <unary_expression> <assignment_operator>
517 <assignment_expression>
518
519 <assignment_operator> ::= "="
520 | "*="
521 | "/="
522 | "+="
523 | "-="
524 | "%=" // reserved
525 | "<<=" // reserved
526 | ">>=" // reserved
527 | "&=" // reserved
528 | "^=" // reserved
529 | "|=" // reserved
530 */
531 assignment_expression
532 assignment_expression_1 .or assignment_expression_2 .or assignment_expression_3 .or
533 assignment_expression_4 .or assignment_expression_5/* .or assignment_expression_6 .or
534 assignment_expression_7 .or assignment_expression_8 .or assignment_expression_9 .or
535 assignment_expression_10 .or assignment_expression_11*/ .or conditional_expression;
536 assignment_expression_1
537 unary_expression .and equals .and assignment_expression .and .true .emit OP_ASSIGN;
538 assignment_expression_2
539 unary_expression .and starequals .and assignment_expression .and .true .emit OP_MULASSIGN;
540 assignment_expression_3
541 unary_expression .and slashequals .and assignment_expression .and .true .emit OP_DIVASSIGN;
542 assignment_expression_4
543 unary_expression .and plusequals .and assignment_expression .and .true .emit OP_ADDASSIGN;
544 assignment_expression_5
545 unary_expression .and minusequals .and assignment_expression .and .true .emit OP_SUBASSIGN;
546 /*assignment_expression_6
547 unary_expression .and percentequals .and assignment_expression .and .true .emit OP_MODASSIGN;*/
548 /*assignment_expression_7
549 unary_expression .and lesslessequals .and assignment_expression .and .true .emit OP_LSHASSIGN;*/
550 /*assignment_expression_8
551 unary_expression .and greatergreaterequals .and assignment_expression .and
552 .true .emit OP_RSHASSIGN;*/
553 /*assignment_expression_9
554 unary_expression .and ampersandequals .and assignment_expression .and .true .emit OP_ANDASSIGN;*/
555 /*assignment_expression_10
556 unary_expression .and caretequals .and assignment_expression .and .true .emit OP_XORASSIGN;*/
557 /*assignment_expression_11
558 unary_expression .and barequals .and assignment_expression .and .true .emit OP_ORASSIGN;*/
559
560 /*
561 <expression> ::= <assignment_expression>
562 | <expression> "," <assignment_expression>
563 */
564 expression
565 assignment_expression .and .loop expression_1;
566 expression_1
567 comma .and assignment_expression .and .true .emit OP_SEQUENCE;
568
569 /*
570 <constant_expression> ::= <conditional_expression>
571 */
572 constant_expression
573 conditional_expression .and .true .emit OP_END;
574
575 /*
576 <declaration> ::= <function_prototype> ";"
577 | <init_declarator_list> ";"
578 */
579 declaration
580 declaration_1 .or declaration_2;
581 declaration_1
582 function_prototype .emit DECLARATION_FUNCTION_PROTOTYPE .and semicolon;
583 declaration_2
584 init_declarator_list .emit DECLARATION_INIT_DECLARATOR_LIST .and semicolon;
585
586 /*
587 <function_prototype> ::= <function_declarator> ")"
588 */
589 function_prototype
590 function_declarator .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
591
592 /*
593 <function_declarator> ::= <function_header>
594 | <function_header_with_parameters>
595 */
596 function_declarator
597 function_header_with_parameters .or function_header;
598
599 /*
600 <function_header_with_parameters> ::= <function_header> <parameter_declaration>
601 | <function_header_with_parameters> ","
602 <parameter_declaration>
603 */
604 function_header_with_parameters
605 function_header .and parameter_declaration .and .loop function_header_with_parameters_1;
606 function_header_with_parameters_1
607 comma .and parameter_declaration;
608
609 /*
610 <function_header> ::= <fully_specified_type> <identifier> "("
611 */
612 function_header
613 function_header_nospace .or function_header_space;
614 function_header_space
615 fully_specified_type_space .and space .and function_decl_identifier .and lparen;
616 function_header_nospace
617 fully_specified_type_nospace .and function_decl_identifier .and lparen;
618
619 /*
620 <function_decl_identifier> ::= "__constructor"
621 | <__operator>
622 | <identifier>
623
624 note: this is an extension to the standard language specification - normally slang disallows
625 operator and constructor prototypes and definitions
626 */
627 function_decl_identifier
628 .if (parsing_builtin != 0) __operator .emit FUNCTION_OPERATOR .or
629 .if (parsing_builtin != 0) "__constructor" .emit FUNCTION_CONSTRUCTOR .or
630 identifier .emit FUNCTION_ORDINARY;
631
632 /*
633 <__operator> ::= "__operator" <overriden_op>
634
635 note: this is an extension to the standard language specification - normally slang disallows
636 operator prototypes and definitions
637 */
638 __operator
639 "__operator" .and overriden_operator .error INVALID_OPERATOR_OVERRIDE;
640
641 /*
642 <overriden_op> ::= "="
643 | "+="
644 | "-="
645 | "*="
646 | "/="
647 | "%=" // reserved
648 | "<<=" // reserved
649 | ">>=" // reserved
650 | "&=" // reserved
651 | "^=" // reserved
652 | "|=" // reserved
653 | "^^"
654 | "|" // reserved
655 | "^" // reserved
656 | "&" // reserved
657 | "=="
658 | "!="
659 | "<"
660 | ">"
661 | "<="
662 | ">="
663 | "<<" // reserved
664 | ">>" // reserved
665 | "*"
666 | "/"
667 | "%" // reserved
668 | "++"
669 | "--"
670 | "+"
671 | "-"
672 | "~" // reserved
673 | "!"
674
675 note: this is an extension to the standard language specification - normally slang disallows
676 operator prototypes and definitions
677 */
678 overriden_operator
679 plusplus .emit OPERATOR_INCREMENT .or
680 plusequals .emit OPERATOR_ADDASSIGN .or
681 plus .emit OPERATOR_PLUS .or
682 minusminus .emit OPERATOR_DECREMENT .or
683 minusequals .emit OPERATOR_SUBASSIGN .or
684 minus .emit OPERATOR_MINUS .or
685 bangequals .emit OPERATOR_NOTEQUAL .or
686 bang .emit OPERATOR_NOT .or
687 starequals .emit OPERATOR_MULASSIGN .or
688 star .emit OPERATOR_MULTIPLY .or
689 slashequals .emit OPERATOR_DIVASSIGN .or
690 slash .emit OPERATOR_DIVIDE .or
691 lessequals .emit OPERATOR_LESSEQUAL .or
692 /*lesslessequals .emit OPERATOR_LSHASSIGN .or*/
693 /*lessless .emit OPERATOR_LSHIFT .or*/
694 less .emit OPERATOR_LESS .or
695 greaterequals .emit OPERATOR_GREATEREQUAL .or
696 /*greatergreaterequals .emit OPERATOR_RSHASSIGN .or*/
697 /*greatergreater .emit OPERATOR_RSHIFT .or*/
698 greater .emit OPERATOR_GREATER .or
699 equalsequals .emit OPERATOR_EQUAL .or
700 equals .emit OPERATOR_ASSIGN .or
701 /*percentequals .emit OPERATOR_MODASSIGN .or*/
702 /*percent .emit OPERATOR_MODULUS .or*/
703 /*ampersandequals .emit OPERATOR_ANDASSIGN */
704 /*ampersand .emit OPERATOR_BITAND .or*/
705 /*barequals .emit OPERATOR_ORASSIGN .or*/
706 /*bar .emit OPERATOR_BITOR .or*/
707 /*tilde .emit OPERATOR_COMPLEMENT .or*/
708 /*caretequals .emit OPERATOR_XORASSIGN .or*/
709 caretcaret .emit OPERATOR_LOGICALXOR /*.or
710 caret .emit OPERATOR_BITXOR*/;
711
712 /*
713 <parameter_declarator> ::= <type_specifier> <identifier>
714 | <type_specifier> <identifier> "[" <constant_expression>
715 "]"
716 */
717 parameter_declarator
718 parameter_declarator_nospace .or parameter_declarator_space;
719 parameter_declarator_nospace
720 type_specifier_nospace .and identifier .and parameter_declarator_1;
721 parameter_declarator_space
722 type_specifier_space .and space .and identifier .and parameter_declarator_1;
723 parameter_declarator_1
724 parameter_declarator_2 .emit PARAMETER_ARRAY_PRESENT .or
725 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
726 parameter_declarator_2
727 lbracket .and constant_expression .and rbracket;
728
729 /*
730 <parameter_declaration> ::= <type_qualifier> <parameter_qualifier>
731 <parameter_declarator>
732 | <type_qualifier> <parameter_qualifier>
733 <parameter_type_specifier>
734 | <parameter_qualifier> <parameter_declarator>
735 | <parameter_qualifier> <parameter_type_specifier>
736 */
737 parameter_declaration
738 parameter_declaration_1 .emit PARAMETER_NEXT;
739 parameter_declaration_1
740 parameter_declaration_2 .or parameter_declaration_3;
741 parameter_declaration_2
742 type_qualifier .and space .and parameter_qualifier .and parameter_declaration_4;
743 parameter_declaration_3
744 parameter_qualifier .emit TYPE_QUALIFIER_NONE .and parameter_declaration_4;
745 parameter_declaration_4
746 parameter_declarator .or parameter_type_specifier;
747
748 /*
749 <parameter_qualifier> ::= "in"
750 | "out"
751 | "inout"
752 | ""
753 */
754 parameter_qualifier
755 parameter_qualifier_1 .or .true .emit PARAM_QUALIFIER_IN;
756 parameter_qualifier_1
757 parameter_qualifier_2 .and space;
758 parameter_qualifier_2
759 "in" .emit PARAM_QUALIFIER_IN .or
760 "out" .emit PARAM_QUALIFIER_OUT .or
761 "inout" .emit PARAM_QUALIFIER_INOUT;
762
763 /*
764 <parameter_type_specifier> ::= <type_specifier>
765 | <type_specifier> "[" <constant_expression> "]"
766 */
767 parameter_type_specifier
768 parameter_type_specifier_1 .and .true .emit '\0' .and parameter_type_specifier_2;
769 parameter_type_specifier_1
770 type_specifier_nospace .or type_specifier_space;
771 parameter_type_specifier_2
772 parameter_type_specifier_3 .emit PARAMETER_ARRAY_PRESENT .or
773 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
774 parameter_type_specifier_3
775 lbracket .and constant_expression .and rbracket;
776
777 /*
778 <init_declarator_list> ::= <single_declaration>
779 | <init_declarator_list> "," <identifier>
780 | <init_declarator_list> "," <identifier> "[" "]"
781 | <init_declarator_list> "," <identifier> "["
782 <constant_expression> "]"
783 | <init_declarator_list> "," <identifier> "="
784 <initializer>
785 */
786 init_declarator_list
787 single_declaration .and .loop init_declarator_list_1 .emit DECLARATOR_NEXT .and
788 .true .emit DECLARATOR_NONE;
789 init_declarator_list_1
790 comma .and identifier .emit VARIABLE_IDENTIFIER .and init_declarator_list_2;
791 init_declarator_list_2
792 init_declarator_list_3 .or init_declarator_list_4 .or .true .emit VARIABLE_NONE;
793 init_declarator_list_3
794 equals .and initializer .emit VARIABLE_INITIALIZER;
795 init_declarator_list_4
796 lbracket .and init_declarator_list_5 .and rbracket;
797 init_declarator_list_5
798 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
799
800 /*
801 <single_declaration> ::= <fully_specified_type>
802 | <fully_specified_type> <identifier>
803 | <fully_specified_type> <identifier> "[" "]"
804 | <fully_specified_type> <identifier> "["
805 <constant_expression> "]"
806 | <fully_specified_type> <identifier> "=" <initializer>
807 */
808 single_declaration
809 single_declaration_nospace .or single_declaration_space;
810 single_declaration_space
811 fully_specified_type_space .and single_declaration_space_1;
812 single_declaration_nospace
813 fully_specified_type_nospace .and single_declaration_nospace_1;
814 single_declaration_space_1
815 single_declaration_space_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
816 single_declaration_nospace_1
817 single_declaration_nospace_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
818 single_declaration_space_2
819 space .and identifier .and single_declaration_3;
820 single_declaration_nospace_2
821 identifier .and single_declaration_3;
822 single_declaration_3
823 single_declaration_4 .or single_declaration_5 .or .true .emit VARIABLE_NONE;
824 single_declaration_4
825 equals .and initializer .emit VARIABLE_INITIALIZER;
826 single_declaration_5
827 lbracket .and single_declaration_6 .and rbracket;
828 single_declaration_6
829 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
830
831 /*
832 <fully_specified_type> ::= <type_specifier>
833 | <type_qualifier> <type_specifier>
834 */
835 fully_specified_type_space
836 fully_specified_type_1 .and type_specifier_space;
837 fully_specified_type_nospace
838 fully_specified_type_1 .and type_specifier_nospace;
839 fully_specified_type_1
840 fully_specified_type_2 .or .true .emit TYPE_QUALIFIER_NONE;
841 fully_specified_type_2
842 type_qualifier .and space;
843
844 /*
845 <type_qualifier> ::= "const"
846 | "attribute" // Vertex only.
847 | "varying"
848 | "uniform"
849 */
850 type_qualifier
851 "const" .emit TYPE_QUALIFIER_CONST .or
852 .if (shader_type == 2) "attribute" .emit TYPE_QUALIFIER_ATTRIBUTE .or
853 "varying" .emit TYPE_QUALIFIER_VARYING .or
854 "uniform" .emit TYPE_QUALIFIER_UNIFORM;
855
856 /*
857 <type_specifier> ::= "void"
858 | "float"
859 | "int"
860 | "bool"
861 | "vec2"
862 | "vec3"
863 | "vec4"
864 | "bvec2"
865 | "bvec3"
866 | "bvec4"
867 | "ivec2"
868 | "ivec3"
869 | "ivec4"
870 | "mat2"
871 | "mat3"
872 | "mat4"
873 | "sampler1D"
874 | "sampler2D"
875 | "sampler3D"
876 | "samplerCube"
877 | "sampler1DShadow"
878 | "sampler2DShadow"
879 | <struct_specifier>
880 | <type_name>
881 */
882 type_specifier_space
883 "void" .emit TYPE_SPECIFIER_VOID .or
884 "float" .emit TYPE_SPECIFIER_FLOAT .or
885 "int" .emit TYPE_SPECIFIER_INT .or
886 "bool" .emit TYPE_SPECIFIER_BOOL .or
887 "vec2" .emit TYPE_SPECIFIER_VEC2 .or
888 "vec3" .emit TYPE_SPECIFIER_VEC3 .or
889 "vec4" .emit TYPE_SPECIFIER_VEC4 .or
890 "bvec2" .emit TYPE_SPECIFIER_BVEC2 .or
891 "bvec3" .emit TYPE_SPECIFIER_BVEC3 .or
892 "bvec4" .emit TYPE_SPECIFIER_BVEC4 .or
893 "ivec2" .emit TYPE_SPECIFIER_IVEC2 .or
894 "ivec3" .emit TYPE_SPECIFIER_IVEC3 .or
895 "ivec4" .emit TYPE_SPECIFIER_IVEC4 .or
896 "mat2" .emit TYPE_SPECIFIER_MAT2 .or
897 "mat3" .emit TYPE_SPECIFIER_MAT3 .or
898 "mat4" .emit TYPE_SPECIFIER_MAT4 .or
899 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
900 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
901 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
902 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
903 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
904 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
905 type_name .emit TYPE_SPECIFIER_TYPENAME;
906 type_specifier_nospace
907 struct_specifier .emit TYPE_SPECIFIER_STRUCT;
908
909 /*
910 <struct_specifier> ::= "struct" <identifier> "{" <struct_declaration_list> "}"
911 | "struct" "{" <struct_declaration_list> "}"
912 */
913 struct_specifier
914 "struct" .and struct_specifier_1 .and optional_space .and lbrace .error LBRACE_EXPECTED .and
915 struct_declaration_list .and rbrace .emit FIELD_NONE;
916 struct_specifier_1
917 struct_specifier_2 .or .true .emit '\0';
918 struct_specifier_2
919 space .and identifier;
920
921 /*
922 <struct_declaration_list> ::= <struct_declaration>
923 | <struct_declaration_list> <struct_declaration>
924 */
925 struct_declaration_list
926 struct_declaration .and .loop struct_declaration .emit FIELD_NEXT;
927
928 /*
929 <struct_declaration> ::= <type_specifier> <struct_declarator_list> ";"
930 */
931 struct_declaration
932 struct_declaration_nospace .or struct_declaration_space;
933 struct_declaration_space
934 type_specifier_space .and space .and struct_declarator_list .and semicolon .emit FIELD_NONE;
935 struct_declaration_nospace
936 type_specifier_nospace .and struct_declarator_list .and semicolon .emit FIELD_NONE;
937
938 /*
939 <struct_declarator_list> ::= <struct_declarator>
940 | <struct_declarator_list> "," <struct_declarator>
941 */
942 struct_declarator_list
943 struct_declarator .and .loop struct_declarator_list_1 .emit FIELD_NEXT;
944 struct_declarator_list_1
945 comma .and struct_declarator;
946
947 /*
948 <struct_declarator> ::= <identifier>
949 | <identifier> "[" <constant_expression> "]"
950 */
951 struct_declarator
952 identifier .and struct_declarator_1;
953 struct_declarator_1
954 struct_declarator_2 .emit FIELD_ARRAY .or .true .emit FIELD_NONE;
955 struct_declarator_2
956 lbracket .and constant_expression .and rbracket;
957
958 /*
959 <initializer> ::= <assignment_expression>
960 */
961 initializer
962 assignment_expression .and .true .emit OP_END;
963
964 /*
965 <declaration_statement> ::= <declaration>
966 */
967 declaration_statement
968 declaration;
969
970 /*
971 <statement> ::= <compound_statement>
972 | <simple_statement>
973 */
974 statement
975 compound_statement .or simple_statement;
976 statement_space
977 compound_statement .or statement_space_1;
978 statement_space_1
979 space .and simple_statement;
980
981 /*
982 <simple_statement> ::= <__asm_statement>
983 | <selection_statement>
984 | <iteration_statement>
985 | <jump_statement>
986 | <expression_statement>
987 | <declaration_statement>
988
989 note: this is an extension to the standard language specification - normally slang disallows
990 use of __asm statements
991 */
992 simple_statement
993 .if (parsing_builtin != 0) __asm_statement .emit OP_ASM .or
994 selection_statement .or
995 iteration_statement .or
996 jump_statement .or
997 expression_statement .emit OP_EXPRESSION .or
998 declaration_statement .emit OP_DECLARE;
999
1000 /*
1001 <compound_statement> ::= "{" "}"
1002 | "{" <statement_list> "}"
1003 */
1004 compound_statement
1005 compound_statement_1 .emit OP_BLOCK_BEGIN_NEW_SCOPE .and .true .emit OP_END;
1006 compound_statement_1
1007 compound_statement_2 .or compound_statement_3;
1008 compound_statement_2
1009 lbrace .and rbrace;
1010 compound_statement_3
1011 lbrace .and statement_list .and rbrace;
1012
1013 /*
1014 <statement_no_new_scope> ::= <compound_statement_no_new_scope>
1015 | <simple_statement>
1016 */
1017 statement_no_new_scope
1018 compound_statement_no_new_scope .or simple_statement;
1019
1020 /*
1021 <compound_statement_no_new_scope> ::= "{" "}"
1022 | "{" <statement_list> "}"
1023 */
1024 compound_statement_no_new_scope
1025 compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;
1026 compound_statement_no_new_scope_1
1027 compound_statement_no_new_scope_2 .or compound_statement_no_new_scope_3;
1028 compound_statement_no_new_scope_2
1029 lbrace .and rbrace;
1030 compound_statement_no_new_scope_3
1031 lbrace .and statement_list .and rbrace;
1032
1033 /*
1034 <statement_list> ::= <statement>
1035 | <statement_list> <statement>
1036 */
1037 statement_list
1038 statement .and .loop statement;
1039
1040 /*
1041 <expression_statement> ::= ";"
1042 | <expression> ";"
1043 */
1044 expression_statement
1045 expression_statement_1 .or expression_statement_2;
1046 expression_statement_1
1047 semicolon .emit OP_PUSH_VOID .emit OP_END;
1048 expression_statement_2
1049 expression .and semicolon .emit OP_END;
1050
1051 /*
1052 <selection_statement> ::= "if" "(" <expression> ")" <selection_rest_statement>
1053 */
1054 selection_statement
1055 "if" .emit OP_IF .and lparen .error LPAREN_EXPECTED .and expression .and
1056 rparen .error RPAREN_EXPECTED .emit OP_END .and selection_rest_statement;
1057
1058 /*
1059 <selection_rest_statement> ::= <statement> "else" <statement>
1060 | <statement>
1061 */
1062 selection_rest_statement
1063 statement .and selection_rest_statement_1;
1064 selection_rest_statement_1
1065 selection_rest_statement_2 .or .true .emit OP_EXPRESSION .emit OP_PUSH_VOID .emit OP_END;
1066 selection_rest_statement_2
1067 "else" .and optional_space .and statement;
1068
1069 /*
1070 <condition> ::= <expression>
1071 | <fully_specified_type> <identifier> "=" <initializer>
1072
1073 note: if <condition_1> is executed, the emit format must match <declaration> emit format
1074 */
1075 condition
1076 condition_1 .emit OP_DECLARE .emit DECLARATION_INIT_DECLARATOR_LIST .or
1077 condition_3 .emit OP_EXPRESSION;
1078 condition_1
1079 condition_1_nospace .or condition_1_space;
1080 condition_1_nospace
1081 fully_specified_type_nospace .and condition_2;
1082 condition_1_space
1083 fully_specified_type_space .and space .and condition_2;
1084 condition_2
1085 identifier .emit VARIABLE_IDENTIFIER .and equals .emit VARIABLE_INITIALIZER .and
1086 initializer .and .true .emit DECLARATOR_NONE;
1087 condition_3
1088 expression .and .true .emit OP_END;
1089
1090 /*
1091 <iteration_statement> ::= "while" "(" <condition> ")" <statement_no_new_scope>
1092 | "do" <statement> "while" "(" <expression> ")" ";"
1093 | "for" "(" <for_init_statement> <for_rest_statement> ")"
1094 <statement_no_new_scope>
1095 */
1096 iteration_statement
1097 iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3;
1098 iteration_statement_1
1099 "while" .emit OP_WHILE .and lparen .error LPAREN_EXPECTED .and condition .and
1100 rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
1101 iteration_statement_2
1102 "do" .emit OP_DO .and statement_space .and "while" .and lparen .error LPAREN_EXPECTED .and
1103 expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;
1104 iteration_statement_3
1105 "for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and
1106 for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
1107
1108 /*
1109 <for_init_statement> ::= <expression_statement>
1110 | <declaration_statement>
1111 */
1112 for_init_statement
1113 expression_statement .or declaration_statement;
1114
1115 /*
1116 <conditionopt> ::= <condition>
1117 | ""
1118
1119 note: <conditionopt> is used only by "for" statement - if <condition> is ommitted, parser
1120 simulates default behaviour, that is simulates "true" expression
1121 */
1122 conditionopt
1123 condition .or
1124 .true .emit OP_EXPRESSION .emit OP_PUSH_BOOL .emit 2 .emit '1' .emit '\0' .emit OP_END;
1125
1126 /*
1127 <for_rest_statement> ::= <conditionopt> ";"
1128 | <conditionopt> ";" <expression>
1129 */
1130 for_rest_statement
1131 conditionopt .and semicolon .and for_rest_statement_1;
1132 for_rest_statement_1
1133 for_rest_statement_2 .or .true .emit OP_PUSH_VOID .emit OP_END;
1134 for_rest_statement_2
1135 expression .and .true .emit OP_END;
1136
1137 /*
1138 <jump_statement> ::= "continue" ";"
1139 | "break" ";"
1140 | "return" ";"
1141 | "return" <expression> ";"
1142 | "discard" ";" // Fragment shader only.
1143 */
1144 jump_statement
1145 jump_statement_1 .or jump_statement_2 .or jump_statement_3 .or jump_statement_4 .or
1146 .if (shader_type == 1) jump_statement_5;
1147 jump_statement_1
1148 "continue" .and semicolon .emit OP_CONTINUE;
1149 jump_statement_2
1150 "break" .and semicolon .emit OP_BREAK;
1151 jump_statement_3
1152 "return" .emit OP_RETURN .and optional_space .and expression .and semicolon .emit OP_END;
1153 jump_statement_4
1154 "return" .emit OP_RETURN .and semicolon .emit OP_PUSH_VOID .emit OP_END;
1155 jump_statement_5
1156 "discard" .and semicolon .emit OP_DISCARD;
1157
1158 /*
1159 <__asm_statement> ::= "__asm" <identifier> <asm_arguments> ";"
1160
1161 note: this is an extension to the standard language specification - normally slang disallows
1162 __asm statements
1163 */
1164 __asm_statement
1165 "__asm" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END;
1166
1167 /*
1168 <asm_arguments> ::= <identifier>
1169 | <asm_arguments> "," <identifier>
1170
1171 note: this is an extension to the standard language specification - normally slang disallows
1172 __asm statements
1173 */
1174 asm_arguments
1175 variable_identifier .and .true .emit OP_END .and .loop asm_arguments_1;
1176 asm_arguments_1
1177 comma .and variable_identifier .and .true .emit OP_END;
1178
1179 /*
1180 <translation_unit> ::= <external_declaration>
1181 | <translation_unit> <external_declaration>
1182 */
1183 translation_unit
1184 optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and
1185 .loop external_declaration .and optional_space .and
1186 '\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL;
1187
1188 /*
1189 <external_declaration> ::= <function_definition>
1190 | <declaration>
1191 */
1192 external_declaration
1193 function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or
1194 declaration .emit EXTERNAL_DECLARATION;
1195
1196 /*
1197 <function_definition> :: <function_prototype> <compound_statement_no_new_scope>
1198 */
1199 function_definition
1200 function_prototype .and compound_statement_no_new_scope;
1201
1202 /* helper rulez, not part of the official language syntax */
1203
1204 digit_oct
1205 '0'-'7';
1206
1207 digit_dec
1208 '0'-'9';
1209
1210 digit_hex
1211 '0'-'9' .or 'A'-'F' .or 'a'-'f';
1212
1213 id_character_first
1214 'a'-'z' .or 'A'-'Z' .or '_';
1215
1216 id_character_next
1217 id_character_first .or digit_dec;
1218
1219 identifier
1220 id_character_first .emit * .and .loop id_character_next .emit * .and .true .emit '\0';
1221
1222 float
1223 float_1 .or float_2;
1224 float_1
1225 float_fractional_constant .and float_optional_exponent_part;
1226 float_2
1227 float_digit_sequence .and .true .emit '\0' .and float_exponent_part;
1228
1229 float_fractional_constant
1230 float_fractional_constant_1 .or float_fractional_constant_2 .or float_fractional_constant_3;
1231 float_fractional_constant_1
1232 float_digit_sequence .and '.' .and float_digit_sequence;
1233 float_fractional_constant_2
1234 float_digit_sequence .and '.' .and .true .emit '\0';
1235 float_fractional_constant_3
1236 '.' .emit '\0' .and float_digit_sequence;
1237
1238 float_optional_exponent_part
1239 float_exponent_part .or .true .emit '\0';
1240
1241 float_digit_sequence
1242 digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1243
1244 float_exponent_part
1245 float_exponent_part_1 .or float_exponent_part_2;
1246 float_exponent_part_1
1247 'e' .and float_optional_sign .and float_digit_sequence;
1248 float_exponent_part_2
1249 'E' .and float_optional_sign .and float_digit_sequence;
1250
1251 float_optional_sign
1252 float_sign .or .true;
1253
1254 float_sign
1255 '+' .or '-' .emit '-';
1256
1257 integer
1258 integer_hex .or integer_oct .or integer_dec;
1259
1260 integer_hex
1261 '0' .and integer_hex_1 .emit 0x10 .and digit_hex .emit * .and .loop digit_hex .emit * .and
1262 .true .emit '\0';
1263 integer_hex_1
1264 'x' .or 'X';
1265
1266 integer_oct
1267 '0' .emit 8 .emit * .and .loop digit_oct .emit * .and .true .emit '\0';
1268
1269 integer_dec
1270 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1271
1272 boolean
1273 "true" .emit 2 .emit '1' .emit '\0' .or
1274 "false" .emit 2 .emit '0' .emit '\0';
1275
1276 type_name
1277 identifier;
1278
1279 field_selection
1280 identifier;
1281
1282 floatconstant
1283 float .emit OP_PUSH_FLOAT;
1284
1285 intconstant
1286 integer .emit OP_PUSH_INT;
1287
1288 boolconstant
1289 boolean .emit OP_PUSH_BOOL;
1290
1291 optional_space
1292 .loop single_space;
1293
1294 space
1295 single_space .and .loop single_space;
1296
1297 single_space
1298 white_char .or c_style_comment_block .or cpp_style_comment_block;
1299
1300 white_char
1301 ' ' .or '\t' .or new_line .or '\v' .or '\f';
1302
1303 new_line
1304 cr_lf .or lf_cr .or '\n' .or '\r';
1305
1306 cr_lf
1307 '\r' .and '\n';
1308
1309 lf_cr
1310 '\n' .and '\r';
1311
1312 c_style_comment_block
1313 '/' .and '*' .and c_style_comment_rest;
1314
1315 c_style_comment_rest
1316 .loop c_style_comment_char_no_star .and c_style_comment_rest_1;
1317 c_style_comment_rest_1
1318 c_style_comment_end .or c_style_comment_rest_2;
1319 c_style_comment_rest_2
1320 '*' .and c_style_comment_rest;
1321
1322 c_style_comment_char_no_star
1323 '\x2B'-'\xFF' .or '\x01'-'\x29';
1324
1325 c_style_comment_end
1326 '*' .and '/';
1327
1328 cpp_style_comment_block
1329 '/' .and '/' .and cpp_style_comment_block_1;
1330 cpp_style_comment_block_1
1331 cpp_style_comment_block_2 .or cpp_style_comment_block_3;
1332 cpp_style_comment_block_2
1333 .loop cpp_style_comment_char .and new_line;
1334 cpp_style_comment_block_3
1335 .loop cpp_style_comment_char;
1336
1337 cpp_style_comment_char
1338 '\x0E'-'\xFF' .or '\x01'-'\x09' .or '\x0B'-'\x0C';
1339
1340 /* lexical rulez */
1341
1342 /*ampersand
1343 optional_space .and '&' .and optional_space;*/
1344
1345 ampersandampersand
1346 optional_space .and '&' .and '&' .and optional_space;
1347
1348 /*ampersandequals
1349 optional_space .and '&' .and '=' .and optional_space;*/
1350
1351 /*bar
1352 optional_space .and '|' .and optional_space;*/
1353
1354 barbar
1355 optional_space .and '|' .and '|' .and optional_space;
1356
1357 /*barequals
1358 optional_space .and '|' .and '=' .and optional_space;*/
1359
1360 bang
1361 optional_space .and '!' .and optional_space;
1362
1363 bangequals
1364 optional_space .and '!' .and '=' .and optional_space;
1365
1366 /*caret
1367 optional_space .and '^' .and optional_space;*/
1368
1369 caretcaret
1370 optional_space .and '^' .and '^' .and optional_space;
1371
1372 /*caretequals
1373 optional_space .and '^' .and '=' .and optional_space;*/
1374
1375 colon
1376 optional_space .and ':' .and optional_space;
1377
1378 comma
1379 optional_space .and ',' .and optional_space;
1380
1381 dot
1382 optional_space .and '.' .and optional_space;
1383
1384 equals
1385 optional_space .and '=' .and optional_space;
1386
1387 equalsequals
1388 optional_space .and '=' .and '=' .and optional_space;
1389
1390 greater
1391 optional_space .and '>' .and optional_space;
1392
1393 greaterequals
1394 optional_space .and '>' .and '=' .and optional_space;
1395
1396 /*greatergreater
1397 optional_space .and '>' .and '>' .and optional_space;*/
1398
1399 /*greatergreaterequals
1400 optional_space .and '>' .and '>' .and '=' .and optional_space;*/
1401
1402 lbrace
1403 optional_space .and '{' .and optional_space;
1404
1405 lbracket
1406 optional_space .and '[' .and optional_space;
1407
1408 less
1409 optional_space .and '<' .and optional_space;
1410
1411 lessequals
1412 optional_space .and '<' .and '=' .and optional_space;
1413
1414 /*lessless
1415 optional_space .and '<' .and '<' .and optional_space;*/
1416
1417 /*lesslessequals
1418 optional_space .and '<' .and '<' .and '=' .and optional_space;*/
1419
1420 lparen
1421 optional_space .and '(' .and optional_space;
1422
1423 minus
1424 optional_space .and '-' .and optional_space;
1425
1426 minusequals
1427 optional_space .and '-' .and '=' .and optional_space;
1428
1429 minusminus
1430 optional_space .and '-' .and '-' .and optional_space;
1431
1432 /*percent
1433 optional_space .and '%' .and optional_space;*/
1434
1435 /*percentequals
1436 optional_space .and '%' .and '=' .and optional_space;*/
1437
1438 plus
1439 optional_space .and '+' .and optional_space;
1440
1441 plusequals
1442 optional_space .and '+' .and '=' .and optional_space;
1443
1444 plusplus
1445 optional_space .and '+' .and '+' .and optional_space;
1446
1447 question
1448 optional_space .and '?' .and optional_space;
1449
1450 rbrace
1451 optional_space .and '}' .and optional_space;
1452
1453 rbracket
1454 optional_space .and ']' .and optional_space;
1455
1456 rparen
1457 optional_space .and ')' .and optional_space;
1458
1459 semicolon
1460 optional_space .and ';' .and optional_space;
1461
1462 slash
1463 optional_space .and '/' .and optional_space;
1464
1465 slashequals
1466 optional_space .and '/' .and '=' .and optional_space;
1467
1468 star
1469 optional_space .and '*' .and optional_space;
1470
1471 starequals
1472 optional_space .and '*' .and '=' .and optional_space;
1473
1474 /*tilde
1475 optional_space .and '~' .and optional_space;*/
1476
1477 /* string rulez - these are used internally by the parser when parsing quoted strings */
1478
1479 .string string_lexer;
1480
1481 string_lexer
1482 lex_first_identifier_character .and .loop lex_next_identifier_character;
1483
1484 lex_first_identifier_character
1485 'a'-'z' .or 'A'-'Z' .or '_';
1486
1487 lex_next_identifier_character
1488 'a'-'z' .or 'A'-'Z' .or '0'-'9' .or '_';
1489
1490 /* error rulez - these are used by error messages */
1491
1492 err_token
1493 '~' .or '`' .or '!' .or '@' .or '#' .or '$' .or '%' .or '^' .or '&' .or '*' .or '(' .or ')' .or
1494 '-' .or '+' .or '=' .or '|' .or '\\' .or '[' .or ']' .or '{' .or '}' .or ':' .or ';' .or '"' .or
1495 '\'' .or '<' .or ',' .or '>' .or '.' .or '/' .or '?' .or err_identifier;
1496
1497 err_identifier
1498 id_character_first .and .loop id_character_next;
1499