2 * Mesa 3-D graphics library
4 * Copyright (C) 2004-2006 Brian Paul All Rights Reserved.
5 * Copyright (C) 2008 VMware, Inc. All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
26 * \file slang_shader.syn
27 * slang vertex/fragment shader syntax
33 * syn2c slang_shader.syn > slang_shader_syn.h
35 * when modifying or extending this file, several things must be taken into
38 * - when adding new operators that were marked as reserved in the
39 * initial specification, one must only uncomment particular lines of
40 * code that refer to operators being added;
42 * - when adding new shader targets, one must reserve a new value for
43 * shader_type register and use it in .if constructs for symbols that
44 * are exclusive for that shader;
46 * - some symbols mimic output of other symbols - the best example is
47 * the "for" construct: expression "for (foo(); ; bar())" is seen as
48 * "for (foo(); true; bar())" by the output processor - hence, special
49 * care must be taken when rearranging output of essential symbols;
51 * - order of single-quoted tokens does matter in alternatives - so do not
52 * parse "<" operator before "<<" and "<<" before "<<=";
54 * - all double-quoted tokens are internally preprocessed to eliminate
55 * problems with parsing strings that are prefixes of other strings,
56 * like "sampler1D" and "sampler1DShadow";
59 .syntax translation_unit;
61 /* revision number - increment after each change affecting emitted output */
64 /* external declaration (or precision or invariant stmt) */
65 .emtcode EXTERNAL_NULL 0
66 .emtcode EXTERNAL_FUNCTION_DEFINITION 1
67 .emtcode EXTERNAL_DECLARATION 2
68 .emtcode DEFAULT_PRECISION 3
69 .emtcode INVARIANT_STMT 4
72 .emtcode PRECISION_DEFAULT 0
73 .emtcode PRECISION_LOW 1
74 .emtcode PRECISION_MEDIUM 2
75 .emtcode PRECISION_HIGH 3
78 .emtcode DECLARATION_FUNCTION_PROTOTYPE 1
79 .emtcode DECLARATION_INIT_DECLARATOR_LIST 2
82 .emtcode FUNCTION_ORDINARY 0
83 .emtcode FUNCTION_CONSTRUCTOR 1
84 .emtcode FUNCTION_OPERATOR 2
86 /* function call type */
87 .emtcode FUNCTION_CALL_NONARRAY 0
88 .emtcode FUNCTION_CALL_ARRAY 1
91 .emtcode OPERATOR_ADDASSIGN 1
92 .emtcode OPERATOR_SUBASSIGN 2
93 .emtcode OPERATOR_MULASSIGN 3
94 .emtcode OPERATOR_DIVASSIGN 4
95 /*.emtcode OPERATOR_MODASSIGN 5*/
96 /*.emtcode OPERATOR_LSHASSIGN 6*/
97 /*.emtcode OPERATOR_RSHASSIGN 7*/
98 /*.emtcode OPERATOR_ORASSIGN 8*/
99 /*.emtcode OPERATOR_XORASSIGN 9*/
100 /*.emtcode OPERATOR_ANDASSIGN 10*/
101 .emtcode OPERATOR_LOGICALXOR 11
102 /*.emtcode OPERATOR_BITOR 12*/
103 /*.emtcode OPERATOR_BITXOR 13*/
104 /*.emtcode OPERATOR_BITAND 14*/
105 .emtcode OPERATOR_LESS 15
106 .emtcode OPERATOR_GREATER 16
107 .emtcode OPERATOR_LESSEQUAL 17
108 .emtcode OPERATOR_GREATEREQUAL 18
109 /*.emtcode OPERATOR_LSHIFT 19*/
110 /*.emtcode OPERATOR_RSHIFT 20*/
111 .emtcode OPERATOR_MULTIPLY 21
112 .emtcode OPERATOR_DIVIDE 22
113 /*.emtcode OPERATOR_MODULUS 23*/
114 .emtcode OPERATOR_INCREMENT 24
115 .emtcode OPERATOR_DECREMENT 25
116 .emtcode OPERATOR_PLUS 26
117 .emtcode OPERATOR_MINUS 27
118 /*.emtcode OPERATOR_COMPLEMENT 28*/
119 .emtcode OPERATOR_NOT 29
121 /* init declarator list */
122 .emtcode DECLARATOR_NONE 0
123 .emtcode DECLARATOR_NEXT 1
125 /* variable declaration */
126 .emtcode VARIABLE_NONE 0
127 .emtcode VARIABLE_IDENTIFIER 1
128 .emtcode VARIABLE_INITIALIZER 2
129 .emtcode VARIABLE_ARRAY_EXPLICIT 3
130 .emtcode VARIABLE_ARRAY_UNKNOWN 4
133 .emtcode TYPE_QUALIFIER_NONE 0
134 .emtcode TYPE_QUALIFIER_CONST 1
135 .emtcode TYPE_QUALIFIER_ATTRIBUTE 2
136 .emtcode TYPE_QUALIFIER_VARYING 3
137 .emtcode TYPE_QUALIFIER_UNIFORM 4
138 .emtcode TYPE_QUALIFIER_FIXEDOUTPUT 5
139 .emtcode TYPE_QUALIFIER_FIXEDINPUT 6
141 /* invariant qualifier */
142 .emtcode TYPE_VARIANT 90
143 .emtcode TYPE_INVARIANT 91
145 /* centroid qualifier */
146 .emtcode TYPE_CENTER 95
147 .emtcode TYPE_CENTROID 96
150 .emtcode TYPE_SPECIFIER_VOID 0
151 .emtcode TYPE_SPECIFIER_BOOL 1
152 .emtcode TYPE_SPECIFIER_BVEC2 2
153 .emtcode TYPE_SPECIFIER_BVEC3 3
154 .emtcode TYPE_SPECIFIER_BVEC4 4
155 .emtcode TYPE_SPECIFIER_INT 5
156 .emtcode TYPE_SPECIFIER_IVEC2 6
157 .emtcode TYPE_SPECIFIER_IVEC3 7
158 .emtcode TYPE_SPECIFIER_IVEC4 8
159 .emtcode TYPE_SPECIFIER_FLOAT 9
160 .emtcode TYPE_SPECIFIER_VEC2 10
161 .emtcode TYPE_SPECIFIER_VEC3 11
162 .emtcode TYPE_SPECIFIER_VEC4 12
163 .emtcode TYPE_SPECIFIER_MAT2 13
164 .emtcode TYPE_SPECIFIER_MAT3 14
165 .emtcode TYPE_SPECIFIER_MAT4 15
166 .emtcode TYPE_SPECIFIER_SAMPLER1D 16
167 .emtcode TYPE_SPECIFIER_SAMPLER2D 17
168 .emtcode TYPE_SPECIFIER_SAMPLER3D 18
169 .emtcode TYPE_SPECIFIER_SAMPLERCUBE 19
170 .emtcode TYPE_SPECIFIER_SAMPLER1DSHADOW 20
171 .emtcode TYPE_SPECIFIER_SAMPLER2DSHADOW 21
172 .emtcode TYPE_SPECIFIER_SAMPLER2DRECT 22
173 .emtcode TYPE_SPECIFIER_SAMPLER2DRECTSHADOW 23
174 .emtcode TYPE_SPECIFIER_STRUCT 24
175 .emtcode TYPE_SPECIFIER_TYPENAME 25
178 .emtcode TYPE_SPECIFIER_MAT23 26
179 .emtcode TYPE_SPECIFIER_MAT32 27
180 .emtcode TYPE_SPECIFIER_MAT24 28
181 .emtcode TYPE_SPECIFIER_MAT42 29
182 .emtcode TYPE_SPECIFIER_MAT34 30
183 .emtcode TYPE_SPECIFIER_MAT43 31
185 /* type specifier array */
186 .emtcode TYPE_SPECIFIER_NONARRAY 0
187 .emtcode TYPE_SPECIFIER_ARRAY 1
189 /* structure field */
190 .emtcode FIELD_NONE 0
191 .emtcode FIELD_NEXT 1
192 .emtcode FIELD_ARRAY 2
196 .emtcode OP_BLOCK_BEGIN_NO_NEW_SCOPE 1
197 .emtcode OP_BLOCK_BEGIN_NEW_SCOPE 2
198 .emtcode OP_DECLARE 3
201 .emtcode OP_CONTINUE 6
202 .emtcode OP_DISCARD 7
204 .emtcode OP_EXPRESSION 9
209 .emtcode OP_PUSH_VOID 14
210 .emtcode OP_PUSH_BOOL 15
211 .emtcode OP_PUSH_INT 16
212 .emtcode OP_PUSH_FLOAT 17
213 .emtcode OP_PUSH_IDENTIFIER 18
214 .emtcode OP_SEQUENCE 19
215 .emtcode OP_ASSIGN 20
216 .emtcode OP_ADDASSIGN 21
217 .emtcode OP_SUBASSIGN 22
218 .emtcode OP_MULASSIGN 23
219 .emtcode OP_DIVASSIGN 24
220 /*.emtcode OP_MODASSIGN 25*/
221 /*.emtcode OP_LSHASSIGN 26*/
222 /*.emtcode OP_RSHASSIGN 27*/
223 /*.emtcode OP_ORASSIGN 28*/
224 /*.emtcode OP_XORASSIGN 29*/
225 /*.emtcode OP_ANDASSIGN 30*/
226 .emtcode OP_SELECT 31
227 .emtcode OP_LOGICALOR 32
228 .emtcode OP_LOGICALXOR 33
229 .emtcode OP_LOGICALAND 34
230 /*.emtcode OP_BITOR 35*/
231 /*.emtcode OP_BITXOR 36*/
232 /*.emtcode OP_BITAND 37*/
234 .emtcode OP_NOTEQUAL 39
236 .emtcode OP_GREATER 41
237 .emtcode OP_LESSEQUAL 42
238 .emtcode OP_GREATEREQUAL 43
239 /*.emtcode OP_LSHIFT 44*/
240 /*.emtcode OP_RSHIFT 45*/
242 .emtcode OP_SUBTRACT 47
243 .emtcode OP_MULTIPLY 48
244 .emtcode OP_DIVIDE 49
245 /*.emtcode OP_MODULUS 50*/
246 .emtcode OP_PREINCREMENT 51
247 .emtcode OP_PREDECREMENT 52
250 /*.emtcode OP_COMPLEMENT 55*/
252 .emtcode OP_SUBSCRIPT 57
255 .emtcode OP_POSTINCREMENT 60
256 .emtcode OP_POSTDECREMENT 61
257 .emtcode OP_PRECISION 62
258 .emtcode OP_METHOD 63
260 /* parameter qualifier */
261 .emtcode PARAM_QUALIFIER_IN 0
262 .emtcode PARAM_QUALIFIER_OUT 1
263 .emtcode PARAM_QUALIFIER_INOUT 2
265 /* function parameter */
266 .emtcode PARAMETER_NONE 0
267 .emtcode PARAMETER_NEXT 1
269 /* function parameter array presence */
270 .emtcode PARAMETER_ARRAY_NOT_PRESENT 0
271 .emtcode PARAMETER_ARRAY_PRESENT 1
273 /* INVALID_EXTERNAL_DECLARATION seems to be reported when there's */
274 /* any syntax errors... */
275 .errtext INVALID_EXTERNAL_DECLARATION "2001: Syntax error."
276 .errtext INVALID_OPERATOR_OVERRIDE "2002: Invalid operator override."
277 .errtext LBRACE_EXPECTED "2003: '{' expected but '$err_token$' found."
278 .errtext LPAREN_EXPECTED "2004: '(' expected but '$err_token$' found."
279 .errtext RPAREN_EXPECTED "2005: ')' expected but '$err_token$' found."
280 .errtext INVALID_PRECISION "2006: Invalid precision specifier '$err_token$'."
281 .errtext INVALID_PRECISION_TYPE "2007: Invalid precision type '$err_token$'."
285 * tells whether the shader that is being parsed is a built-in shader or not
286 * 0 - normal behaviour
287 * 1 - accepts constructor and operator definitions and __asm statements
288 * the implementation will set it to 1 when compiling internal built-in shaders
290 .regbyte parsing_builtin 0
293 * holds the type of the shader being parsed; possible values are
297 * shader type is set by the caller before parsing
299 .regbyte shader_type 0
302 * <variable_identifier> ::= <identifier>
305 identifier .emit OP_PUSH_IDENTIFIER;
308 * <primary_expression> ::= <variable_identifier>
312 * | "(" <expression> ")"
315 floatconstant .or boolconstant .or intconstant .or variable_identifier .or primary_expression_1;
317 lparen .and expression .and rparen;
320 * <postfix_expression> ::= <primary_expression>
321 * | <postfix_expression> "[" <integer_expression> "]"
323 * | <postfix_expression> "." <field_selection>
324 * | <postfix_expression> "++"
325 * | <postfix_expression> "--"
328 postfix_expression_1 .and .loop postfix_expression_2;
330 function_call .or primary_expression;
332 postfix_expression_3 .or postfix_expression_4 .or
333 plusplus .emit OP_POSTINCREMENT .or
334 minusminus .emit OP_POSTDECREMENT;
336 lbracket .and integer_expression .and rbracket .emit OP_SUBSCRIPT;
338 dot .and field_selection .emit OP_FIELD;
341 * <integer_expression> ::= <expression>
347 * <function_call> ::= <function_call_generic>
350 function_call_or_method;
353 * <function_call_or_method> ::= <regular_function_call>
354 * | <postfix_expression> "." <function_call_generic>
356 function_call_or_method
357 regular_function_call .or method_call;
360 * <method_call> ::= <identifier> "." <function_call_generic>
363 identifier .emit OP_METHOD .and dot .and function_call_generic .and .true .emit OP_END;
366 * <regular_function_call> ::= <function_call_generic>
368 regular_function_call
369 function_call_generic .emit OP_CALL .and .true .emit OP_END;
372 * <function_call_generic> ::= <function_call_header_with_parameters> ")"
373 * | <function_call_header_no_parameters> ")"
375 function_call_generic
376 function_call_generic_1 .or function_call_generic_2;
377 function_call_generic_1
378 function_call_header_with_parameters .and rparen .error RPAREN_EXPECTED;
379 function_call_generic_2
380 function_call_header_no_parameters .and rparen .error RPAREN_EXPECTED;
383 * <function_call_header_no_parameters>::= <function_call_header> "void"
384 * | <function_call_header>
386 function_call_header_no_parameters
387 function_call_header .and function_call_header_no_parameters_1;
388 function_call_header_no_parameters_1
392 * <function_call_header_with_parameters> ::= <function_call_header> <assignment_expression>
393 * | <function_call_header_with_parameters> "," <assignment_expression>
395 function_call_header_with_parameters
396 function_call_header .and assignment_expression .and .true .emit OP_END .and
397 .loop function_call_header_with_parameters_1;
398 function_call_header_with_parameters_1
399 comma .and assignment_expression .and .true .emit OP_END;
402 * <function_call_header> ::= <function_identifier> "("
405 function_identifier .and lparen;
408 * <function_identifier> ::= <constructor_identifier>
412 * note: <constructor_identifier> and <type_specifier> have been deleted
415 identifier .and function_identifier_opt_array;
416 function_identifier_opt_array
417 function_identifier_array .emit FUNCTION_CALL_ARRAY .or
418 .true .emit FUNCTION_CALL_NONARRAY;
419 function_identifier_array
420 lbracket .and constant_expression .and rbracket;
423 * <unary_expression> ::= <postfix_expression>
424 * | "++" <unary_expression>
425 * | "--" <unary_expression>
426 * | <unary_operator> <unary_expression>
428 * <unary_operator> ::= "+"
434 postfix_expression .or unary_expression_1 .or unary_expression_2 .or unary_expression_3 .or
435 unary_expression_4 .or unary_expression_5/* .or unary_expression_6*/;
437 plusplus .and unary_expression .and .true .emit OP_PREINCREMENT;
439 minusminus .and unary_expression .and .true .emit OP_PREDECREMENT;
441 plus .and unary_expression .and .true .emit OP_PLUS;
443 minus .and unary_expression .and .true .emit OP_MINUS;
445 bang .and unary_expression .and .true .emit OP_NOT;
447 tilde .and unary_expression .and .true .emit OP_COMPLEMENT;*/
450 * <multiplicative_expression> ::= <unary_expression>
451 * | <multiplicative_expression> "*" <unary_expression>
452 * | <multiplicative_expression> "/" <unary_expression>
453 * | <multiplicative_expression> "%" <unary_expression> // reserved
455 multiplicative_expression
456 unary_expression .and .loop multiplicative_expression_1;
457 multiplicative_expression_1
458 multiplicative_expression_2 .or multiplicative_expression_3/* .or multiplicative_expression_4*/;
459 multiplicative_expression_2
460 star .and unary_expression .and .true .emit OP_MULTIPLY;
461 multiplicative_expression_3
462 slash .and unary_expression .and .true .emit OP_DIVIDE;
463 /*multiplicative_expression_4
464 percent .and unary_expression .and .true .emit OP_MODULUS;*/
467 * <additive_expression> ::= <multiplicative_expression>
468 * | <additive_expression> "+" <multiplicative_expression>
469 * | <additive_expression> "-" <multiplicative_expression>
472 multiplicative_expression .and .loop additive_expression_1;
473 additive_expression_1
474 additive_expression_2 .or additive_expression_3;
475 additive_expression_2
476 plus .and multiplicative_expression .and .true .emit OP_ADD;
477 additive_expression_3
478 minus .and multiplicative_expression .and .true .emit OP_SUBTRACT;
481 * <shift_expression> ::= <additive_expression>
482 * | <shift_expression> "<<" <additive_expression> // reserved
483 * | <shift_expression> ">>" <additive_expression> // reserved
486 additive_expression/* .and .loop shift_expression_1*/;
488 shift_expression_2 .or shift_expression_3;*/
490 lessless .and additive_expression .and .true .emit OP_LSHIFT;*/
492 greatergreater .and additive_expression .and .true .emit OP_RSHIFT;*/
495 * <relational_expression> ::= <shift_expression>
496 * | <relational_expression> "<" <shift_expression>
497 * | <relational_expression> ">" <shift_expression>
498 * | <relational_expression> "<=" <shift_expression>
499 * | <relational_expression> ">=" <shift_expression>
501 relational_expression
502 shift_expression .and .loop relational_expression_1;
503 relational_expression_1
504 relational_expression_2 .or relational_expression_3 .or relational_expression_4 .or
505 relational_expression_5;
506 relational_expression_2
507 lessequals .and shift_expression .and .true .emit OP_LESSEQUAL;
508 relational_expression_3
509 greaterequals .and shift_expression .and .true .emit OP_GREATEREQUAL;
510 relational_expression_4
511 less .and shift_expression .and .true .emit OP_LESS;
512 relational_expression_5
513 greater .and shift_expression .and .true .emit OP_GREATER;
516 * <equality_expression> ::= <relational_expression>
517 * | <equality_expression> "==" <relational_expression>
518 * | <equality_expression> "!=" <relational_expression>
521 relational_expression .and .loop equality_expression_1;
522 equality_expression_1
523 equality_expression_2 .or equality_expression_3;
524 equality_expression_2
525 equalsequals .and relational_expression .and .true .emit OP_EQUAL;
526 equality_expression_3
527 bangequals .and relational_expression .and .true .emit OP_NOTEQUAL;
530 * <and_expression> ::= <equality_expression>
531 * | <and_expression> "&" <equality_expression> // reserved
534 equality_expression/* .and .loop and_expression_1*/;
536 ampersand .and equality_expression .and .true .emit OP_BITAND;*/
539 * <exclusive_or_expression> ::= <and_expression>
540 * | <exclusive_or_expression> "^" <and_expression> // reserved
542 exclusive_or_expression
543 and_expression/* .and .loop exclusive_or_expression_1*/;
544 /*exclusive_or_expression_1
545 caret .and and_expression .and .true .emit OP_BITXOR;*/
548 * <inclusive_or_expression> ::= <exclusive_or_expression>
549 * | <inclusive_or_expression> "|" <exclusive_or_expression> // reserved
551 inclusive_or_expression
552 exclusive_or_expression/* .and .loop inclusive_or_expression_1*/;
553 /*inclusive_or_expression_1
554 bar .and exclusive_or_expression .and .true .emit OP_BITOR;*/
557 * <logical_and_expression> ::= <inclusive_or_expression>
558 * | <logical_and_expression> "&&" <inclusive_or_expression>
560 logical_and_expression
561 inclusive_or_expression .and .loop logical_and_expression_1;
562 logical_and_expression_1
563 ampersandampersand .and inclusive_or_expression .and .true .emit OP_LOGICALAND;
566 * <logical_xor_expression> ::= <logical_and_expression>
567 * | <logical_xor_expression> "^^" <logical_and_expression>
569 logical_xor_expression
570 logical_and_expression .and .loop logical_xor_expression_1;
571 logical_xor_expression_1
572 caretcaret .and logical_and_expression .and .true .emit OP_LOGICALXOR;
575 * <logical_or_expression> ::= <logical_xor_expression>
576 * | <logical_or_expression> "||" <logical_xor_expression>
578 logical_or_expression
579 logical_xor_expression .and .loop logical_or_expression_1;
580 logical_or_expression_1
581 barbar .and logical_xor_expression .and .true .emit OP_LOGICALOR;
584 * <conditional_expression> ::= <logical_or_expression>
585 * | <logical_or_expression> "?" <expression> ":" <conditional_expression>
587 conditional_expression
588 logical_or_expression .and .loop conditional_expression_1;
589 conditional_expression_1
590 question .and expression .and colon .and conditional_expression .and .true .emit OP_SELECT;
593 * <assignment_expression> ::= <conditional_expression>
594 * | <unary_expression> <assignment_operator> <assignment_expression>
596 * <assignment_operator> ::= "="
602 * | "<<=" // reserved
603 * | ">>=" // reserved
608 assignment_expression
609 assignment_expression_1 .or assignment_expression_2 .or assignment_expression_3 .or
610 assignment_expression_4 .or assignment_expression_5/* .or assignment_expression_6 .or
611 assignment_expression_7 .or assignment_expression_8 .or assignment_expression_9 .or
612 assignment_expression_10 .or assignment_expression_11*/ .or conditional_expression;
613 assignment_expression_1
614 unary_expression .and equals .and assignment_expression .and .true .emit OP_ASSIGN;
615 assignment_expression_2
616 unary_expression .and starequals .and assignment_expression .and .true .emit OP_MULASSIGN;
617 assignment_expression_3
618 unary_expression .and slashequals .and assignment_expression .and .true .emit OP_DIVASSIGN;
619 assignment_expression_4
620 unary_expression .and plusequals .and assignment_expression .and .true .emit OP_ADDASSIGN;
621 assignment_expression_5
622 unary_expression .and minusequals .and assignment_expression .and .true .emit OP_SUBASSIGN;
623 /*assignment_expression_6
624 unary_expression .and percentequals .and assignment_expression .and .true .emit OP_MODASSIGN;*/
625 /*assignment_expression_7
626 unary_expression .and lesslessequals .and assignment_expression .and .true .emit OP_LSHASSIGN;*/
627 /*assignment_expression_8
628 unary_expression .and greatergreaterequals .and assignment_expression .and
629 .true .emit OP_RSHASSIGN;*/
630 /*assignment_expression_9
631 unary_expression .and ampersandequals .and assignment_expression .and .true .emit OP_ANDASSIGN;*/
632 /*assignment_expression_10
633 unary_expression .and caretequals .and assignment_expression .and .true .emit OP_XORASSIGN;*/
634 /*assignment_expression_11
635 unary_expression .and barequals .and assignment_expression .and .true .emit OP_ORASSIGN;*/
638 * <expression> ::= <assignment_expression>
639 * | <expression> "," <assignment_expression>
642 assignment_expression .and .loop expression_1;
644 comma .and assignment_expression .and .true .emit OP_SEQUENCE;
647 * <constant_expression> ::= <conditional_expression>
650 conditional_expression .and .true .emit OP_END;
653 * <declaration> ::= <function_prototype> ";"
654 * | <init_declarator_list> ";"
657 declaration_1 .or declaration_2;
659 function_prototype .emit DECLARATION_FUNCTION_PROTOTYPE .and semicolon;
661 init_declarator_list .emit DECLARATION_INIT_DECLARATOR_LIST .and semicolon;
664 * <function_prototype> ::= <function_header> "void" ")"
665 * | <function_declarator> ")"
668 function_prototype_1 .or function_prototype_2;
670 function_header .and "void" .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
672 function_declarator .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
675 * <function_declarator> ::= <function_header>
676 * | <function_header_with_parameters>
679 function_header_with_parameters .or function_header;
682 * <function_header_with_parameters> ::= <function_header> <parameter_declaration>
683 * | <function_header_with_parameters> ","
684 * <parameter_declaration>
686 function_header_with_parameters
687 function_header .and parameter_declaration .and .loop function_header_with_parameters_1;
688 function_header_with_parameters_1
689 comma .and parameter_declaration;
692 * <function_header> ::= <fully_specified_type> <identifier> "("
695 function_header_nospace .or function_header_space;
696 function_header_space
697 fully_specified_type_space .and space .and function_decl_identifier .and lparen;
698 function_header_nospace
699 fully_specified_type_nospace .and function_decl_identifier .and lparen;
702 * <function_decl_identifier> ::= "__constructor"
706 * note: this is an extension to the standard language specification.
707 * normally slang disallows operator and constructor prototypes and definitions
709 function_decl_identifier
710 .if (parsing_builtin != 0) __operator .emit FUNCTION_OPERATOR .or
711 .if (parsing_builtin != 0) "__constructor" .emit FUNCTION_CONSTRUCTOR .or
712 identifier .emit FUNCTION_ORDINARY;
715 * <__operator> ::= "__operator" <overriden_op>
717 * note: this is an extension to the standard language specification.
718 * normally slang disallows operator prototypes and definitions
721 "__operator" .and overriden_operator .error INVALID_OPERATOR_OVERRIDE;
724 * <overriden_op> ::= "="
730 * | "<<=" // reserved
731 * | ">>=" // reserved
757 * note: this is an extension to the standard language specification.
758 * normally slang disallows operator prototypes and definitions
761 plusplus .emit OPERATOR_INCREMENT .or
762 plusequals .emit OPERATOR_ADDASSIGN .or
763 plus .emit OPERATOR_PLUS .or
764 minusminus .emit OPERATOR_DECREMENT .or
765 minusequals .emit OPERATOR_SUBASSIGN .or
766 minus .emit OPERATOR_MINUS .or
767 bang .emit OPERATOR_NOT .or
768 starequals .emit OPERATOR_MULASSIGN .or
769 star .emit OPERATOR_MULTIPLY .or
770 slashequals .emit OPERATOR_DIVASSIGN .or
771 slash .emit OPERATOR_DIVIDE .or
772 lessequals .emit OPERATOR_LESSEQUAL .or
773 /*lesslessequals .emit OPERATOR_LSHASSIGN .or*/
774 /*lessless .emit OPERATOR_LSHIFT .or*/
775 less .emit OPERATOR_LESS .or
776 greaterequals .emit OPERATOR_GREATEREQUAL .or
777 /*greatergreaterequals .emit OPERATOR_RSHASSIGN .or*/
778 /*greatergreater .emit OPERATOR_RSHIFT .or*/
779 greater .emit OPERATOR_GREATER .or
780 /*percentequals .emit OPERATOR_MODASSIGN .or*/
781 /*percent .emit OPERATOR_MODULUS .or*/
782 /*ampersandequals .emit OPERATOR_ANDASSIGN */
783 /*ampersand .emit OPERATOR_BITAND .or*/
784 /*barequals .emit OPERATOR_ORASSIGN .or*/
785 /*bar .emit OPERATOR_BITOR .or*/
786 /*tilde .emit OPERATOR_COMPLEMENT .or*/
787 /*caretequals .emit OPERATOR_XORASSIGN .or*/
788 caretcaret .emit OPERATOR_LOGICALXOR /*.or
789 caret .emit OPERATOR_BITXOR*/;
792 * <parameter_declarator> ::= <type_specifier> <identifier>
793 * | <type_specifier> <identifier> "[" <constant_expression> "]"
796 parameter_declarator_nospace .or parameter_declarator_space;
797 parameter_declarator_nospace
798 type_specifier_nospace .and identifier .and parameter_declarator_1;
799 parameter_declarator_space
800 type_specifier_space .and space .and identifier .and parameter_declarator_1;
801 parameter_declarator_1
802 parameter_declarator_2 .emit PARAMETER_ARRAY_PRESENT .or
803 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
804 parameter_declarator_2
805 lbracket .and constant_expression .and rbracket;
808 * <parameter_declaration> ::= <type_qualifier> <parameter_qualifier>
809 * <precision> <parameter_declarator>
810 * | <type_qualifier> <parameter_qualifier>
811 * <precision> <parameter_type_specifier>
812 * | <type_qualifier> <parameter_qualifier>
813 * <parameter_declarator>
814 * | <type_qualifier> <parameter_qualifier>
815 * <parameter_type_specifier>
816 * | <parameter_qualifier> <precision>
817 * <parameter_declarator>
818 * | <parameter_qualifier> <precision>
819 * <parameter_type_specifier>
820 * | <parameter_qualifier> <parameter_declarator>
821 * | <parameter_qualifier> <parameter_type_specifier>
823 parameter_declaration
824 parameter_declaration_1 .emit PARAMETER_NEXT;
825 parameter_declaration_1
826 parameter_declaration_2 .or parameter_declaration_3;
827 parameter_declaration_2
828 type_qualifier .and space .and parameter_qualifier .and parameter_declaration_4;
829 parameter_declaration_3
830 parameter_qualifier .emit TYPE_QUALIFIER_NONE .and parameter_declaration_4;
831 parameter_declaration_4
832 parameter_declaration_optprec .and parameter_declaration_rest;
833 parameter_declaration_optprec
834 parameter_declaration_prec .or .true .emit PRECISION_DEFAULT;
835 parameter_declaration_prec
836 precision .and space;
837 parameter_declaration_rest
838 parameter_declarator .or parameter_type_specifier;
841 * <parameter_qualifier> ::= "in"
847 parameter_qualifier_1 .or .true .emit PARAM_QUALIFIER_IN;
848 parameter_qualifier_1
849 parameter_qualifier_2 .and space;
850 parameter_qualifier_2
851 "in" .emit PARAM_QUALIFIER_IN .or
852 "out" .emit PARAM_QUALIFIER_OUT .or
853 "inout" .emit PARAM_QUALIFIER_INOUT;
856 * <parameter_type_specifier> ::= <type_specifier>
857 * | <type_specifier> "[" <constant_expression> "]"
859 parameter_type_specifier
860 parameter_type_specifier_1 .and .true .emit '\0' .and parameter_type_specifier_2;
861 parameter_type_specifier_1
862 type_specifier_nospace .or type_specifier_space;
863 parameter_type_specifier_2
864 parameter_type_specifier_3 .emit PARAMETER_ARRAY_PRESENT .or
865 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
866 parameter_type_specifier_3
867 lbracket .and constant_expression .and rbracket;
870 * <init_declarator_list> ::= <single_declaration>
871 * | <init_declarator_list> "," <identifier>
872 * | <init_declarator_list> "," <identifier> "[" "]"
873 * | <init_declarator_list> "," <identifier> "[" <constant_expression> "]"
874 * | <init_declarator_list> "," <identifier> "=" <initializer>
877 single_declaration .and .loop init_declarator_list_1 .emit DECLARATOR_NEXT .and
878 .true .emit DECLARATOR_NONE;
879 init_declarator_list_1
880 comma .and identifier .emit VARIABLE_IDENTIFIER .and init_declarator_list_2;
881 init_declarator_list_2
882 init_declarator_list_3 .or init_declarator_list_4 .or .true .emit VARIABLE_NONE;
883 init_declarator_list_3
884 equals .and initializer .emit VARIABLE_INITIALIZER;
885 init_declarator_list_4
886 lbracket .and init_declarator_list_5 .and rbracket;
887 init_declarator_list_5
888 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
891 * <single_declaration> ::= <fully_specified_type>
892 * | <fully_specified_type> <identifier>
893 * | <fully_specified_type> <identifier> "[" "]"
894 * | <fully_specified_type> <identifier> "[" <constant_expression> "]"
895 * | <fully_specified_type> <identifier> "=" <initializer>
898 single_declaration_nospace .or single_declaration_space;
899 single_declaration_space
900 fully_specified_type_space .and single_declaration_space_1;
901 single_declaration_nospace
902 fully_specified_type_nospace .and single_declaration_nospace_1;
903 single_declaration_space_1
904 single_declaration_space_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
905 single_declaration_nospace_1
906 single_declaration_nospace_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
907 single_declaration_space_2
908 space .and identifier .and single_declaration_3;
909 single_declaration_nospace_2
910 identifier .and single_declaration_3;
912 single_declaration_4 .or single_declaration_5 .or .true .emit VARIABLE_NONE;
914 equals .and initializer .emit VARIABLE_INITIALIZER;
916 lbracket .and single_declaration_6 .and rbracket;
918 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
921 * <fully_specified_type> ::= <opt_invariant> <opt_centroid> <opt_qualifer> <opt_precision> <type_specifier>
923 * Example: "invariant varying highp vec3"
925 fully_specified_type_space
926 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_space;
927 fully_specified_type_nospace
928 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_nospace;
929 fully_specified_type_optinvariant
930 fully_specified_type_invariant .or .true .emit TYPE_VARIANT;
931 fully_specified_type_invariant
932 invariant_qualifier .and space;
933 fully_specified_type_optcentroid
934 fully_specified_type_centroid .or .true .emit TYPE_CENTER;
935 fully_specified_type_centroid
936 centroid_qualifier .and space;
937 fully_specified_type_optqual
938 fully_specified_type_qual .or .true .emit TYPE_QUALIFIER_NONE;
939 fully_specified_type_qual
940 type_qualifier .and space;
941 fully_specified_type_optprec
942 fully_specified_type_prec .or .true .emit PRECISION_DEFAULT;
943 fully_specified_type_prec
944 precision .and space;
947 * <invariant_qualifier> ::= "invariant"
950 "invariant" .emit TYPE_INVARIANT;
953 "centroid" .emit TYPE_CENTROID;
957 * <type_qualifier> ::= "const"
958 * | "attribute" // Vertex only.
964 * note: this is an extension to the standard language specification,
965 * normally slang disallows __fixed_output and __fixed_input type qualifiers
968 "const" .emit TYPE_QUALIFIER_CONST .or
969 .if (shader_type == 2) "attribute" .emit TYPE_QUALIFIER_ATTRIBUTE .or
970 "varying" .emit TYPE_QUALIFIER_VARYING .or
971 "uniform" .emit TYPE_QUALIFIER_UNIFORM .or
972 .if (parsing_builtin != 0) "__fixed_output" .emit TYPE_QUALIFIER_FIXEDOUTPUT .or
973 .if (parsing_builtin != 0) "__fixed_input" .emit TYPE_QUALIFIER_FIXEDINPUT;
976 * <type_specifier_nonarray> ::= "void"
1002 * | "sampler1DShadow"
1003 * | "sampler2DShadow"
1005 * | "sampler2DRectShadow"
1006 * | <struct_specifier>
1009 type_specifier_nonarray_space
1010 "void" .emit TYPE_SPECIFIER_VOID .or
1011 "float" .emit TYPE_SPECIFIER_FLOAT .or
1012 "int" .emit TYPE_SPECIFIER_INT .or
1013 "bool" .emit TYPE_SPECIFIER_BOOL .or
1014 "vec2" .emit TYPE_SPECIFIER_VEC2 .or
1015 "vec3" .emit TYPE_SPECIFIER_VEC3 .or
1016 "vec4" .emit TYPE_SPECIFIER_VEC4 .or
1017 "bvec2" .emit TYPE_SPECIFIER_BVEC2 .or
1018 "bvec3" .emit TYPE_SPECIFIER_BVEC3 .or
1019 "bvec4" .emit TYPE_SPECIFIER_BVEC4 .or
1020 "ivec2" .emit TYPE_SPECIFIER_IVEC2 .or
1021 "ivec3" .emit TYPE_SPECIFIER_IVEC3 .or
1022 "ivec4" .emit TYPE_SPECIFIER_IVEC4 .or
1023 "mat2" .emit TYPE_SPECIFIER_MAT2 .or
1024 "mat3" .emit TYPE_SPECIFIER_MAT3 .or
1025 "mat4" .emit TYPE_SPECIFIER_MAT4 .or
1026 "mat2x3" .emit TYPE_SPECIFIER_MAT23 .or
1027 "mat3x2" .emit TYPE_SPECIFIER_MAT32 .or
1028 "mat2x4" .emit TYPE_SPECIFIER_MAT24 .or
1029 "mat4x2" .emit TYPE_SPECIFIER_MAT42 .or
1030 "mat3x4" .emit TYPE_SPECIFIER_MAT34 .or
1031 "mat4x3" .emit TYPE_SPECIFIER_MAT43 .or
1032 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1033 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1034 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1035 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1036 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1037 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1038 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1039 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW .or
1040 type_name .emit TYPE_SPECIFIER_TYPENAME;
1041 type_specifier_nonarray_nospace
1042 struct_specifier .emit TYPE_SPECIFIER_STRUCT;
1043 type_specifier_nonarray
1044 type_specifier_nonarray_nospace .or type_specifier_nonarray_space;
1047 * <type_specifier> ::= <type_specifier_nonarray>
1048 * | <type_specifier_nonarray> "[" <constant_expression> "]"
1050 type_specifier_space
1051 type_specifier_nonarray_space .and .true .emit TYPE_SPECIFIER_NONARRAY;
1052 type_specifier_nospace
1053 type_specifier_nospace_array .or type_specifier_nospace_1;
1054 type_specifier_nospace_1
1055 type_specifier_nonarray_nospace .and .true .emit TYPE_SPECIFIER_NONARRAY;
1056 type_specifier_nospace_array
1057 type_specifier_nonarray .and lbracket .emit TYPE_SPECIFIER_ARRAY .and constant_expression .and rbracket;
1060 * <struct_specifier> ::= "struct" <identifier> "{" <struct_declaration_list> "}"
1061 * | "struct" "{" <struct_declaration_list> "}"
1064 "struct" .and struct_specifier_1 .and optional_space .and lbrace .error LBRACE_EXPECTED .and
1065 struct_declaration_list .and rbrace .emit FIELD_NONE;
1067 struct_specifier_2 .or .true .emit '\0';
1069 space .and identifier;
1072 * <struct_declaration_list> ::= <struct_declaration>
1073 * | <struct_declaration_list> <struct_declaration>
1075 struct_declaration_list
1076 struct_declaration .and .loop struct_declaration .emit FIELD_NEXT;
1079 * <struct_declaration> ::= <type_specifier> <struct_declarator_list> ";"
1082 struct_declaration_nospace .or struct_declaration_space;
1083 struct_declaration_space
1084 type_specifier_space .and space .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1085 struct_declaration_nospace
1086 type_specifier_nospace .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1089 * <struct_declarator_list> ::= <struct_declarator>
1090 * | <struct_declarator_list> "," <struct_declarator>
1092 struct_declarator_list
1093 struct_declarator .and .loop struct_declarator_list_1 .emit FIELD_NEXT;
1094 struct_declarator_list_1
1095 comma .and struct_declarator;
1098 * <struct_declarator> ::= <identifier>
1099 * | <identifier> "[" <constant_expression> "]"
1102 identifier .and struct_declarator_1;
1104 struct_declarator_2 .emit FIELD_ARRAY .or .true .emit FIELD_NONE;
1106 lbracket .and constant_expression .and rbracket;
1109 * <initializer> ::= <assignment_expression>
1112 assignment_expression .and .true .emit OP_END;
1115 * <declaration_statement> ::= <declaration>
1117 declaration_statement
1121 * <statement> ::= <compound_statement>
1122 * | <simple_statement>
1125 compound_statement .or simple_statement;
1127 compound_statement .or statement_space_1;
1129 space .and simple_statement;
1132 * <simple_statement> ::= <__asm_statement>
1133 * | <selection_statement>
1134 * | <iteration_statement>
1135 * | <jump_statement>
1136 * | <expression_statement>
1137 * | <declaration_statement>
1139 * note: this is an extension to the standard language specification.
1140 * normally slang disallows use of __asm statements
1143 .if (parsing_builtin != 0) __asm_statement .emit OP_ASM .or
1144 selection_statement .or
1145 iteration_statement .or
1146 precision_stmt .emit OP_PRECISION .or
1148 expression_statement .emit OP_EXPRESSION .or
1149 declaration_statement .emit OP_DECLARE;
1152 * <compound_statement> ::= "{" "}"
1153 * | "{" <statement_list> "}"
1156 compound_statement_1 .emit OP_BLOCK_BEGIN_NEW_SCOPE .and .true .emit OP_END;
1157 compound_statement_1
1158 compound_statement_2 .or compound_statement_3;
1159 compound_statement_2
1161 compound_statement_3
1162 lbrace .and statement_list .and rbrace;
1165 * <statement_no_new_scope> ::= <compound_statement_no_new_scope>
1166 * | <simple_statement>
1168 statement_no_new_scope
1169 compound_statement_no_new_scope .or simple_statement;
1172 * <compound_statement_no_new_scope> ::= "{" "}"
1173 * | "{" <statement_list> "}"
1175 compound_statement_no_new_scope
1176 compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;
1177 compound_statement_no_new_scope_1
1178 compound_statement_no_new_scope_2 .or compound_statement_no_new_scope_3;
1179 compound_statement_no_new_scope_2
1181 compound_statement_no_new_scope_3
1182 lbrace .and statement_list .and rbrace;
1185 * <statement_list> ::= <statement>
1186 * | <statement_list> <statement>
1189 statement .and .loop statement;
1192 * <expression_statement> ::= ";"
1193 * | <expression> ";"
1195 expression_statement
1196 expression_statement_1 .or expression_statement_2;
1197 expression_statement_1
1198 semicolon .emit OP_PUSH_VOID .emit OP_END;
1199 expression_statement_2
1200 expression .and semicolon .emit OP_END;
1203 * <selection_statement> ::= "if" "(" <expression> ")" <selection_rest_statement>
1206 "if" .emit OP_IF .and lparen .error LPAREN_EXPECTED .and expression .and
1207 rparen .error RPAREN_EXPECTED .emit OP_END .and selection_rest_statement;
1210 * <selection_rest_statement> ::= <statement> "else" <statement>
1213 selection_rest_statement
1214 statement .and selection_rest_statement_1;
1215 selection_rest_statement_1
1216 selection_rest_statement_2 .or .true .emit OP_EXPRESSION .emit OP_PUSH_VOID .emit OP_END;
1217 selection_rest_statement_2
1218 "else" .and optional_space .and statement;
1221 * <condition> ::= <expression>
1222 * | <fully_specified_type> <identifier> "=" <initializer>
1224 * note: if <condition_1> is executed, the emit format must
1225 * match <declaration> emit format
1228 condition_1 .emit OP_DECLARE .emit DECLARATION_INIT_DECLARATOR_LIST .or
1229 condition_3 .emit OP_EXPRESSION;
1231 condition_1_nospace .or condition_1_space;
1233 fully_specified_type_nospace .and condition_2;
1235 fully_specified_type_space .and space .and condition_2;
1237 identifier .emit VARIABLE_IDENTIFIER .and equals .emit VARIABLE_INITIALIZER .and
1238 initializer .and .true .emit DECLARATOR_NONE;
1240 expression .and .true .emit OP_END;
1243 * <iteration_statement> ::= "while" "(" <condition> ")" <statement>
1244 * | "do" <statement> "while" "(" <expression> ")" ";"
1245 * | "for" "(" <for_init_statement> <for_rest_statement> ")"
1246 * <statement_no_new_scope>
1249 iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3;
1250 iteration_statement_1
1251 "while" .emit OP_WHILE .and lparen .error LPAREN_EXPECTED .and condition .and
1252 rparen .error RPAREN_EXPECTED .and statement;
1253 iteration_statement_2
1254 "do" .emit OP_DO .and statement_space .and "while" .and lparen .error LPAREN_EXPECTED .and
1255 expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;
1256 iteration_statement_3
1257 "for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and
1258 for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
1261 * <for_init_statement> ::= <expression_statement>
1262 * | <declaration_statement>
1265 expression_statement .emit OP_EXPRESSION .or declaration_statement .emit OP_DECLARE;
1268 * <conditionopt> ::= <condition>
1271 * note: <conditionopt> is used only by "for" statement.
1272 * if <condition> is ommitted, parser simulates default behaviour,
1273 * that is simulates "true" expression
1277 .true .emit OP_EXPRESSION .emit OP_PUSH_BOOL .emit 2 .emit '1' .emit '\0' .emit OP_END;
1280 * <for_rest_statement> ::= <conditionopt> ";"
1281 * | <conditionopt> ";" <expression>
1284 conditionopt .and semicolon .and for_rest_statement_1;
1285 for_rest_statement_1
1286 for_rest_statement_2 .or .true .emit OP_PUSH_VOID .emit OP_END;
1287 for_rest_statement_2
1288 expression .and .true .emit OP_END;
1291 * <jump_statement> ::= "continue" ";"
1294 * | "return" <expression> ";"
1295 * | "discard" ";" // Fragment shader only.
1298 jump_statement_1 .or jump_statement_2 .or jump_statement_3 .or jump_statement_4 .or
1299 .if (shader_type == 1) jump_statement_5;
1301 "continue" .and semicolon .emit OP_CONTINUE;
1303 "break" .and semicolon .emit OP_BREAK;
1305 "return" .emit OP_RETURN .and optional_space .and expression .and semicolon .emit OP_END;
1307 "return" .emit OP_RETURN .and semicolon .emit OP_PUSH_VOID .emit OP_END;
1309 "discard" .and semicolon .emit OP_DISCARD;
1312 * <__asm_statement> ::= "__asm" <identifier> <asm_arguments> ";"
1314 * note: this is an extension to the standard language specification.
1315 * normally slang disallows __asm statements
1318 "__asm" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END;
1321 * <asm_arguments> ::= <asm_argument>
1322 * | <asm_arguments> "," <asm_argument>
1324 * note: this is an extension to the standard language specification.
1325 * normally slang disallows __asm statements
1328 asm_argument .and .true .emit OP_END .and .loop asm_arguments_1;
1330 comma .and asm_argument .and .true .emit OP_END;
1333 * <asm_argument> ::= <variable_identifier>
1336 * note: this is an extension to the standard language specification.
1337 * normally slang disallows __asm statements
1341 variable_identifier .or
1345 variable_identifier .and dot .and field_selection .emit OP_FIELD;
1349 * <translation_unit> ::= <external_declaration>
1350 * | <translation_unit> <external_declaration>
1353 optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and
1354 .loop external_declaration .and optional_space .and
1355 '\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL;
1359 * <external_declaration> ::= <function_definition>
1362 external_declaration
1363 precision_stmt .emit DEFAULT_PRECISION .or
1364 function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or
1365 invariant_stmt .emit INVARIANT_STMT .or
1366 declaration .emit EXTERNAL_DECLARATION;
1370 * <precision_stmt> ::= "precision" <precision> <prectype>
1373 "precision" .and space .and precision .error INVALID_PRECISION .and space .and prectype .error INVALID_PRECISION_TYPE .and semicolon;
1376 * <precision> ::= "lowp"
1381 "lowp" .emit PRECISION_LOW .or
1382 "mediump" .emit PRECISION_MEDIUM .or
1383 "highp" .emit PRECISION_HIGH;
1386 * <prectype> ::= "int"
1388 * | "a sampler type"
1391 "int" .emit TYPE_SPECIFIER_INT .or
1392 "float" .emit TYPE_SPECIFIER_FLOAT .or
1393 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1394 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1395 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1396 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1397 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1398 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1399 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1400 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW;
1404 * <invariant_stmt> ::= "invariant" identifier;
1407 "invariant" .and space .and identifier .and semicolon;
1411 * <function_definition> :: <function_prototype> <compound_statement_no_new_scope>
1414 function_prototype .and compound_statement_no_new_scope;
1419 * helper rules, not part of the official language syntax
1429 '0'-'9' .or 'A'-'F' .or 'a'-'f';
1432 'a'-'z' .or 'A'-'Z' .or '_';
1435 id_character_first .or digit_dec;
1438 id_character_first .emit * .and .loop id_character_next .emit * .and .true .emit '\0';
1441 float_1 .or float_2 .or float_3;
1443 float_fractional_constant .and float_optional_exponent_part .and optional_f_suffix;
1445 float_digit_sequence .and .true .emit '\0' .and float_exponent_part .and optional_f_suffix;
1447 float_digit_sequence .and .true .emit '\0' .and 'f' .emit '\0';
1449 float_fractional_constant
1450 float_fractional_constant_1 .or float_fractional_constant_2 .or float_fractional_constant_3;
1451 float_fractional_constant_1
1452 float_digit_sequence .and '.' .and float_digit_sequence;
1453 float_fractional_constant_2
1454 float_digit_sequence .and '.' .and .true .emit '\0';
1455 float_fractional_constant_3
1456 '.' .emit '\0' .and float_digit_sequence;
1458 float_optional_exponent_part
1459 float_exponent_part .or .true .emit '\0';
1461 float_digit_sequence
1462 digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1465 float_exponent_part_1 .or float_exponent_part_2;
1466 float_exponent_part_1
1467 'e' .and float_optional_sign .and float_digit_sequence;
1468 float_exponent_part_2
1469 'E' .and float_optional_sign .and float_digit_sequence;
1472 float_sign .or .true;
1475 '+' .or '-' .emit '-';
1482 integer_hex .or integer_oct .or integer_dec;
1485 '0' .and integer_hex_1 .emit 0x10 .and digit_hex .emit * .and .loop digit_hex .emit * .and
1491 '0' .emit 8 .emit * .and .loop digit_oct .emit * .and .true .emit '\0';
1494 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1497 "true" .emit 2 .emit '1' .emit '\0' .or
1498 "false" .emit 2 .emit '0' .emit '\0';
1507 float .emit OP_PUSH_FLOAT;
1510 integer .emit OP_PUSH_INT;
1513 boolean .emit OP_PUSH_BOOL;
1519 single_space .and .loop single_space;
1522 white_char .or c_style_comment_block .or cpp_style_comment_block;
1525 ' ' .or '\t' .or new_line .or '\v' .or '\f';
1528 cr_lf .or lf_cr .or '\n' .or '\r';
1536 c_style_comment_block
1537 '/' .and '*' .and c_style_comment_rest;
1539 c_style_comment_rest
1540 .loop c_style_comment_char_no_star .and c_style_comment_rest_1;
1541 c_style_comment_rest_1
1542 c_style_comment_end .or c_style_comment_rest_2;
1543 c_style_comment_rest_2
1544 '*' .and c_style_comment_rest;
1546 c_style_comment_char_no_star
1547 '\x2B'-'\xFF' .or '\x01'-'\x29';
1552 cpp_style_comment_block
1553 '/' .and '/' .and cpp_style_comment_block_1;
1554 cpp_style_comment_block_1
1555 cpp_style_comment_block_2 .or cpp_style_comment_block_3;
1556 cpp_style_comment_block_2
1557 .loop cpp_style_comment_char .and new_line;
1558 cpp_style_comment_block_3
1559 .loop cpp_style_comment_char;
1561 cpp_style_comment_char
1562 '\x0E'-'\xFF' .or '\x01'-'\x09' .or '\x0B'-'\x0C';
1567 optional_space .and '&' .and optional_space;*/
1570 optional_space .and '&' .and '&' .and optional_space;
1573 optional_space .and '&' .and '=' .and optional_space;*/
1576 optional_space .and '|' .and optional_space;*/
1579 optional_space .and '|' .and '|' .and optional_space;
1582 optional_space .and '|' .and '=' .and optional_space;*/
1585 optional_space .and '!' .and optional_space;
1588 optional_space .and '!' .and '=' .and optional_space;
1591 optional_space .and '^' .and optional_space;*/
1594 optional_space .and '^' .and '^' .and optional_space;
1597 optional_space .and '^' .and '=' .and optional_space;*/
1600 optional_space .and ':' .and optional_space;
1603 optional_space .and ',' .and optional_space;
1606 optional_space .and '.' .and optional_space;
1609 optional_space .and '=' .and optional_space;
1612 optional_space .and '=' .and '=' .and optional_space;
1615 optional_space .and '>' .and optional_space;
1618 optional_space .and '>' .and '=' .and optional_space;
1621 optional_space .and '>' .and '>' .and optional_space;*/
1623 /*greatergreaterequals
1624 optional_space .and '>' .and '>' .and '=' .and optional_space;*/
1627 optional_space .and '{' .and optional_space;
1630 optional_space .and '[' .and optional_space;
1633 optional_space .and '<' .and optional_space;
1636 optional_space .and '<' .and '=' .and optional_space;
1639 optional_space .and '<' .and '<' .and optional_space;*/
1642 optional_space .and '<' .and '<' .and '=' .and optional_space;*/
1645 optional_space .and '(' .and optional_space;
1648 optional_space .and '-' .and optional_space;
1651 optional_space .and '-' .and '=' .and optional_space;
1654 optional_space .and '-' .and '-' .and optional_space;
1657 optional_space .and '%' .and optional_space;*/
1660 optional_space .and '%' .and '=' .and optional_space;*/
1663 optional_space .and '+' .and optional_space;
1666 optional_space .and '+' .and '=' .and optional_space;
1669 optional_space .and '+' .and '+' .and optional_space;
1672 optional_space .and '?' .and optional_space;
1675 optional_space .and '}' .and optional_space;
1678 optional_space .and ']' .and optional_space;
1681 optional_space .and ')' .and optional_space;
1684 optional_space .and ';' .and optional_space;
1687 optional_space .and '/' .and optional_space;
1690 optional_space .and '/' .and '=' .and optional_space;
1693 optional_space .and '*' .and optional_space;
1696 optional_space .and '*' .and '=' .and optional_space;
1699 optional_space .and '~' .and optional_space;*/
1701 /* string rules - these are used internally by the parser when parsing quoted strings */
1703 .string string_lexer;
1706 lex_first_identifier_character .and .loop lex_next_identifier_character;
1708 lex_first_identifier_character
1709 'a'-'z' .or 'A'-'Z' .or '_';
1711 lex_next_identifier_character
1712 'a'-'z' .or 'A'-'Z' .or '0'-'9' .or '_';
1714 /* error rules - these are used by error messages */
1717 '~' .or '`' .or '!' .or '@' .or '#' .or '$' .or '%' .or '^' .or '&' .or '*' .or '(' .or ')' .or
1718 '-' .or '+' .or '=' .or '|' .or '\\' .or '[' .or ']' .or '{' .or '}' .or ':' .or ';' .or '"' .or
1719 '\'' .or '<' .or ',' .or '>' .or '.' .or '/' .or '?' .or err_identifier;
1722 id_character_first .and .loop id_character_next;