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