2 * Mesa 3-D graphics library
5 * Copyright (C) 2004-2006 Brian Paul 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
87 .emtcode OPERATOR_ADDASSIGN 1
88 .emtcode OPERATOR_SUBASSIGN 2
89 .emtcode OPERATOR_MULASSIGN 3
90 .emtcode OPERATOR_DIVASSIGN 4
91 /*.emtcode OPERATOR_MODASSIGN 5*/
92 /*.emtcode OPERATOR_LSHASSIGN 6*/
93 /*.emtcode OPERATOR_RSHASSIGN 7*/
94 /*.emtcode OPERATOR_ORASSIGN 8*/
95 /*.emtcode OPERATOR_XORASSIGN 9*/
96 /*.emtcode OPERATOR_ANDASSIGN 10*/
97 .emtcode OPERATOR_LOGICALXOR 11
98 /*.emtcode OPERATOR_BITOR 12*/
99 /*.emtcode OPERATOR_BITXOR 13*/
100 /*.emtcode OPERATOR_BITAND 14*/
101 .emtcode OPERATOR_LESS 15
102 .emtcode OPERATOR_GREATER 16
103 .emtcode OPERATOR_LESSEQUAL 17
104 .emtcode OPERATOR_GREATEREQUAL 18
105 /*.emtcode OPERATOR_LSHIFT 19*/
106 /*.emtcode OPERATOR_RSHIFT 20*/
107 .emtcode OPERATOR_MULTIPLY 21
108 .emtcode OPERATOR_DIVIDE 22
109 /*.emtcode OPERATOR_MODULUS 23*/
110 .emtcode OPERATOR_INCREMENT 24
111 .emtcode OPERATOR_DECREMENT 25
112 .emtcode OPERATOR_PLUS 26
113 .emtcode OPERATOR_MINUS 27
114 /*.emtcode OPERATOR_COMPLEMENT 28*/
115 .emtcode OPERATOR_NOT 29
117 /* init declarator list */
118 .emtcode DECLARATOR_NONE 0
119 .emtcode DECLARATOR_NEXT 1
121 /* variable declaration */
122 .emtcode VARIABLE_NONE 0
123 .emtcode VARIABLE_IDENTIFIER 1
124 .emtcode VARIABLE_INITIALIZER 2
125 .emtcode VARIABLE_ARRAY_EXPLICIT 3
126 .emtcode VARIABLE_ARRAY_UNKNOWN 4
129 .emtcode TYPE_QUALIFIER_NONE 0
130 .emtcode TYPE_QUALIFIER_CONST 1
131 .emtcode TYPE_QUALIFIER_ATTRIBUTE 2
132 .emtcode TYPE_QUALIFIER_VARYING 3
133 .emtcode TYPE_QUALIFIER_UNIFORM 4
134 .emtcode TYPE_QUALIFIER_FIXEDOUTPUT 5
135 .emtcode TYPE_QUALIFIER_FIXEDINPUT 6
137 /* invariant qualifier */
138 .emtcode TYPE_VARIANT 90
139 .emtcode TYPE_INVARIANT 91
141 /* centroid qualifier */
142 .emtcode TYPE_CENTER 95
143 .emtcode TYPE_CENTROID 96
146 .emtcode TYPE_SPECIFIER_VOID 0
147 .emtcode TYPE_SPECIFIER_BOOL 1
148 .emtcode TYPE_SPECIFIER_BVEC2 2
149 .emtcode TYPE_SPECIFIER_BVEC3 3
150 .emtcode TYPE_SPECIFIER_BVEC4 4
151 .emtcode TYPE_SPECIFIER_INT 5
152 .emtcode TYPE_SPECIFIER_IVEC2 6
153 .emtcode TYPE_SPECIFIER_IVEC3 7
154 .emtcode TYPE_SPECIFIER_IVEC4 8
155 .emtcode TYPE_SPECIFIER_FLOAT 9
156 .emtcode TYPE_SPECIFIER_VEC2 10
157 .emtcode TYPE_SPECIFIER_VEC3 11
158 .emtcode TYPE_SPECIFIER_VEC4 12
159 .emtcode TYPE_SPECIFIER_MAT2 13
160 .emtcode TYPE_SPECIFIER_MAT3 14
161 .emtcode TYPE_SPECIFIER_MAT4 15
162 .emtcode TYPE_SPECIFIER_SAMPLER1D 16
163 .emtcode TYPE_SPECIFIER_SAMPLER2D 17
164 .emtcode TYPE_SPECIFIER_SAMPLER3D 18
165 .emtcode TYPE_SPECIFIER_SAMPLERCUBE 19
166 .emtcode TYPE_SPECIFIER_SAMPLER1DSHADOW 20
167 .emtcode TYPE_SPECIFIER_SAMPLER2DSHADOW 21
168 .emtcode TYPE_SPECIFIER_SAMPLER2DRECT 22
169 .emtcode TYPE_SPECIFIER_SAMPLER2DRECTSHADOW 23
170 .emtcode TYPE_SPECIFIER_STRUCT 24
171 .emtcode TYPE_SPECIFIER_TYPENAME 25
174 .emtcode TYPE_SPECIFIER_MAT23 26
175 .emtcode TYPE_SPECIFIER_MAT32 27
176 .emtcode TYPE_SPECIFIER_MAT24 28
177 .emtcode TYPE_SPECIFIER_MAT42 29
178 .emtcode TYPE_SPECIFIER_MAT34 30
179 .emtcode TYPE_SPECIFIER_MAT43 31
181 /* optional array size. Ex: "float[6] myarray;" */
182 .emtcode TYPE_ARRAY_SIZE 220
183 .emtcode TYPE_NO_ARRAY_SIZE 221
185 /* structure field */
186 .emtcode FIELD_NONE 0
187 .emtcode FIELD_NEXT 1
188 .emtcode FIELD_ARRAY 2
192 .emtcode OP_BLOCK_BEGIN_NO_NEW_SCOPE 1
193 .emtcode OP_BLOCK_BEGIN_NEW_SCOPE 2
194 .emtcode OP_DECLARE 3
197 .emtcode OP_CONTINUE 6
198 .emtcode OP_DISCARD 7
200 .emtcode OP_EXPRESSION 9
205 .emtcode OP_PUSH_VOID 14
206 .emtcode OP_PUSH_BOOL 15
207 .emtcode OP_PUSH_INT 16
208 .emtcode OP_PUSH_FLOAT 17
209 .emtcode OP_PUSH_IDENTIFIER 18
210 .emtcode OP_SEQUENCE 19
211 .emtcode OP_ASSIGN 20
212 .emtcode OP_ADDASSIGN 21
213 .emtcode OP_SUBASSIGN 22
214 .emtcode OP_MULASSIGN 23
215 .emtcode OP_DIVASSIGN 24
216 /*.emtcode OP_MODASSIGN 25*/
217 /*.emtcode OP_LSHASSIGN 26*/
218 /*.emtcode OP_RSHASSIGN 27*/
219 /*.emtcode OP_ORASSIGN 28*/
220 /*.emtcode OP_XORASSIGN 29*/
221 /*.emtcode OP_ANDASSIGN 30*/
222 .emtcode OP_SELECT 31
223 .emtcode OP_LOGICALOR 32
224 .emtcode OP_LOGICALXOR 33
225 .emtcode OP_LOGICALAND 34
226 /*.emtcode OP_BITOR 35*/
227 /*.emtcode OP_BITXOR 36*/
228 /*.emtcode OP_BITAND 37*/
230 .emtcode OP_NOTEQUAL 39
232 .emtcode OP_GREATER 41
233 .emtcode OP_LESSEQUAL 42
234 .emtcode OP_GREATEREQUAL 43
235 /*.emtcode OP_LSHIFT 44*/
236 /*.emtcode OP_RSHIFT 45*/
238 .emtcode OP_SUBTRACT 47
239 .emtcode OP_MULTIPLY 48
240 .emtcode OP_DIVIDE 49
241 /*.emtcode OP_MODULUS 50*/
242 .emtcode OP_PREINCREMENT 51
243 .emtcode OP_PREDECREMENT 52
246 /*.emtcode OP_COMPLEMENT 55*/
248 .emtcode OP_SUBSCRIPT 57
251 .emtcode OP_POSTINCREMENT 60
252 .emtcode OP_POSTDECREMENT 61
253 .emtcode OP_PRECISION 62
254 .emtcode OP_METHOD 63
256 /* parameter qualifier */
257 .emtcode PARAM_QUALIFIER_IN 0
258 .emtcode PARAM_QUALIFIER_OUT 1
259 .emtcode PARAM_QUALIFIER_INOUT 2
261 /* function parameter */
262 .emtcode PARAMETER_NONE 0
263 .emtcode PARAMETER_NEXT 1
265 /* function parameter array presence */
266 .emtcode PARAMETER_ARRAY_NOT_PRESENT 0
267 .emtcode PARAMETER_ARRAY_PRESENT 1
269 /* INVALID_EXTERNAL_DECLARATION seems to be reported when there's */
270 /* any syntax errors... */
271 .errtext INVALID_EXTERNAL_DECLARATION "2001: Syntax error."
272 .errtext INVALID_OPERATOR_OVERRIDE "2002: Invalid operator override."
273 .errtext LBRACE_EXPECTED "2003: '{' expected but '$err_token$' found."
274 .errtext LPAREN_EXPECTED "2004: '(' expected but '$err_token$' found."
275 .errtext RPAREN_EXPECTED "2005: ')' expected but '$err_token$' found."
276 .errtext INVALID_PRECISION "2006: Invalid precision specifier '$err_token$'."
277 .errtext INVALID_PRECISION_TYPE "2007: Invalid precision type '$err_token$'."
281 * tells whether the shader that is being parsed is a built-in shader or not
282 * 0 - normal behaviour
283 * 1 - accepts constructor and operator definitions and __asm statements
284 * the implementation will set it to 1 when compiling internal built-in shaders
286 .regbyte parsing_builtin 0
289 * holds the type of the shader being parsed; possible values are
293 * shader type is set by the caller before parsing
295 .regbyte shader_type 0
298 * <variable_identifier> ::= <identifier>
301 identifier .emit OP_PUSH_IDENTIFIER;
304 * <primary_expression> ::= <variable_identifier>
308 * | "(" <expression> ")"
311 floatconstant .or boolconstant .or intconstant .or variable_identifier .or primary_expression_1;
313 lparen .and expression .and rparen;
316 * <postfix_expression> ::= <primary_expression>
317 * | <postfix_expression> "[" <integer_expression> "]"
319 * | <postfix_expression> "." <field_selection>
320 * | <postfix_expression> "++"
321 * | <postfix_expression> "--"
324 postfix_expression_1 .and .loop postfix_expression_2;
326 function_call .or primary_expression;
328 postfix_expression_3 .or postfix_expression_4 .or
329 plusplus .emit OP_POSTINCREMENT .or
330 minusminus .emit OP_POSTDECREMENT;
332 lbracket .and integer_expression .and rbracket .emit OP_SUBSCRIPT;
334 dot .and field_selection .emit OP_FIELD;
337 * <integer_expression> ::= <expression>
343 * <function_call> ::= <function_call_generic>
346 function_call_or_method;
349 * <function_call_or_method> ::= <regular_function_call>
350 * | <postfix_expression> "." <function_call_generic>
352 function_call_or_method
353 regular_function_call .or method_call;
356 * <method_call> ::= <identifier> "." <function_call_generic>
359 identifier .emit OP_METHOD .and dot .and function_call_generic .and .true .emit OP_END;
362 * <regular_function_call> ::= <function_call_generic>
364 regular_function_call
365 function_call_generic .emit OP_CALL .and .true .emit OP_END;
368 * <function_call_generic> ::= <function_call_header_with_parameters> ")"
369 * | <function_call_header_no_parameters> ")"
371 function_call_generic
372 function_call_generic_1 .or function_call_generic_2;
373 function_call_generic_1
374 function_call_header_with_parameters .and rparen .error RPAREN_EXPECTED;
375 function_call_generic_2
376 function_call_header_no_parameters .and rparen .error RPAREN_EXPECTED;
379 * <function_call_header_no_parameters>::= <function_call_header> "void"
380 * | <function_call_header>
382 function_call_header_no_parameters
383 function_call_header .and function_call_header_no_parameters_1;
384 function_call_header_no_parameters_1
388 * <function_call_header_with_parameters> ::= <function_call_header> <assignment_expression>
389 * | <function_call_header_with_parameters> "," <assignment_expression>
391 function_call_header_with_parameters
392 function_call_header .and assignment_expression .and .true .emit OP_END .and
393 .loop function_call_header_with_parameters_1;
394 function_call_header_with_parameters_1
395 comma .and assignment_expression .and .true .emit OP_END;
398 * <function_call_header> ::= <function_identifier> "("
401 function_identifier .and lparen;
404 * <function_identifier> ::= <constructor_identifier>
407 * note: <constructor_identifier> has been deleted
413 * <unary_expression> ::= <postfix_expression>
414 * | "++" <unary_expression>
415 * | "--" <unary_expression>
416 * | <unary_operator> <unary_expression>
418 * <unary_operator> ::= "+"
424 postfix_expression .or unary_expression_1 .or unary_expression_2 .or unary_expression_3 .or
425 unary_expression_4 .or unary_expression_5/* .or unary_expression_6*/;
427 plusplus .and unary_expression .and .true .emit OP_PREINCREMENT;
429 minusminus .and unary_expression .and .true .emit OP_PREDECREMENT;
431 plus .and unary_expression .and .true .emit OP_PLUS;
433 minus .and unary_expression .and .true .emit OP_MINUS;
435 bang .and unary_expression .and .true .emit OP_NOT;
437 tilde .and unary_expression .and .true .emit OP_COMPLEMENT;*/
440 * <multiplicative_expression> ::= <unary_expression>
441 * | <multiplicative_expression> "*" <unary_expression>
442 * | <multiplicative_expression> "/" <unary_expression>
443 * | <multiplicative_expression> "%" <unary_expression> // reserved
445 multiplicative_expression
446 unary_expression .and .loop multiplicative_expression_1;
447 multiplicative_expression_1
448 multiplicative_expression_2 .or multiplicative_expression_3/* .or multiplicative_expression_4*/;
449 multiplicative_expression_2
450 star .and unary_expression .and .true .emit OP_MULTIPLY;
451 multiplicative_expression_3
452 slash .and unary_expression .and .true .emit OP_DIVIDE;
453 /*multiplicative_expression_4
454 percent .and unary_expression .and .true .emit OP_MODULUS;*/
457 * <additive_expression> ::= <multiplicative_expression>
458 * | <additive_expression> "+" <multiplicative_expression>
459 * | <additive_expression> "-" <multiplicative_expression>
462 multiplicative_expression .and .loop additive_expression_1;
463 additive_expression_1
464 additive_expression_2 .or additive_expression_3;
465 additive_expression_2
466 plus .and multiplicative_expression .and .true .emit OP_ADD;
467 additive_expression_3
468 minus .and multiplicative_expression .and .true .emit OP_SUBTRACT;
471 * <shift_expression> ::= <additive_expression>
472 * | <shift_expression> "<<" <additive_expression> // reserved
473 * | <shift_expression> ">>" <additive_expression> // reserved
476 additive_expression/* .and .loop shift_expression_1*/;
478 shift_expression_2 .or shift_expression_3;*/
480 lessless .and additive_expression .and .true .emit OP_LSHIFT;*/
482 greatergreater .and additive_expression .and .true .emit OP_RSHIFT;*/
485 * <relational_expression> ::= <shift_expression>
486 * | <relational_expression> "<" <shift_expression>
487 * | <relational_expression> ">" <shift_expression>
488 * | <relational_expression> "<=" <shift_expression>
489 * | <relational_expression> ">=" <shift_expression>
491 relational_expression
492 shift_expression .and .loop relational_expression_1;
493 relational_expression_1
494 relational_expression_2 .or relational_expression_3 .or relational_expression_4 .or
495 relational_expression_5;
496 relational_expression_2
497 lessequals .and shift_expression .and .true .emit OP_LESSEQUAL;
498 relational_expression_3
499 greaterequals .and shift_expression .and .true .emit OP_GREATEREQUAL;
500 relational_expression_4
501 less .and shift_expression .and .true .emit OP_LESS;
502 relational_expression_5
503 greater .and shift_expression .and .true .emit OP_GREATER;
506 * <equality_expression> ::= <relational_expression>
507 * | <equality_expression> "==" <relational_expression>
508 * | <equality_expression> "!=" <relational_expression>
511 relational_expression .and .loop equality_expression_1;
512 equality_expression_1
513 equality_expression_2 .or equality_expression_3;
514 equality_expression_2
515 equalsequals .and relational_expression .and .true .emit OP_EQUAL;
516 equality_expression_3
517 bangequals .and relational_expression .and .true .emit OP_NOTEQUAL;
520 * <and_expression> ::= <equality_expression>
521 * | <and_expression> "&" <equality_expression> // reserved
524 equality_expression/* .and .loop and_expression_1*/;
526 ampersand .and equality_expression .and .true .emit OP_BITAND;*/
529 * <exclusive_or_expression> ::= <and_expression>
530 * | <exclusive_or_expression> "^" <and_expression> // reserved
532 exclusive_or_expression
533 and_expression/* .and .loop exclusive_or_expression_1*/;
534 /*exclusive_or_expression_1
535 caret .and and_expression .and .true .emit OP_BITXOR;*/
538 * <inclusive_or_expression> ::= <exclusive_or_expression>
539 * | <inclusive_or_expression> "|" <exclusive_or_expression> // reserved
541 inclusive_or_expression
542 exclusive_or_expression/* .and .loop inclusive_or_expression_1*/;
543 /*inclusive_or_expression_1
544 bar .and exclusive_or_expression .and .true .emit OP_BITOR;*/
547 * <logical_and_expression> ::= <inclusive_or_expression>
548 * | <logical_and_expression> "&&" <inclusive_or_expression>
550 logical_and_expression
551 inclusive_or_expression .and .loop logical_and_expression_1;
552 logical_and_expression_1
553 ampersandampersand .and inclusive_or_expression .and .true .emit OP_LOGICALAND;
556 * <logical_xor_expression> ::= <logical_and_expression>
557 * | <logical_xor_expression> "^^" <logical_and_expression>
559 logical_xor_expression
560 logical_and_expression .and .loop logical_xor_expression_1;
561 logical_xor_expression_1
562 caretcaret .and logical_and_expression .and .true .emit OP_LOGICALXOR;
565 * <logical_or_expression> ::= <logical_xor_expression>
566 * | <logical_or_expression> "||" <logical_xor_expression>
568 logical_or_expression
569 logical_xor_expression .and .loop logical_or_expression_1;
570 logical_or_expression_1
571 barbar .and logical_xor_expression .and .true .emit OP_LOGICALOR;
574 * <conditional_expression> ::= <logical_or_expression>
575 * | <logical_or_expression> "?" <expression> ":" <conditional_expression>
577 conditional_expression
578 logical_or_expression .and .loop conditional_expression_1;
579 conditional_expression_1
580 question .and expression .and colon .and conditional_expression .and .true .emit OP_SELECT;
583 * <assignment_expression> ::= <conditional_expression>
584 * | <unary_expression> <assignment_operator> <assignment_expression>
586 * <assignment_operator> ::= "="
592 * | "<<=" // reserved
593 * | ">>=" // reserved
598 assignment_expression
599 assignment_expression_1 .or assignment_expression_2 .or assignment_expression_3 .or
600 assignment_expression_4 .or assignment_expression_5/* .or assignment_expression_6 .or
601 assignment_expression_7 .or assignment_expression_8 .or assignment_expression_9 .or
602 assignment_expression_10 .or assignment_expression_11*/ .or conditional_expression;
603 assignment_expression_1
604 unary_expression .and equals .and assignment_expression .and .true .emit OP_ASSIGN;
605 assignment_expression_2
606 unary_expression .and starequals .and assignment_expression .and .true .emit OP_MULASSIGN;
607 assignment_expression_3
608 unary_expression .and slashequals .and assignment_expression .and .true .emit OP_DIVASSIGN;
609 assignment_expression_4
610 unary_expression .and plusequals .and assignment_expression .and .true .emit OP_ADDASSIGN;
611 assignment_expression_5
612 unary_expression .and minusequals .and assignment_expression .and .true .emit OP_SUBASSIGN;
613 /*assignment_expression_6
614 unary_expression .and percentequals .and assignment_expression .and .true .emit OP_MODASSIGN;*/
615 /*assignment_expression_7
616 unary_expression .and lesslessequals .and assignment_expression .and .true .emit OP_LSHASSIGN;*/
617 /*assignment_expression_8
618 unary_expression .and greatergreaterequals .and assignment_expression .and
619 .true .emit OP_RSHASSIGN;*/
620 /*assignment_expression_9
621 unary_expression .and ampersandequals .and assignment_expression .and .true .emit OP_ANDASSIGN;*/
622 /*assignment_expression_10
623 unary_expression .and caretequals .and assignment_expression .and .true .emit OP_XORASSIGN;*/
624 /*assignment_expression_11
625 unary_expression .and barequals .and assignment_expression .and .true .emit OP_ORASSIGN;*/
628 * <expression> ::= <assignment_expression>
629 * | <expression> "," <assignment_expression>
632 assignment_expression .and .loop expression_1;
634 comma .and assignment_expression .and .true .emit OP_SEQUENCE;
637 * <constant_expression> ::= <conditional_expression>
640 conditional_expression .and .true .emit OP_END;
643 * <declaration> ::= <function_prototype> ";"
644 * | <init_declarator_list> ";"
647 declaration_1 .or declaration_2;
649 function_prototype .emit DECLARATION_FUNCTION_PROTOTYPE .and semicolon;
651 init_declarator_list .emit DECLARATION_INIT_DECLARATOR_LIST .and semicolon;
654 * <function_prototype> ::= <function_header> "void" ")"
655 * | <function_declarator> ")"
658 function_prototype_1 .or function_prototype_2;
660 function_header .and "void" .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
662 function_declarator .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
665 * <function_declarator> ::= <function_header>
666 * | <function_header_with_parameters>
669 function_header_with_parameters .or function_header;
672 * <function_header_with_parameters> ::= <function_header> <parameter_declaration>
673 * | <function_header_with_parameters> ","
674 * <parameter_declaration>
676 function_header_with_parameters
677 function_header .and parameter_declaration .and .loop function_header_with_parameters_1;
678 function_header_with_parameters_1
679 comma .and parameter_declaration;
682 * <function_header> ::= <fully_specified_type> <identifier> "("
685 function_header_nospace .or function_header_space;
686 function_header_space
687 fully_specified_type_space .and space .and function_decl_identifier .and lparen;
688 function_header_nospace
689 fully_specified_type_nospace .and function_decl_identifier .and lparen;
692 * <function_decl_identifier> ::= "__constructor"
696 * note: this is an extension to the standard language specification.
697 * normally slang disallows operator and constructor prototypes and definitions
699 function_decl_identifier
700 .if (parsing_builtin != 0) __operator .emit FUNCTION_OPERATOR .or
701 .if (parsing_builtin != 0) "__constructor" .emit FUNCTION_CONSTRUCTOR .or
702 identifier .emit FUNCTION_ORDINARY;
705 * <__operator> ::= "__operator" <overriden_op>
707 * note: this is an extension to the standard language specification.
708 * normally slang disallows operator prototypes and definitions
711 "__operator" .and overriden_operator .error INVALID_OPERATOR_OVERRIDE;
714 * <overriden_op> ::= "="
720 * | "<<=" // reserved
721 * | ">>=" // reserved
747 * note: this is an extension to the standard language specification.
748 * normally slang disallows operator prototypes and definitions
751 plusplus .emit OPERATOR_INCREMENT .or
752 plusequals .emit OPERATOR_ADDASSIGN .or
753 plus .emit OPERATOR_PLUS .or
754 minusminus .emit OPERATOR_DECREMENT .or
755 minusequals .emit OPERATOR_SUBASSIGN .or
756 minus .emit OPERATOR_MINUS .or
757 bang .emit OPERATOR_NOT .or
758 starequals .emit OPERATOR_MULASSIGN .or
759 star .emit OPERATOR_MULTIPLY .or
760 slashequals .emit OPERATOR_DIVASSIGN .or
761 slash .emit OPERATOR_DIVIDE .or
762 lessequals .emit OPERATOR_LESSEQUAL .or
763 /*lesslessequals .emit OPERATOR_LSHASSIGN .or*/
764 /*lessless .emit OPERATOR_LSHIFT .or*/
765 less .emit OPERATOR_LESS .or
766 greaterequals .emit OPERATOR_GREATEREQUAL .or
767 /*greatergreaterequals .emit OPERATOR_RSHASSIGN .or*/
768 /*greatergreater .emit OPERATOR_RSHIFT .or*/
769 greater .emit OPERATOR_GREATER .or
770 /*percentequals .emit OPERATOR_MODASSIGN .or*/
771 /*percent .emit OPERATOR_MODULUS .or*/
772 /*ampersandequals .emit OPERATOR_ANDASSIGN */
773 /*ampersand .emit OPERATOR_BITAND .or*/
774 /*barequals .emit OPERATOR_ORASSIGN .or*/
775 /*bar .emit OPERATOR_BITOR .or*/
776 /*tilde .emit OPERATOR_COMPLEMENT .or*/
777 /*caretequals .emit OPERATOR_XORASSIGN .or*/
778 caretcaret .emit OPERATOR_LOGICALXOR /*.or
779 caret .emit OPERATOR_BITXOR*/;
782 * <parameter_declarator> ::= <type_specifier> <identifier>
783 * | <type_specifier> <identifier> "[" <constant_expression> "]"
786 parameter_declarator_nospace .or parameter_declarator_space;
787 parameter_declarator_nospace
788 type_specifier_nospace .and identifier .and parameter_declarator_1;
789 parameter_declarator_space
790 type_specifier_space .and space .and identifier .and parameter_declarator_1;
791 parameter_declarator_1
792 parameter_declarator_2 .emit PARAMETER_ARRAY_PRESENT .or
793 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
794 parameter_declarator_2
795 lbracket .and constant_expression .and rbracket;
798 * <parameter_declaration> ::= <type_qualifier> <parameter_qualifier>
799 * <precision> <parameter_declarator>
800 * | <type_qualifier> <parameter_qualifier>
801 * <precision> <parameter_type_specifier>
802 * | <type_qualifier> <parameter_qualifier>
803 * <parameter_declarator>
804 * | <type_qualifier> <parameter_qualifier>
805 * <parameter_type_specifier>
806 * | <parameter_qualifier> <precision>
807 * <parameter_declarator>
808 * | <parameter_qualifier> <precision>
809 * <parameter_type_specifier>
810 * | <parameter_qualifier> <parameter_declarator>
811 * | <parameter_qualifier> <parameter_type_specifier>
813 parameter_declaration
814 parameter_declaration_1 .emit PARAMETER_NEXT;
815 parameter_declaration_1
816 parameter_declaration_2 .or parameter_declaration_3;
817 parameter_declaration_2
818 type_qualifier .and space .and parameter_qualifier .and parameter_declaration_4;
819 parameter_declaration_3
820 parameter_qualifier .emit TYPE_QUALIFIER_NONE .and parameter_declaration_4;
821 parameter_declaration_4
822 parameter_declaration_optprec .and parameter_declaration_rest;
823 parameter_declaration_optprec
824 parameter_declaration_prec .or .true .emit PRECISION_DEFAULT;
825 parameter_declaration_prec
826 precision .and space;
827 parameter_declaration_rest
828 parameter_declarator .or parameter_type_specifier;
831 * <parameter_qualifier> ::= "in"
837 parameter_qualifier_1 .or .true .emit PARAM_QUALIFIER_IN;
838 parameter_qualifier_1
839 parameter_qualifier_2 .and space;
840 parameter_qualifier_2
841 "in" .emit PARAM_QUALIFIER_IN .or
842 "out" .emit PARAM_QUALIFIER_OUT .or
843 "inout" .emit PARAM_QUALIFIER_INOUT;
846 * <parameter_type_specifier> ::= <type_specifier>
847 * | <type_specifier> "[" <constant_expression> "]"
849 parameter_type_specifier
850 parameter_type_specifier_1 .and .true .emit '\0' .and parameter_type_specifier_2;
851 parameter_type_specifier_1
852 type_specifier_nospace .or type_specifier_space;
853 parameter_type_specifier_2
854 parameter_type_specifier_3 .emit PARAMETER_ARRAY_PRESENT .or
855 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
856 parameter_type_specifier_3
857 lbracket .and constant_expression .and rbracket;
860 * <init_declarator_list> ::= <single_declaration>
861 * | <init_declarator_list> "," <identifier>
862 * | <init_declarator_list> "," <identifier> "[" "]"
863 * | <init_declarator_list> "," <identifier> "[" <constant_expression> "]"
864 * | <init_declarator_list> "," <identifier> "=" <initializer>
867 single_declaration .and .loop init_declarator_list_1 .emit DECLARATOR_NEXT .and
868 .true .emit DECLARATOR_NONE;
869 init_declarator_list_1
870 comma .and identifier .emit VARIABLE_IDENTIFIER .and init_declarator_list_2;
871 init_declarator_list_2
872 init_declarator_list_3 .or init_declarator_list_4 .or .true .emit VARIABLE_NONE;
873 init_declarator_list_3
874 equals .and initializer .emit VARIABLE_INITIALIZER;
875 init_declarator_list_4
876 lbracket .and init_declarator_list_5 .and rbracket;
877 init_declarator_list_5
878 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
881 * <single_declaration> ::= <fully_specified_type>
882 * | <fully_specified_type> <identifier>
883 * | <fully_specified_type> <identifier> "[" "]"
884 * | <fully_specified_type> <identifier> "[" <constant_expression> "]"
885 * | <fully_specified_type> <identifier> "=" <initializer>
888 single_declaration_nospace .or single_declaration_space;
889 single_declaration_space
890 fully_specified_type_space .and single_declaration_space_1;
891 single_declaration_nospace
892 fully_specified_type_nospace .and single_declaration_nospace_1;
893 single_declaration_space_1
894 single_declaration_space_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
895 single_declaration_nospace_1
896 single_declaration_nospace_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
897 single_declaration_space_2
898 space .and identifier .and single_declaration_3;
899 single_declaration_nospace_2
900 identifier .and single_declaration_3;
902 single_declaration_4 .or single_declaration_5 .or .true .emit VARIABLE_NONE;
904 equals .and initializer .emit VARIABLE_INITIALIZER;
906 lbracket .and single_declaration_6 .and rbracket;
908 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
911 * <fully_specified_type> ::= <opt_invariant> <opt_centroid> <opt_qualifer> <opt_precision> <type_specifier> <opt_array_size>
913 * Example: "invariant varying highp vec3 [4]"
915 * Note that the *_space version doesn't parse the array size, make sure it is being invoked after the *_nospace version.
917 fully_specified_type_space
918 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_space .and .true .emit TYPE_NO_ARRAY_SIZE;
919 fully_specified_type_nospace
920 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_array;
922 type_specifier_array_1 .or type_specifier_array_2;
923 type_specifier_array_1
924 type_specifier_space .and array_size;
925 type_specifier_array_2
926 type_specifier_nospace .and opt_array_size;
927 fully_specified_type_optinvariant
928 fully_specified_type_invariant .or .true .emit TYPE_VARIANT;
929 fully_specified_type_invariant
930 invariant_qualifier .and space;
931 fully_specified_type_optcentroid
932 fully_specified_type_centroid .or .true .emit TYPE_CENTER;
933 fully_specified_type_centroid
934 centroid_qualifier .and space;
935 fully_specified_type_optqual
936 fully_specified_type_qual .or .true .emit TYPE_QUALIFIER_NONE;
937 fully_specified_type_qual
938 type_qualifier .and space;
939 fully_specified_type_optprec
940 fully_specified_type_prec .or .true .emit PRECISION_DEFAULT;
941 fully_specified_type_prec
942 precision .and space;
944 array_size .or .true .emit TYPE_NO_ARRAY_SIZE;
946 lbracket .emit TYPE_ARRAY_SIZE .and constant_expression .and rbracket;
950 * <invariant_qualifier> ::= "invariant"
953 "invariant" .emit TYPE_INVARIANT;
956 "centroid" .emit TYPE_CENTROID;
960 * <type_qualifier> ::= "const"
961 * | "attribute" // Vertex only.
967 * note: this is an extension to the standard language specification,
968 * normally slang disallows __fixed_output and __fixed_input type qualifiers
971 "const" .emit TYPE_QUALIFIER_CONST .or
972 .if (shader_type == 2) "attribute" .emit TYPE_QUALIFIER_ATTRIBUTE .or
973 "varying" .emit TYPE_QUALIFIER_VARYING .or
974 "uniform" .emit TYPE_QUALIFIER_UNIFORM .or
975 .if (parsing_builtin != 0) "__fixed_output" .emit TYPE_QUALIFIER_FIXEDOUTPUT .or
976 .if (parsing_builtin != 0) "__fixed_input" .emit TYPE_QUALIFIER_FIXEDINPUT;
979 * <type_specifier> ::= "void"
1005 * | "sampler1DShadow"
1006 * | "sampler2DShadow"
1008 * | "sampler2DRectShadow"
1009 * | <struct_specifier>
1012 type_specifier_space
1013 "void" .emit TYPE_SPECIFIER_VOID .or
1014 "float" .emit TYPE_SPECIFIER_FLOAT .or
1015 "int" .emit TYPE_SPECIFIER_INT .or
1016 "bool" .emit TYPE_SPECIFIER_BOOL .or
1017 "vec2" .emit TYPE_SPECIFIER_VEC2 .or
1018 "vec3" .emit TYPE_SPECIFIER_VEC3 .or
1019 "vec4" .emit TYPE_SPECIFIER_VEC4 .or
1020 "bvec2" .emit TYPE_SPECIFIER_BVEC2 .or
1021 "bvec3" .emit TYPE_SPECIFIER_BVEC3 .or
1022 "bvec4" .emit TYPE_SPECIFIER_BVEC4 .or
1023 "ivec2" .emit TYPE_SPECIFIER_IVEC2 .or
1024 "ivec3" .emit TYPE_SPECIFIER_IVEC3 .or
1025 "ivec4" .emit TYPE_SPECIFIER_IVEC4 .or
1026 "mat2" .emit TYPE_SPECIFIER_MAT2 .or
1027 "mat3" .emit TYPE_SPECIFIER_MAT3 .or
1028 "mat4" .emit TYPE_SPECIFIER_MAT4 .or
1029 "mat2x3" .emit TYPE_SPECIFIER_MAT23 .or
1030 "mat3x2" .emit TYPE_SPECIFIER_MAT32 .or
1031 "mat2x4" .emit TYPE_SPECIFIER_MAT24 .or
1032 "mat4x2" .emit TYPE_SPECIFIER_MAT42 .or
1033 "mat3x4" .emit TYPE_SPECIFIER_MAT34 .or
1034 "mat4x3" .emit TYPE_SPECIFIER_MAT43 .or
1035 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1036 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1037 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1038 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1039 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1040 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1041 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1042 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW .or
1043 type_name .emit TYPE_SPECIFIER_TYPENAME;
1044 type_specifier_nospace
1045 struct_specifier .emit TYPE_SPECIFIER_STRUCT;
1048 * <struct_specifier> ::= "struct" <identifier> "{" <struct_declaration_list> "}"
1049 * | "struct" "{" <struct_declaration_list> "}"
1052 "struct" .and struct_specifier_1 .and optional_space .and lbrace .error LBRACE_EXPECTED .and
1053 struct_declaration_list .and rbrace .emit FIELD_NONE;
1055 struct_specifier_2 .or .true .emit '\0';
1057 space .and identifier;
1060 * <struct_declaration_list> ::= <struct_declaration>
1061 * | <struct_declaration_list> <struct_declaration>
1063 struct_declaration_list
1064 struct_declaration .and .loop struct_declaration .emit FIELD_NEXT;
1067 * <struct_declaration> ::= <type_specifier> <struct_declarator_list> ";"
1070 struct_declaration_nospace .or struct_declaration_space;
1071 struct_declaration_space
1072 type_specifier_space .and space .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1073 struct_declaration_nospace
1074 type_specifier_nospace .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1077 * <struct_declarator_list> ::= <struct_declarator>
1078 * | <struct_declarator_list> "," <struct_declarator>
1080 struct_declarator_list
1081 struct_declarator .and .loop struct_declarator_list_1 .emit FIELD_NEXT;
1082 struct_declarator_list_1
1083 comma .and struct_declarator;
1086 * <struct_declarator> ::= <identifier>
1087 * | <identifier> "[" <constant_expression> "]"
1090 identifier .and struct_declarator_1;
1092 struct_declarator_2 .emit FIELD_ARRAY .or .true .emit FIELD_NONE;
1094 lbracket .and constant_expression .and rbracket;
1097 * <initializer> ::= <assignment_expression>
1100 assignment_expression .and .true .emit OP_END;
1103 * <declaration_statement> ::= <declaration>
1105 declaration_statement
1109 * <statement> ::= <compound_statement>
1110 * | <simple_statement>
1113 compound_statement .or simple_statement;
1115 compound_statement .or statement_space_1;
1117 space .and simple_statement;
1120 * <simple_statement> ::= <__asm_statement>
1121 * | <selection_statement>
1122 * | <iteration_statement>
1123 * | <jump_statement>
1124 * | <expression_statement>
1125 * | <declaration_statement>
1127 * note: this is an extension to the standard language specification.
1128 * normally slang disallows use of __asm statements
1131 .if (parsing_builtin != 0) __asm_statement .emit OP_ASM .or
1132 selection_statement .or
1133 iteration_statement .or
1134 precision_stmt .emit OP_PRECISION .or
1136 expression_statement .emit OP_EXPRESSION .or
1137 declaration_statement .emit OP_DECLARE;
1140 * <compound_statement> ::= "{" "}"
1141 * | "{" <statement_list> "}"
1144 compound_statement_1 .emit OP_BLOCK_BEGIN_NEW_SCOPE .and .true .emit OP_END;
1145 compound_statement_1
1146 compound_statement_2 .or compound_statement_3;
1147 compound_statement_2
1149 compound_statement_3
1150 lbrace .and statement_list .and rbrace;
1153 * <statement_no_new_scope> ::= <compound_statement_no_new_scope>
1154 * | <simple_statement>
1156 statement_no_new_scope
1157 compound_statement_no_new_scope .or simple_statement;
1160 * <compound_statement_no_new_scope> ::= "{" "}"
1161 * | "{" <statement_list> "}"
1163 compound_statement_no_new_scope
1164 compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;
1165 compound_statement_no_new_scope_1
1166 compound_statement_no_new_scope_2 .or compound_statement_no_new_scope_3;
1167 compound_statement_no_new_scope_2
1169 compound_statement_no_new_scope_3
1170 lbrace .and statement_list .and rbrace;
1173 * <statement_list> ::= <statement>
1174 * | <statement_list> <statement>
1177 statement .and .loop statement;
1180 * <expression_statement> ::= ";"
1181 * | <expression> ";"
1183 expression_statement
1184 expression_statement_1 .or expression_statement_2;
1185 expression_statement_1
1186 semicolon .emit OP_PUSH_VOID .emit OP_END;
1187 expression_statement_2
1188 expression .and semicolon .emit OP_END;
1191 * <selection_statement> ::= "if" "(" <expression> ")" <selection_rest_statement>
1194 "if" .emit OP_IF .and lparen .error LPAREN_EXPECTED .and expression .and
1195 rparen .error RPAREN_EXPECTED .emit OP_END .and selection_rest_statement;
1198 * <selection_rest_statement> ::= <statement> "else" <statement>
1201 selection_rest_statement
1202 statement .and selection_rest_statement_1;
1203 selection_rest_statement_1
1204 selection_rest_statement_2 .or .true .emit OP_EXPRESSION .emit OP_PUSH_VOID .emit OP_END;
1205 selection_rest_statement_2
1206 "else" .and optional_space .and statement;
1209 * <condition> ::= <expression>
1210 * | <fully_specified_type> <identifier> "=" <initializer>
1212 * note: if <condition_1> is executed, the emit format must
1213 * match <declaration> emit format
1216 condition_1 .emit OP_DECLARE .emit DECLARATION_INIT_DECLARATOR_LIST .or
1217 condition_3 .emit OP_EXPRESSION;
1219 condition_1_nospace .or condition_1_space;
1221 fully_specified_type_nospace .and condition_2;
1223 fully_specified_type_space .and space .and condition_2;
1225 identifier .emit VARIABLE_IDENTIFIER .and equals .emit VARIABLE_INITIALIZER .and
1226 initializer .and .true .emit DECLARATOR_NONE;
1228 expression .and .true .emit OP_END;
1231 * <iteration_statement> ::= "while" "(" <condition> ")" <statement>
1232 * | "do" <statement> "while" "(" <expression> ")" ";"
1233 * | "for" "(" <for_init_statement> <for_rest_statement> ")"
1234 * <statement_no_new_scope>
1237 iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3;
1238 iteration_statement_1
1239 "while" .emit OP_WHILE .and lparen .error LPAREN_EXPECTED .and condition .and
1240 rparen .error RPAREN_EXPECTED .and statement;
1241 iteration_statement_2
1242 "do" .emit OP_DO .and statement_space .and "while" .and lparen .error LPAREN_EXPECTED .and
1243 expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;
1244 iteration_statement_3
1245 "for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and
1246 for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
1249 * <for_init_statement> ::= <expression_statement>
1250 * | <declaration_statement>
1253 expression_statement .emit OP_EXPRESSION .or declaration_statement .emit OP_DECLARE;
1256 * <conditionopt> ::= <condition>
1259 * note: <conditionopt> is used only by "for" statement.
1260 * if <condition> is ommitted, parser simulates default behaviour,
1261 * that is simulates "true" expression
1265 .true .emit OP_EXPRESSION .emit OP_PUSH_BOOL .emit 2 .emit '1' .emit '\0' .emit OP_END;
1268 * <for_rest_statement> ::= <conditionopt> ";"
1269 * | <conditionopt> ";" <expression>
1272 conditionopt .and semicolon .and for_rest_statement_1;
1273 for_rest_statement_1
1274 for_rest_statement_2 .or .true .emit OP_PUSH_VOID .emit OP_END;
1275 for_rest_statement_2
1276 expression .and .true .emit OP_END;
1279 * <jump_statement> ::= "continue" ";"
1282 * | "return" <expression> ";"
1283 * | "discard" ";" // Fragment shader only.
1286 jump_statement_1 .or jump_statement_2 .or jump_statement_3 .or jump_statement_4 .or
1287 .if (shader_type == 1) jump_statement_5;
1289 "continue" .and semicolon .emit OP_CONTINUE;
1291 "break" .and semicolon .emit OP_BREAK;
1293 "return" .emit OP_RETURN .and optional_space .and expression .and semicolon .emit OP_END;
1295 "return" .emit OP_RETURN .and semicolon .emit OP_PUSH_VOID .emit OP_END;
1297 "discard" .and semicolon .emit OP_DISCARD;
1300 * <__asm_statement> ::= "__asm" <identifier> <asm_arguments> ";"
1302 * note: this is an extension to the standard language specification.
1303 * normally slang disallows __asm statements
1306 "__asm" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END;
1309 * <asm_arguments> ::= <asm_argument>
1310 * | <asm_arguments> "," <asm_argument>
1312 * note: this is an extension to the standard language specification.
1313 * normally slang disallows __asm statements
1316 asm_argument .and .true .emit OP_END .and .loop asm_arguments_1;
1318 comma .and asm_argument .and .true .emit OP_END;
1321 * <asm_argument> ::= <variable_identifier>
1324 * note: this is an extension to the standard language specification.
1325 * normally slang disallows __asm statements
1329 variable_identifier .or
1333 variable_identifier .and dot .and field_selection .emit OP_FIELD;
1337 * <translation_unit> ::= <external_declaration>
1338 * | <translation_unit> <external_declaration>
1341 optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and
1342 .loop external_declaration .and optional_space .and
1343 '\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL;
1347 * <external_declaration> ::= <function_definition>
1350 external_declaration
1351 precision_stmt .emit DEFAULT_PRECISION .or
1352 function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or
1353 invariant_stmt .emit INVARIANT_STMT .or
1354 declaration .emit EXTERNAL_DECLARATION;
1358 * <precision_stmt> ::= "precision" <precision> <prectype>
1361 "precision" .and space .and precision .error INVALID_PRECISION .and space .and prectype .error INVALID_PRECISION_TYPE .and semicolon;
1364 * <precision> ::= "lowp"
1369 "lowp" .emit PRECISION_LOW .or
1370 "mediump" .emit PRECISION_MEDIUM .or
1371 "highp" .emit PRECISION_HIGH;
1374 * <prectype> ::= "int"
1376 * | "a sampler type"
1379 "int" .emit TYPE_SPECIFIER_INT .or
1380 "float" .emit TYPE_SPECIFIER_FLOAT .or
1381 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1382 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1383 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1384 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1385 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1386 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1387 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1388 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW;
1392 * <invariant_stmt> ::= "invariant" identifier;
1395 "invariant" .and space .and identifier .and semicolon;
1399 * <function_definition> :: <function_prototype> <compound_statement_no_new_scope>
1402 function_prototype .and compound_statement_no_new_scope;
1407 * helper rules, not part of the official language syntax
1417 '0'-'9' .or 'A'-'F' .or 'a'-'f';
1420 'a'-'z' .or 'A'-'Z' .or '_';
1423 id_character_first .or digit_dec;
1426 id_character_first .emit * .and .loop id_character_next .emit * .and .true .emit '\0';
1429 float_1 .or float_2 .or float_3;
1431 float_fractional_constant .and float_optional_exponent_part .and optional_f_suffix;
1433 float_digit_sequence .and .true .emit '\0' .and float_exponent_part .and optional_f_suffix;
1435 float_digit_sequence .and .true .emit '\0' .and 'f' .emit '\0';
1437 float_fractional_constant
1438 float_fractional_constant_1 .or float_fractional_constant_2 .or float_fractional_constant_3;
1439 float_fractional_constant_1
1440 float_digit_sequence .and '.' .and float_digit_sequence;
1441 float_fractional_constant_2
1442 float_digit_sequence .and '.' .and .true .emit '\0';
1443 float_fractional_constant_3
1444 '.' .emit '\0' .and float_digit_sequence;
1446 float_optional_exponent_part
1447 float_exponent_part .or .true .emit '\0';
1449 float_digit_sequence
1450 digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1453 float_exponent_part_1 .or float_exponent_part_2;
1454 float_exponent_part_1
1455 'e' .and float_optional_sign .and float_digit_sequence;
1456 float_exponent_part_2
1457 'E' .and float_optional_sign .and float_digit_sequence;
1460 float_sign .or .true;
1463 '+' .or '-' .emit '-';
1470 integer_hex .or integer_oct .or integer_dec;
1473 '0' .and integer_hex_1 .emit 0x10 .and digit_hex .emit * .and .loop digit_hex .emit * .and
1479 '0' .emit 8 .emit * .and .loop digit_oct .emit * .and .true .emit '\0';
1482 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1485 "true" .emit 2 .emit '1' .emit '\0' .or
1486 "false" .emit 2 .emit '0' .emit '\0';
1495 float .emit OP_PUSH_FLOAT;
1498 integer .emit OP_PUSH_INT;
1501 boolean .emit OP_PUSH_BOOL;
1507 single_space .and .loop single_space;
1510 white_char .or c_style_comment_block .or cpp_style_comment_block;
1513 ' ' .or '\t' .or new_line .or '\v' .or '\f';
1516 cr_lf .or lf_cr .or '\n' .or '\r';
1524 c_style_comment_block
1525 '/' .and '*' .and c_style_comment_rest;
1527 c_style_comment_rest
1528 .loop c_style_comment_char_no_star .and c_style_comment_rest_1;
1529 c_style_comment_rest_1
1530 c_style_comment_end .or c_style_comment_rest_2;
1531 c_style_comment_rest_2
1532 '*' .and c_style_comment_rest;
1534 c_style_comment_char_no_star
1535 '\x2B'-'\xFF' .or '\x01'-'\x29';
1540 cpp_style_comment_block
1541 '/' .and '/' .and cpp_style_comment_block_1;
1542 cpp_style_comment_block_1
1543 cpp_style_comment_block_2 .or cpp_style_comment_block_3;
1544 cpp_style_comment_block_2
1545 .loop cpp_style_comment_char .and new_line;
1546 cpp_style_comment_block_3
1547 .loop cpp_style_comment_char;
1549 cpp_style_comment_char
1550 '\x0E'-'\xFF' .or '\x01'-'\x09' .or '\x0B'-'\x0C';
1555 optional_space .and '&' .and optional_space;*/
1558 optional_space .and '&' .and '&' .and optional_space;
1561 optional_space .and '&' .and '=' .and optional_space;*/
1564 optional_space .and '|' .and optional_space;*/
1567 optional_space .and '|' .and '|' .and optional_space;
1570 optional_space .and '|' .and '=' .and optional_space;*/
1573 optional_space .and '!' .and optional_space;
1576 optional_space .and '!' .and '=' .and optional_space;
1579 optional_space .and '^' .and optional_space;*/
1582 optional_space .and '^' .and '^' .and optional_space;
1585 optional_space .and '^' .and '=' .and optional_space;*/
1588 optional_space .and ':' .and optional_space;
1591 optional_space .and ',' .and optional_space;
1594 optional_space .and '.' .and optional_space;
1597 optional_space .and '=' .and optional_space;
1600 optional_space .and '=' .and '=' .and optional_space;
1603 optional_space .and '>' .and optional_space;
1606 optional_space .and '>' .and '=' .and optional_space;
1609 optional_space .and '>' .and '>' .and optional_space;*/
1611 /*greatergreaterequals
1612 optional_space .and '>' .and '>' .and '=' .and optional_space;*/
1615 optional_space .and '{' .and optional_space;
1618 optional_space .and '[' .and optional_space;
1621 optional_space .and '<' .and optional_space;
1624 optional_space .and '<' .and '=' .and optional_space;
1627 optional_space .and '<' .and '<' .and optional_space;*/
1630 optional_space .and '<' .and '<' .and '=' .and optional_space;*/
1633 optional_space .and '(' .and optional_space;
1636 optional_space .and '-' .and optional_space;
1639 optional_space .and '-' .and '=' .and optional_space;
1642 optional_space .and '-' .and '-' .and optional_space;
1645 optional_space .and '%' .and optional_space;*/
1648 optional_space .and '%' .and '=' .and optional_space;*/
1651 optional_space .and '+' .and optional_space;
1654 optional_space .and '+' .and '=' .and optional_space;
1657 optional_space .and '+' .and '+' .and optional_space;
1660 optional_space .and '?' .and optional_space;
1663 optional_space .and '}' .and optional_space;
1666 optional_space .and ']' .and optional_space;
1669 optional_space .and ')' .and optional_space;
1672 optional_space .and ';' .and optional_space;
1675 optional_space .and '/' .and optional_space;
1678 optional_space .and '/' .and '=' .and optional_space;
1681 optional_space .and '*' .and optional_space;
1684 optional_space .and '*' .and '=' .and optional_space;
1687 optional_space .and '~' .and optional_space;*/
1689 /* string rules - these are used internally by the parser when parsing quoted strings */
1691 .string string_lexer;
1694 lex_first_identifier_character .and .loop lex_next_identifier_character;
1696 lex_first_identifier_character
1697 'a'-'z' .or 'A'-'Z' .or '_';
1699 lex_next_identifier_character
1700 'a'-'z' .or 'A'-'Z' .or '0'-'9' .or '_';
1702 /* error rules - these are used by error messages */
1705 '~' .or '`' .or '!' .or '@' .or '#' .or '$' .or '%' .or '^' .or '&' .or '*' .or '(' .or ')' .or
1706 '-' .or '+' .or '=' .or '|' .or '\\' .or '[' .or ']' .or '{' .or '}' .or ':' .or ';' .or '"' .or
1707 '\'' .or '<' .or ',' .or '>' .or '.' .or '/' .or '?' .or err_identifier;
1710 id_character_first .and .loop id_character_next;