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
255 /* parameter qualifier */
256 .emtcode PARAM_QUALIFIER_IN 0
257 .emtcode PARAM_QUALIFIER_OUT 1
258 .emtcode PARAM_QUALIFIER_INOUT 2
260 /* function parameter */
261 .emtcode PARAMETER_NONE 0
262 .emtcode PARAMETER_NEXT 1
264 /* function parameter array presence */
265 .emtcode PARAMETER_ARRAY_NOT_PRESENT 0
266 .emtcode PARAMETER_ARRAY_PRESENT 1
268 /* INVALID_EXTERNAL_DECLARATION seems to be reported when there's */
269 /* any syntax errors... */
270 .errtext INVALID_EXTERNAL_DECLARATION "2001: Syntax error."
271 .errtext INVALID_OPERATOR_OVERRIDE "2002: Invalid operator override."
272 .errtext LBRACE_EXPECTED "2003: '{' expected but '$err_token$' found."
273 .errtext LPAREN_EXPECTED "2004: '(' expected but '$err_token$' found."
274 .errtext RPAREN_EXPECTED "2005: ')' expected but '$err_token$' found."
275 .errtext INVALID_PRECISION "2006: Invalid precision specifier '$err_token$'."
276 .errtext INVALID_PRECISION_TYPE "2007: Invalid precision type '$err_token$'."
280 * tells whether the shader that is being parsed is a built-in shader or not
281 * 0 - normal behaviour
282 * 1 - accepts constructor and operator definitions and __asm statements
283 * the implementation will set it to 1 when compiling internal built-in shaders
285 .regbyte parsing_builtin 0
288 * holds the type of the shader being parsed; possible values are
292 * shader type is set by the caller before parsing
294 .regbyte shader_type 0
297 * <variable_identifier> ::= <identifier>
300 identifier .emit OP_PUSH_IDENTIFIER;
303 * <primary_expression> ::= <variable_identifier>
307 * | "(" <expression> ")"
310 floatconstant .or boolconstant .or intconstant .or variable_identifier .or primary_expression_1;
312 lparen .and expression .and rparen;
315 * <postfix_expression> ::= <primary_expression>
316 * | <postfix_expression> "[" <integer_expression> "]"
318 * | <postfix_expression> "." <field_selection>
319 * | <postfix_expression> "++"
320 * | <postfix_expression> "--"
323 postfix_expression_1 .and .loop postfix_expression_2;
325 function_call .or primary_expression;
327 postfix_expression_3 .or postfix_expression_4 .or
328 plusplus .emit OP_POSTINCREMENT .or
329 minusminus .emit OP_POSTDECREMENT;
331 lbracket .and integer_expression .and rbracket .emit OP_SUBSCRIPT;
333 dot .and field_selection .emit OP_FIELD;
336 * <integer_expression> ::= <expression>
342 * <function_call> ::= <function_call_generic>
345 function_call_generic .emit OP_CALL .and .true .emit OP_END;
348 * <function_call_generic> ::= <function_call_header_with_parameters> ")"
349 * | <function_call_header_no_parameters> ")"
351 function_call_generic
352 function_call_generic_1 .or function_call_generic_2;
353 function_call_generic_1
354 function_call_header_with_parameters .and rparen .error RPAREN_EXPECTED;
355 function_call_generic_2
356 function_call_header_no_parameters .and rparen .error RPAREN_EXPECTED;
359 * <function_call_header_no_parameters>::= <function_call_header> "void"
360 * | <function_call_header>
362 function_call_header_no_parameters
363 function_call_header .and function_call_header_no_parameters_1;
364 function_call_header_no_parameters_1
368 * <function_call_header_with_parameters> ::= <function_call_header> <assignment_expression>
369 * | <function_call_header_with_parameters> "," <assignment_expression>
371 function_call_header_with_parameters
372 function_call_header .and assignment_expression .and .true .emit OP_END .and
373 .loop function_call_header_with_parameters_1;
374 function_call_header_with_parameters_1
375 comma .and assignment_expression .and .true .emit OP_END;
378 * <function_call_header> ::= <function_identifier> "("
381 function_identifier .and lparen;
384 * <function_identifier> ::= <constructor_identifier>
387 * note: <constructor_identifier> has been deleted
393 * <unary_expression> ::= <postfix_expression>
394 * | "++" <unary_expression>
395 * | "--" <unary_expression>
396 * | <unary_operator> <unary_expression>
398 * <unary_operator> ::= "+"
404 postfix_expression .or unary_expression_1 .or unary_expression_2 .or unary_expression_3 .or
405 unary_expression_4 .or unary_expression_5/* .or unary_expression_6*/;
407 plusplus .and unary_expression .and .true .emit OP_PREINCREMENT;
409 minusminus .and unary_expression .and .true .emit OP_PREDECREMENT;
411 plus .and unary_expression .and .true .emit OP_PLUS;
413 minus .and unary_expression .and .true .emit OP_MINUS;
415 bang .and unary_expression .and .true .emit OP_NOT;
417 tilde .and unary_expression .and .true .emit OP_COMPLEMENT;*/
420 * <multiplicative_expression> ::= <unary_expression>
421 * | <multiplicative_expression> "*" <unary_expression>
422 * | <multiplicative_expression> "/" <unary_expression>
423 * | <multiplicative_expression> "%" <unary_expression> // reserved
425 multiplicative_expression
426 unary_expression .and .loop multiplicative_expression_1;
427 multiplicative_expression_1
428 multiplicative_expression_2 .or multiplicative_expression_3/* .or multiplicative_expression_4*/;
429 multiplicative_expression_2
430 star .and unary_expression .and .true .emit OP_MULTIPLY;
431 multiplicative_expression_3
432 slash .and unary_expression .and .true .emit OP_DIVIDE;
433 /*multiplicative_expression_4
434 percent .and unary_expression .and .true .emit OP_MODULUS;*/
437 * <additive_expression> ::= <multiplicative_expression>
438 * | <additive_expression> "+" <multiplicative_expression>
439 * | <additive_expression> "-" <multiplicative_expression>
442 multiplicative_expression .and .loop additive_expression_1;
443 additive_expression_1
444 additive_expression_2 .or additive_expression_3;
445 additive_expression_2
446 plus .and multiplicative_expression .and .true .emit OP_ADD;
447 additive_expression_3
448 minus .and multiplicative_expression .and .true .emit OP_SUBTRACT;
451 * <shift_expression> ::= <additive_expression>
452 * | <shift_expression> "<<" <additive_expression> // reserved
453 * | <shift_expression> ">>" <additive_expression> // reserved
456 additive_expression/* .and .loop shift_expression_1*/;
458 shift_expression_2 .or shift_expression_3;*/
460 lessless .and additive_expression .and .true .emit OP_LSHIFT;*/
462 greatergreater .and additive_expression .and .true .emit OP_RSHIFT;*/
465 * <relational_expression> ::= <shift_expression>
466 * | <relational_expression> "<" <shift_expression>
467 * | <relational_expression> ">" <shift_expression>
468 * | <relational_expression> "<=" <shift_expression>
469 * | <relational_expression> ">=" <shift_expression>
471 relational_expression
472 shift_expression .and .loop relational_expression_1;
473 relational_expression_1
474 relational_expression_2 .or relational_expression_3 .or relational_expression_4 .or
475 relational_expression_5;
476 relational_expression_2
477 lessequals .and shift_expression .and .true .emit OP_LESSEQUAL;
478 relational_expression_3
479 greaterequals .and shift_expression .and .true .emit OP_GREATEREQUAL;
480 relational_expression_4
481 less .and shift_expression .and .true .emit OP_LESS;
482 relational_expression_5
483 greater .and shift_expression .and .true .emit OP_GREATER;
486 * <equality_expression> ::= <relational_expression>
487 * | <equality_expression> "==" <relational_expression>
488 * | <equality_expression> "!=" <relational_expression>
491 relational_expression .and .loop equality_expression_1;
492 equality_expression_1
493 equality_expression_2 .or equality_expression_3;
494 equality_expression_2
495 equalsequals .and relational_expression .and .true .emit OP_EQUAL;
496 equality_expression_3
497 bangequals .and relational_expression .and .true .emit OP_NOTEQUAL;
500 * <and_expression> ::= <equality_expression>
501 * | <and_expression> "&" <equality_expression> // reserved
504 equality_expression/* .and .loop and_expression_1*/;
506 ampersand .and equality_expression .and .true .emit OP_BITAND;*/
509 * <exclusive_or_expression> ::= <and_expression>
510 * | <exclusive_or_expression> "^" <and_expression> // reserved
512 exclusive_or_expression
513 and_expression/* .and .loop exclusive_or_expression_1*/;
514 /*exclusive_or_expression_1
515 caret .and and_expression .and .true .emit OP_BITXOR;*/
518 * <inclusive_or_expression> ::= <exclusive_or_expression>
519 * | <inclusive_or_expression> "|" <exclusive_or_expression> // reserved
521 inclusive_or_expression
522 exclusive_or_expression/* .and .loop inclusive_or_expression_1*/;
523 /*inclusive_or_expression_1
524 bar .and exclusive_or_expression .and .true .emit OP_BITOR;*/
527 * <logical_and_expression> ::= <inclusive_or_expression>
528 * | <logical_and_expression> "&&" <inclusive_or_expression>
530 logical_and_expression
531 inclusive_or_expression .and .loop logical_and_expression_1;
532 logical_and_expression_1
533 ampersandampersand .and inclusive_or_expression .and .true .emit OP_LOGICALAND;
536 * <logical_xor_expression> ::= <logical_and_expression>
537 * | <logical_xor_expression> "^^" <logical_and_expression>
539 logical_xor_expression
540 logical_and_expression .and .loop logical_xor_expression_1;
541 logical_xor_expression_1
542 caretcaret .and logical_and_expression .and .true .emit OP_LOGICALXOR;
545 * <logical_or_expression> ::= <logical_xor_expression>
546 * | <logical_or_expression> "||" <logical_xor_expression>
548 logical_or_expression
549 logical_xor_expression .and .loop logical_or_expression_1;
550 logical_or_expression_1
551 barbar .and logical_xor_expression .and .true .emit OP_LOGICALOR;
554 * <conditional_expression> ::= <logical_or_expression>
555 * | <logical_or_expression> "?" <expression> ":" <conditional_expression>
557 conditional_expression
558 logical_or_expression .and .loop conditional_expression_1;
559 conditional_expression_1
560 question .and expression .and colon .and conditional_expression .and .true .emit OP_SELECT;
563 * <assignment_expression> ::= <conditional_expression>
564 * | <unary_expression> <assignment_operator> <assignment_expression>
566 * <assignment_operator> ::= "="
572 * | "<<=" // reserved
573 * | ">>=" // reserved
578 assignment_expression
579 assignment_expression_1 .or assignment_expression_2 .or assignment_expression_3 .or
580 assignment_expression_4 .or assignment_expression_5/* .or assignment_expression_6 .or
581 assignment_expression_7 .or assignment_expression_8 .or assignment_expression_9 .or
582 assignment_expression_10 .or assignment_expression_11*/ .or conditional_expression;
583 assignment_expression_1
584 unary_expression .and equals .and assignment_expression .and .true .emit OP_ASSIGN;
585 assignment_expression_2
586 unary_expression .and starequals .and assignment_expression .and .true .emit OP_MULASSIGN;
587 assignment_expression_3
588 unary_expression .and slashequals .and assignment_expression .and .true .emit OP_DIVASSIGN;
589 assignment_expression_4
590 unary_expression .and plusequals .and assignment_expression .and .true .emit OP_ADDASSIGN;
591 assignment_expression_5
592 unary_expression .and minusequals .and assignment_expression .and .true .emit OP_SUBASSIGN;
593 /*assignment_expression_6
594 unary_expression .and percentequals .and assignment_expression .and .true .emit OP_MODASSIGN;*/
595 /*assignment_expression_7
596 unary_expression .and lesslessequals .and assignment_expression .and .true .emit OP_LSHASSIGN;*/
597 /*assignment_expression_8
598 unary_expression .and greatergreaterequals .and assignment_expression .and
599 .true .emit OP_RSHASSIGN;*/
600 /*assignment_expression_9
601 unary_expression .and ampersandequals .and assignment_expression .and .true .emit OP_ANDASSIGN;*/
602 /*assignment_expression_10
603 unary_expression .and caretequals .and assignment_expression .and .true .emit OP_XORASSIGN;*/
604 /*assignment_expression_11
605 unary_expression .and barequals .and assignment_expression .and .true .emit OP_ORASSIGN;*/
608 * <expression> ::= <assignment_expression>
609 * | <expression> "," <assignment_expression>
612 assignment_expression .and .loop expression_1;
614 comma .and assignment_expression .and .true .emit OP_SEQUENCE;
617 * <constant_expression> ::= <conditional_expression>
620 conditional_expression .and .true .emit OP_END;
623 * <declaration> ::= <function_prototype> ";"
624 * | <init_declarator_list> ";"
627 declaration_1 .or declaration_2;
629 function_prototype .emit DECLARATION_FUNCTION_PROTOTYPE .and semicolon;
631 init_declarator_list .emit DECLARATION_INIT_DECLARATOR_LIST .and semicolon;
634 * <function_prototype> ::= <function_header> "void" ")"
635 * | <function_declarator> ")"
638 function_prototype_1 .or function_prototype_2;
640 function_header .and "void" .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
642 function_declarator .and rparen .error RPAREN_EXPECTED .emit PARAMETER_NONE;
645 * <function_declarator> ::= <function_header>
646 * | <function_header_with_parameters>
649 function_header_with_parameters .or function_header;
652 * <function_header_with_parameters> ::= <function_header> <parameter_declaration>
653 * | <function_header_with_parameters> ","
654 * <parameter_declaration>
656 function_header_with_parameters
657 function_header .and parameter_declaration .and .loop function_header_with_parameters_1;
658 function_header_with_parameters_1
659 comma .and parameter_declaration;
662 * <function_header> ::= <fully_specified_type> <identifier> "("
665 function_header_nospace .or function_header_space;
666 function_header_space
667 fully_specified_type_space .and space .and function_decl_identifier .and lparen;
668 function_header_nospace
669 fully_specified_type_nospace .and function_decl_identifier .and lparen;
672 * <function_decl_identifier> ::= "__constructor"
676 * note: this is an extension to the standard language specification.
677 * normally slang disallows operator and constructor prototypes and definitions
679 function_decl_identifier
680 .if (parsing_builtin != 0) __operator .emit FUNCTION_OPERATOR .or
681 .if (parsing_builtin != 0) "__constructor" .emit FUNCTION_CONSTRUCTOR .or
682 identifier .emit FUNCTION_ORDINARY;
685 * <__operator> ::= "__operator" <overriden_op>
687 * note: this is an extension to the standard language specification.
688 * normally slang disallows operator prototypes and definitions
691 "__operator" .and overriden_operator .error INVALID_OPERATOR_OVERRIDE;
694 * <overriden_op> ::= "="
700 * | "<<=" // reserved
701 * | ">>=" // reserved
727 * note: this is an extension to the standard language specification.
728 * normally slang disallows operator prototypes and definitions
731 plusplus .emit OPERATOR_INCREMENT .or
732 plusequals .emit OPERATOR_ADDASSIGN .or
733 plus .emit OPERATOR_PLUS .or
734 minusminus .emit OPERATOR_DECREMENT .or
735 minusequals .emit OPERATOR_SUBASSIGN .or
736 minus .emit OPERATOR_MINUS .or
737 bang .emit OPERATOR_NOT .or
738 starequals .emit OPERATOR_MULASSIGN .or
739 star .emit OPERATOR_MULTIPLY .or
740 slashequals .emit OPERATOR_DIVASSIGN .or
741 slash .emit OPERATOR_DIVIDE .or
742 lessequals .emit OPERATOR_LESSEQUAL .or
743 /*lesslessequals .emit OPERATOR_LSHASSIGN .or*/
744 /*lessless .emit OPERATOR_LSHIFT .or*/
745 less .emit OPERATOR_LESS .or
746 greaterequals .emit OPERATOR_GREATEREQUAL .or
747 /*greatergreaterequals .emit OPERATOR_RSHASSIGN .or*/
748 /*greatergreater .emit OPERATOR_RSHIFT .or*/
749 greater .emit OPERATOR_GREATER .or
750 /*percentequals .emit OPERATOR_MODASSIGN .or*/
751 /*percent .emit OPERATOR_MODULUS .or*/
752 /*ampersandequals .emit OPERATOR_ANDASSIGN */
753 /*ampersand .emit OPERATOR_BITAND .or*/
754 /*barequals .emit OPERATOR_ORASSIGN .or*/
755 /*bar .emit OPERATOR_BITOR .or*/
756 /*tilde .emit OPERATOR_COMPLEMENT .or*/
757 /*caretequals .emit OPERATOR_XORASSIGN .or*/
758 caretcaret .emit OPERATOR_LOGICALXOR /*.or
759 caret .emit OPERATOR_BITXOR*/;
762 * <parameter_declarator> ::= <type_specifier> <identifier>
763 * | <type_specifier> <identifier> "[" <constant_expression> "]"
766 parameter_declarator_nospace .or parameter_declarator_space;
767 parameter_declarator_nospace
768 type_specifier_nospace .and identifier .and parameter_declarator_1;
769 parameter_declarator_space
770 type_specifier_space .and space .and identifier .and parameter_declarator_1;
771 parameter_declarator_1
772 parameter_declarator_2 .emit PARAMETER_ARRAY_PRESENT .or
773 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
774 parameter_declarator_2
775 lbracket .and constant_expression .and rbracket;
778 * <parameter_declaration> ::= <type_qualifier> <parameter_qualifier>
779 * <precision> <parameter_declarator>
780 * | <type_qualifier> <parameter_qualifier>
781 * <precision> <parameter_type_specifier>
782 * | <type_qualifier> <parameter_qualifier>
783 * <parameter_declarator>
784 * | <type_qualifier> <parameter_qualifier>
785 * <parameter_type_specifier>
786 * | <parameter_qualifier> <precision>
787 * <parameter_declarator>
788 * | <parameter_qualifier> <precision>
789 * <parameter_type_specifier>
790 * | <parameter_qualifier> <parameter_declarator>
791 * | <parameter_qualifier> <parameter_type_specifier>
793 parameter_declaration
794 parameter_declaration_1 .emit PARAMETER_NEXT;
795 parameter_declaration_1
796 parameter_declaration_2 .or parameter_declaration_3;
797 parameter_declaration_2
798 type_qualifier .and space .and parameter_qualifier .and parameter_declaration_4;
799 parameter_declaration_3
800 parameter_qualifier .emit TYPE_QUALIFIER_NONE .and parameter_declaration_4;
801 parameter_declaration_4
802 parameter_declaration_optprec .and parameter_declaration_rest;
803 parameter_declaration_optprec
804 parameter_declaration_prec .or .true .emit PRECISION_DEFAULT;
805 parameter_declaration_prec
806 precision .and space;
807 parameter_declaration_rest
808 parameter_declarator .or parameter_type_specifier;
811 * <parameter_qualifier> ::= "in"
817 parameter_qualifier_1 .or .true .emit PARAM_QUALIFIER_IN;
818 parameter_qualifier_1
819 parameter_qualifier_2 .and space;
820 parameter_qualifier_2
821 "in" .emit PARAM_QUALIFIER_IN .or
822 "out" .emit PARAM_QUALIFIER_OUT .or
823 "inout" .emit PARAM_QUALIFIER_INOUT;
826 * <parameter_type_specifier> ::= <type_specifier>
827 * | <type_specifier> "[" <constant_expression> "]"
829 parameter_type_specifier
830 parameter_type_specifier_1 .and .true .emit '\0' .and parameter_type_specifier_2;
831 parameter_type_specifier_1
832 type_specifier_nospace .or type_specifier_space;
833 parameter_type_specifier_2
834 parameter_type_specifier_3 .emit PARAMETER_ARRAY_PRESENT .or
835 .true .emit PARAMETER_ARRAY_NOT_PRESENT;
836 parameter_type_specifier_3
837 lbracket .and constant_expression .and rbracket;
840 * <init_declarator_list> ::= <single_declaration>
841 * | <init_declarator_list> "," <identifier>
842 * | <init_declarator_list> "," <identifier> "[" "]"
843 * | <init_declarator_list> "," <identifier> "[" <constant_expression> "]"
844 * | <init_declarator_list> "," <identifier> "=" <initializer>
847 single_declaration .and .loop init_declarator_list_1 .emit DECLARATOR_NEXT .and
848 .true .emit DECLARATOR_NONE;
849 init_declarator_list_1
850 comma .and identifier .emit VARIABLE_IDENTIFIER .and init_declarator_list_2;
851 init_declarator_list_2
852 init_declarator_list_3 .or init_declarator_list_4 .or .true .emit VARIABLE_NONE;
853 init_declarator_list_3
854 equals .and initializer .emit VARIABLE_INITIALIZER;
855 init_declarator_list_4
856 lbracket .and init_declarator_list_5 .and rbracket;
857 init_declarator_list_5
858 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
861 * <single_declaration> ::= <fully_specified_type>
862 * | <fully_specified_type> <identifier>
863 * | <fully_specified_type> <identifier> "[" "]"
864 * | <fully_specified_type> <identifier> "[" <constant_expression> "]"
865 * | <fully_specified_type> <identifier> "=" <initializer>
868 single_declaration_nospace .or single_declaration_space;
869 single_declaration_space
870 fully_specified_type_space .and single_declaration_space_1;
871 single_declaration_nospace
872 fully_specified_type_nospace .and single_declaration_nospace_1;
873 single_declaration_space_1
874 single_declaration_space_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
875 single_declaration_nospace_1
876 single_declaration_nospace_2 .emit VARIABLE_IDENTIFIER .or .true .emit VARIABLE_NONE;
877 single_declaration_space_2
878 space .and identifier .and single_declaration_3;
879 single_declaration_nospace_2
880 identifier .and single_declaration_3;
882 single_declaration_4 .or single_declaration_5 .or .true .emit VARIABLE_NONE;
884 equals .and initializer .emit VARIABLE_INITIALIZER;
886 lbracket .and single_declaration_6 .and rbracket;
888 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
891 * <fully_specified_type> ::= <opt_invariant> <opt_centroid> <opt_qualifer> <opt_precision> <type_specifier> <opt_array_size>
893 * Example: "invariant varying highp vec3 [4]"
895 * Note that the *_space version doesn't parse the array size, make sure it is being invoked after the *_nospace version.
897 fully_specified_type_space
898 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;
899 fully_specified_type_nospace
900 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_array;
902 type_specifier_array_1 .or type_specifier_array_2;
903 type_specifier_array_1
904 type_specifier_space .and array_size;
905 type_specifier_array_2
906 type_specifier_nospace .and opt_array_size;
907 fully_specified_type_optinvariant
908 fully_specified_type_invariant .or .true .emit TYPE_VARIANT;
909 fully_specified_type_invariant
910 invariant_qualifier .and space;
911 fully_specified_type_optcentroid
912 fully_specified_type_centroid .or .true .emit TYPE_CENTER;
913 fully_specified_type_centroid
914 centroid_qualifier .and space;
915 fully_specified_type_optqual
916 fully_specified_type_qual .or .true .emit TYPE_QUALIFIER_NONE;
917 fully_specified_type_qual
918 type_qualifier .and space;
919 fully_specified_type_optprec
920 fully_specified_type_prec .or .true .emit PRECISION_DEFAULT;
921 fully_specified_type_prec
922 precision .and space;
924 array_size .or .true .emit TYPE_NO_ARRAY_SIZE;
926 lbracket .emit TYPE_ARRAY_SIZE .and constant_expression .and rbracket;
930 * <invariant_qualifier> ::= "invariant"
933 "invariant" .emit TYPE_INVARIANT;
936 "centroid" .emit TYPE_CENTROID;
940 * <type_qualifier> ::= "const"
941 * | "attribute" // Vertex only.
947 * note: this is an extension to the standard language specification,
948 * normally slang disallows __fixed_output and __fixed_input type qualifiers
951 "const" .emit TYPE_QUALIFIER_CONST .or
952 .if (shader_type == 2) "attribute" .emit TYPE_QUALIFIER_ATTRIBUTE .or
953 "varying" .emit TYPE_QUALIFIER_VARYING .or
954 "uniform" .emit TYPE_QUALIFIER_UNIFORM .or
955 .if (parsing_builtin != 0) "__fixed_output" .emit TYPE_QUALIFIER_FIXEDOUTPUT .or
956 .if (parsing_builtin != 0) "__fixed_input" .emit TYPE_QUALIFIER_FIXEDINPUT;
959 * <type_specifier> ::= "void"
985 * | "sampler1DShadow"
986 * | "sampler2DShadow"
988 * | "sampler2DRectShadow"
989 * | <struct_specifier>
993 "void" .emit TYPE_SPECIFIER_VOID .or
994 "float" .emit TYPE_SPECIFIER_FLOAT .or
995 "int" .emit TYPE_SPECIFIER_INT .or
996 "bool" .emit TYPE_SPECIFIER_BOOL .or
997 "vec2" .emit TYPE_SPECIFIER_VEC2 .or
998 "vec3" .emit TYPE_SPECIFIER_VEC3 .or
999 "vec4" .emit TYPE_SPECIFIER_VEC4 .or
1000 "bvec2" .emit TYPE_SPECIFIER_BVEC2 .or
1001 "bvec3" .emit TYPE_SPECIFIER_BVEC3 .or
1002 "bvec4" .emit TYPE_SPECIFIER_BVEC4 .or
1003 "ivec2" .emit TYPE_SPECIFIER_IVEC2 .or
1004 "ivec3" .emit TYPE_SPECIFIER_IVEC3 .or
1005 "ivec4" .emit TYPE_SPECIFIER_IVEC4 .or
1006 "mat2" .emit TYPE_SPECIFIER_MAT2 .or
1007 "mat3" .emit TYPE_SPECIFIER_MAT3 .or
1008 "mat4" .emit TYPE_SPECIFIER_MAT4 .or
1009 "mat2x3" .emit TYPE_SPECIFIER_MAT23 .or
1010 "mat3x2" .emit TYPE_SPECIFIER_MAT32 .or
1011 "mat2x4" .emit TYPE_SPECIFIER_MAT24 .or
1012 "mat4x2" .emit TYPE_SPECIFIER_MAT42 .or
1013 "mat3x4" .emit TYPE_SPECIFIER_MAT34 .or
1014 "mat4x3" .emit TYPE_SPECIFIER_MAT43 .or
1015 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1016 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1017 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1018 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1019 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1020 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1021 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1022 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW .or
1023 type_name .emit TYPE_SPECIFIER_TYPENAME;
1024 type_specifier_nospace
1025 struct_specifier .emit TYPE_SPECIFIER_STRUCT;
1028 * <struct_specifier> ::= "struct" <identifier> "{" <struct_declaration_list> "}"
1029 * | "struct" "{" <struct_declaration_list> "}"
1032 "struct" .and struct_specifier_1 .and optional_space .and lbrace .error LBRACE_EXPECTED .and
1033 struct_declaration_list .and rbrace .emit FIELD_NONE;
1035 struct_specifier_2 .or .true .emit '\0';
1037 space .and identifier;
1040 * <struct_declaration_list> ::= <struct_declaration>
1041 * | <struct_declaration_list> <struct_declaration>
1043 struct_declaration_list
1044 struct_declaration .and .loop struct_declaration .emit FIELD_NEXT;
1047 * <struct_declaration> ::= <type_specifier> <struct_declarator_list> ";"
1050 struct_declaration_nospace .or struct_declaration_space;
1051 struct_declaration_space
1052 type_specifier_space .and space .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1053 struct_declaration_nospace
1054 type_specifier_nospace .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1057 * <struct_declarator_list> ::= <struct_declarator>
1058 * | <struct_declarator_list> "," <struct_declarator>
1060 struct_declarator_list
1061 struct_declarator .and .loop struct_declarator_list_1 .emit FIELD_NEXT;
1062 struct_declarator_list_1
1063 comma .and struct_declarator;
1066 * <struct_declarator> ::= <identifier>
1067 * | <identifier> "[" <constant_expression> "]"
1070 identifier .and struct_declarator_1;
1072 struct_declarator_2 .emit FIELD_ARRAY .or .true .emit FIELD_NONE;
1074 lbracket .and constant_expression .and rbracket;
1077 * <initializer> ::= <assignment_expression>
1080 assignment_expression .and .true .emit OP_END;
1083 * <declaration_statement> ::= <declaration>
1085 declaration_statement
1089 * <statement> ::= <compound_statement>
1090 * | <simple_statement>
1093 compound_statement .or simple_statement;
1095 compound_statement .or statement_space_1;
1097 space .and simple_statement;
1100 * <simple_statement> ::= <__asm_statement>
1101 * | <selection_statement>
1102 * | <iteration_statement>
1103 * | <jump_statement>
1104 * | <expression_statement>
1105 * | <declaration_statement>
1107 * note: this is an extension to the standard language specification.
1108 * normally slang disallows use of __asm statements
1111 .if (parsing_builtin != 0) __asm_statement .emit OP_ASM .or
1112 selection_statement .or
1113 iteration_statement .or
1114 precision_stmt .emit OP_PRECISION .or
1116 expression_statement .emit OP_EXPRESSION .or
1117 declaration_statement .emit OP_DECLARE;
1120 * <compound_statement> ::= "{" "}"
1121 * | "{" <statement_list> "}"
1124 compound_statement_1 .emit OP_BLOCK_BEGIN_NEW_SCOPE .and .true .emit OP_END;
1125 compound_statement_1
1126 compound_statement_2 .or compound_statement_3;
1127 compound_statement_2
1129 compound_statement_3
1130 lbrace .and statement_list .and rbrace;
1133 * <statement_no_new_scope> ::= <compound_statement_no_new_scope>
1134 * | <simple_statement>
1136 statement_no_new_scope
1137 compound_statement_no_new_scope .or simple_statement;
1140 * <compound_statement_no_new_scope> ::= "{" "}"
1141 * | "{" <statement_list> "}"
1143 compound_statement_no_new_scope
1144 compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;
1145 compound_statement_no_new_scope_1
1146 compound_statement_no_new_scope_2 .or compound_statement_no_new_scope_3;
1147 compound_statement_no_new_scope_2
1149 compound_statement_no_new_scope_3
1150 lbrace .and statement_list .and rbrace;
1153 * <statement_list> ::= <statement>
1154 * | <statement_list> <statement>
1157 statement .and .loop statement;
1160 * <expression_statement> ::= ";"
1161 * | <expression> ";"
1163 expression_statement
1164 expression_statement_1 .or expression_statement_2;
1165 expression_statement_1
1166 semicolon .emit OP_PUSH_VOID .emit OP_END;
1167 expression_statement_2
1168 expression .and semicolon .emit OP_END;
1171 * <selection_statement> ::= "if" "(" <expression> ")" <selection_rest_statement>
1174 "if" .emit OP_IF .and lparen .error LPAREN_EXPECTED .and expression .and
1175 rparen .error RPAREN_EXPECTED .emit OP_END .and selection_rest_statement;
1178 * <selection_rest_statement> ::= <statement> "else" <statement>
1181 selection_rest_statement
1182 statement .and selection_rest_statement_1;
1183 selection_rest_statement_1
1184 selection_rest_statement_2 .or .true .emit OP_EXPRESSION .emit OP_PUSH_VOID .emit OP_END;
1185 selection_rest_statement_2
1186 "else" .and optional_space .and statement;
1189 * <condition> ::= <expression>
1190 * | <fully_specified_type> <identifier> "=" <initializer>
1192 * note: if <condition_1> is executed, the emit format must
1193 * match <declaration> emit format
1196 condition_1 .emit OP_DECLARE .emit DECLARATION_INIT_DECLARATOR_LIST .or
1197 condition_3 .emit OP_EXPRESSION;
1199 condition_1_nospace .or condition_1_space;
1201 fully_specified_type_nospace .and condition_2;
1203 fully_specified_type_space .and space .and condition_2;
1205 identifier .emit VARIABLE_IDENTIFIER .and equals .emit VARIABLE_INITIALIZER .and
1206 initializer .and .true .emit DECLARATOR_NONE;
1208 expression .and .true .emit OP_END;
1211 * <iteration_statement> ::= "while" "(" <condition> ")" <statement>
1212 * | "do" <statement> "while" "(" <expression> ")" ";"
1213 * | "for" "(" <for_init_statement> <for_rest_statement> ")"
1214 * <statement_no_new_scope>
1217 iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3;
1218 iteration_statement_1
1219 "while" .emit OP_WHILE .and lparen .error LPAREN_EXPECTED .and condition .and
1220 rparen .error RPAREN_EXPECTED .and statement;
1221 iteration_statement_2
1222 "do" .emit OP_DO .and statement_space .and "while" .and lparen .error LPAREN_EXPECTED .and
1223 expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;
1224 iteration_statement_3
1225 "for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and
1226 for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
1229 * <for_init_statement> ::= <expression_statement>
1230 * | <declaration_statement>
1233 expression_statement .emit OP_EXPRESSION .or declaration_statement .emit OP_DECLARE;
1236 * <conditionopt> ::= <condition>
1239 * note: <conditionopt> is used only by "for" statement.
1240 * if <condition> is ommitted, parser simulates default behaviour,
1241 * that is simulates "true" expression
1245 .true .emit OP_EXPRESSION .emit OP_PUSH_BOOL .emit 2 .emit '1' .emit '\0' .emit OP_END;
1248 * <for_rest_statement> ::= <conditionopt> ";"
1249 * | <conditionopt> ";" <expression>
1252 conditionopt .and semicolon .and for_rest_statement_1;
1253 for_rest_statement_1
1254 for_rest_statement_2 .or .true .emit OP_PUSH_VOID .emit OP_END;
1255 for_rest_statement_2
1256 expression .and .true .emit OP_END;
1259 * <jump_statement> ::= "continue" ";"
1262 * | "return" <expression> ";"
1263 * | "discard" ";" // Fragment shader only.
1266 jump_statement_1 .or jump_statement_2 .or jump_statement_3 .or jump_statement_4 .or
1267 .if (shader_type == 1) jump_statement_5;
1269 "continue" .and semicolon .emit OP_CONTINUE;
1271 "break" .and semicolon .emit OP_BREAK;
1273 "return" .emit OP_RETURN .and optional_space .and expression .and semicolon .emit OP_END;
1275 "return" .emit OP_RETURN .and semicolon .emit OP_PUSH_VOID .emit OP_END;
1277 "discard" .and semicolon .emit OP_DISCARD;
1280 * <__asm_statement> ::= "__asm" <identifier> <asm_arguments> ";"
1282 * note: this is an extension to the standard language specification.
1283 * normally slang disallows __asm statements
1286 "__asm" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END;
1289 * <asm_arguments> ::= <asm_argument>
1290 * | <asm_arguments> "," <asm_argument>
1292 * note: this is an extension to the standard language specification.
1293 * normally slang disallows __asm statements
1296 asm_argument .and .true .emit OP_END .and .loop asm_arguments_1;
1298 comma .and asm_argument .and .true .emit OP_END;
1301 * <asm_argument> ::= <variable_identifier>
1304 * note: this is an extension to the standard language specification.
1305 * normally slang disallows __asm statements
1309 variable_identifier .or
1313 variable_identifier .and dot .and field_selection .emit OP_FIELD;
1317 * <translation_unit> ::= <external_declaration>
1318 * | <translation_unit> <external_declaration>
1321 optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and
1322 .loop external_declaration .and optional_space .and
1323 '\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL;
1327 * <external_declaration> ::= <function_definition>
1330 external_declaration
1331 precision_stmt .emit DEFAULT_PRECISION .or
1332 function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or
1333 invariant_stmt .emit INVARIANT_STMT .or
1334 declaration .emit EXTERNAL_DECLARATION;
1338 * <precision_stmt> ::= "precision" <precision> <prectype>
1341 "precision" .and space .and precision .error INVALID_PRECISION .and space .and prectype .error INVALID_PRECISION_TYPE .and semicolon;
1344 * <precision> ::= "lowp"
1349 "lowp" .emit PRECISION_LOW .or
1350 "mediump" .emit PRECISION_MEDIUM .or
1351 "highp" .emit PRECISION_HIGH;
1354 * <prectype> ::= "int"
1356 * | "a sampler type"
1359 "int" .emit TYPE_SPECIFIER_INT .or
1360 "float" .emit TYPE_SPECIFIER_FLOAT .or
1361 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1362 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1363 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1364 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1365 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1366 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1367 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1368 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW;
1372 * <invariant_stmt> ::= "invariant" identifier;
1375 "invariant" .and space .and identifier .and semicolon;
1379 * <function_definition> :: <function_prototype> <compound_statement_no_new_scope>
1382 function_prototype .and compound_statement_no_new_scope;
1387 * helper rules, not part of the official language syntax
1397 '0'-'9' .or 'A'-'F' .or 'a'-'f';
1400 'a'-'z' .or 'A'-'Z' .or '_';
1403 id_character_first .or digit_dec;
1406 id_character_first .emit * .and .loop id_character_next .emit * .and .true .emit '\0';
1409 float_1 .or float_2 .or float_3;
1411 float_fractional_constant .and float_optional_exponent_part .and optional_f_suffix;
1413 float_digit_sequence .and .true .emit '\0' .and float_exponent_part .and optional_f_suffix;
1415 float_digit_sequence .and .true .emit '\0' .and 'f' .emit '\0';
1417 float_fractional_constant
1418 float_fractional_constant_1 .or float_fractional_constant_2 .or float_fractional_constant_3;
1419 float_fractional_constant_1
1420 float_digit_sequence .and '.' .and float_digit_sequence;
1421 float_fractional_constant_2
1422 float_digit_sequence .and '.' .and .true .emit '\0';
1423 float_fractional_constant_3
1424 '.' .emit '\0' .and float_digit_sequence;
1426 float_optional_exponent_part
1427 float_exponent_part .or .true .emit '\0';
1429 float_digit_sequence
1430 digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1433 float_exponent_part_1 .or float_exponent_part_2;
1434 float_exponent_part_1
1435 'e' .and float_optional_sign .and float_digit_sequence;
1436 float_exponent_part_2
1437 'E' .and float_optional_sign .and float_digit_sequence;
1440 float_sign .or .true;
1443 '+' .or '-' .emit '-';
1450 integer_hex .or integer_oct .or integer_dec;
1453 '0' .and integer_hex_1 .emit 0x10 .and digit_hex .emit * .and .loop digit_hex .emit * .and
1459 '0' .emit 8 .emit * .and .loop digit_oct .emit * .and .true .emit '\0';
1462 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1465 "true" .emit 2 .emit '1' .emit '\0' .or
1466 "false" .emit 2 .emit '0' .emit '\0';
1475 float .emit OP_PUSH_FLOAT;
1478 integer .emit OP_PUSH_INT;
1481 boolean .emit OP_PUSH_BOOL;
1487 single_space .and .loop single_space;
1490 white_char .or c_style_comment_block .or cpp_style_comment_block;
1493 ' ' .or '\t' .or new_line .or '\v' .or '\f';
1496 cr_lf .or lf_cr .or '\n' .or '\r';
1504 c_style_comment_block
1505 '/' .and '*' .and c_style_comment_rest;
1507 c_style_comment_rest
1508 .loop c_style_comment_char_no_star .and c_style_comment_rest_1;
1509 c_style_comment_rest_1
1510 c_style_comment_end .or c_style_comment_rest_2;
1511 c_style_comment_rest_2
1512 '*' .and c_style_comment_rest;
1514 c_style_comment_char_no_star
1515 '\x2B'-'\xFF' .or '\x01'-'\x29';
1520 cpp_style_comment_block
1521 '/' .and '/' .and cpp_style_comment_block_1;
1522 cpp_style_comment_block_1
1523 cpp_style_comment_block_2 .or cpp_style_comment_block_3;
1524 cpp_style_comment_block_2
1525 .loop cpp_style_comment_char .and new_line;
1526 cpp_style_comment_block_3
1527 .loop cpp_style_comment_char;
1529 cpp_style_comment_char
1530 '\x0E'-'\xFF' .or '\x01'-'\x09' .or '\x0B'-'\x0C';
1535 optional_space .and '&' .and optional_space;*/
1538 optional_space .and '&' .and '&' .and optional_space;
1541 optional_space .and '&' .and '=' .and optional_space;*/
1544 optional_space .and '|' .and optional_space;*/
1547 optional_space .and '|' .and '|' .and optional_space;
1550 optional_space .and '|' .and '=' .and optional_space;*/
1553 optional_space .and '!' .and optional_space;
1556 optional_space .and '!' .and '=' .and optional_space;
1559 optional_space .and '^' .and optional_space;*/
1562 optional_space .and '^' .and '^' .and optional_space;
1565 optional_space .and '^' .and '=' .and optional_space;*/
1568 optional_space .and ':' .and optional_space;
1571 optional_space .and ',' .and optional_space;
1574 optional_space .and '.' .and optional_space;
1577 optional_space .and '=' .and optional_space;
1580 optional_space .and '=' .and '=' .and optional_space;
1583 optional_space .and '>' .and optional_space;
1586 optional_space .and '>' .and '=' .and optional_space;
1589 optional_space .and '>' .and '>' .and optional_space;*/
1591 /*greatergreaterequals
1592 optional_space .and '>' .and '>' .and '=' .and optional_space;*/
1595 optional_space .and '{' .and optional_space;
1598 optional_space .and '[' .and optional_space;
1601 optional_space .and '<' .and optional_space;
1604 optional_space .and '<' .and '=' .and optional_space;
1607 optional_space .and '<' .and '<' .and optional_space;*/
1610 optional_space .and '<' .and '<' .and '=' .and optional_space;*/
1613 optional_space .and '(' .and optional_space;
1616 optional_space .and '-' .and optional_space;
1619 optional_space .and '-' .and '=' .and optional_space;
1622 optional_space .and '-' .and '-' .and optional_space;
1625 optional_space .and '%' .and optional_space;*/
1628 optional_space .and '%' .and '=' .and optional_space;*/
1631 optional_space .and '+' .and optional_space;
1634 optional_space .and '+' .and '=' .and optional_space;
1637 optional_space .and '+' .and '+' .and optional_space;
1640 optional_space .and '?' .and optional_space;
1643 optional_space .and '}' .and optional_space;
1646 optional_space .and ']' .and optional_space;
1649 optional_space .and ')' .and optional_space;
1652 optional_space .and ';' .and optional_space;
1655 optional_space .and '/' .and optional_space;
1658 optional_space .and '/' .and '=' .and optional_space;
1661 optional_space .and '*' .and optional_space;
1664 optional_space .and '*' .and '=' .and optional_space;
1667 optional_space .and '~' .and optional_space;*/
1669 /* string rules - these are used internally by the parser when parsing quoted strings */
1671 .string string_lexer;
1674 lex_first_identifier_character .and .loop lex_next_identifier_character;
1676 lex_first_identifier_character
1677 'a'-'z' .or 'A'-'Z' .or '_';
1679 lex_next_identifier_character
1680 'a'-'z' .or 'A'-'Z' .or '0'-'9' .or '_';
1682 /* error rules - these are used by error messages */
1685 '~' .or '`' .or '!' .or '@' .or '#' .or '$' .or '%' .or '^' .or '&' .or '*' .or '(' .or ')' .or
1686 '-' .or '+' .or '=' .or '|' .or '\\' .or '[' .or ']' .or '{' .or '}' .or ':' .or ';' .or '"' .or
1687 '\'' .or '<' .or ',' .or '>' .or '.' .or '/' .or '?' .or err_identifier;
1690 id_character_first .and .loop id_character_next;