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