Merge commit 'origin/gallium-0.1' into gallium-0.2
[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> "["
841 * <constant_expression> "]"
842 * | <init_declarator_list> "," <identifier> "="
843 * <initializer>
844 */
845 init_declarator_list
846 single_declaration .and .loop init_declarator_list_1 .emit DECLARATOR_NEXT .and
847 .true .emit DECLARATOR_NONE;
848 init_declarator_list_1
849 comma .and identifier .emit VARIABLE_IDENTIFIER .and init_declarator_list_2;
850 init_declarator_list_2
851 init_declarator_list_3 .or init_declarator_list_4 .or .true .emit VARIABLE_NONE;
852 init_declarator_list_3
853 equals .and initializer .emit VARIABLE_INITIALIZER;
854 init_declarator_list_4
855 lbracket .and init_declarator_list_5 .and rbracket;
856 init_declarator_list_5
857 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
858
859 /*
860 * <single_declaration> ::= <fully_specified_type>
861 * | <fully_specified_type> <identifier>
862 * | <fully_specified_type> <identifier> "[" "]"
863 * | <fully_specified_type> <identifier> "["
864 * <constant_expression> "]"
865 * | <fully_specified_type> <identifier> "=" <initializer>
866 */
867 single_declaration
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;
881 single_declaration_3
882 single_declaration_4 .or single_declaration_5 .or .true .emit VARIABLE_NONE;
883 single_declaration_4
884 equals .and initializer .emit VARIABLE_INITIALIZER;
885 single_declaration_5
886 lbracket .and single_declaration_6 .and rbracket;
887 single_declaration_6
888 constant_expression .emit VARIABLE_ARRAY_EXPLICIT .or .true .emit VARIABLE_ARRAY_UNKNOWN;
889
890 /*
891 * <fully_specified_type> ::= <opt_invariant> <opt_centroid> <opt_qualifer> <opt_precision> <type_specifier>
892 *
893 * Example: "invariant varying highp vec3"
894 */
895 fully_specified_type_space
896 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_space;
897 fully_specified_type_nospace
898 fully_specified_type_optinvariant .and fully_specified_type_optcentroid .and fully_specified_type_optqual .and fully_specified_type_optprec .and type_specifier_nospace;
899 fully_specified_type_optinvariant
900 fully_specified_type_invariant .or .true .emit TYPE_VARIANT;
901 fully_specified_type_invariant
902 invariant_qualifier .and space;
903 fully_specified_type_optcentroid
904 fully_specified_type_centroid .or .true .emit TYPE_CENTER;
905 fully_specified_type_centroid
906 centroid_qualifier .and space;
907 fully_specified_type_optqual
908 fully_specified_type_qual .or .true .emit TYPE_QUALIFIER_NONE;
909 fully_specified_type_qual
910 type_qualifier .and space;
911 fully_specified_type_optprec
912 fully_specified_type_prec .or .true .emit PRECISION_DEFAULT;
913 fully_specified_type_prec
914 precision .and space;
915
916 /*
917 * <invariant_qualifier> ::= "invariant"
918 */
919 invariant_qualifier
920 "invariant" .emit TYPE_INVARIANT;
921
922 centroid_qualifier
923 "centroid" .emit TYPE_CENTROID;
924
925
926 /*
927 * <type_qualifier> ::= "const"
928 * | "attribute" // Vertex only.
929 * | "varying"
930 * | "uniform"
931 * | "__fixed_output"
932 * | "__fixed_input"
933 *
934 * note: this is an extension to the standard language specification,
935 * normally slang disallows __fixed_output and __fixed_input type qualifiers
936 */
937 type_qualifier
938 "const" .emit TYPE_QUALIFIER_CONST .or
939 .if (shader_type == 2) "attribute" .emit TYPE_QUALIFIER_ATTRIBUTE .or
940 "varying" .emit TYPE_QUALIFIER_VARYING .or
941 "uniform" .emit TYPE_QUALIFIER_UNIFORM .or
942 .if (parsing_builtin != 0) "__fixed_output" .emit TYPE_QUALIFIER_FIXEDOUTPUT .or
943 .if (parsing_builtin != 0) "__fixed_input" .emit TYPE_QUALIFIER_FIXEDINPUT;
944
945 /*
946 * <type_specifier> ::= "void"
947 * | "float"
948 * | "int"
949 * | "bool"
950 * | "vec2"
951 * | "vec3"
952 * | "vec4"
953 * | "bvec2"
954 * | "bvec3"
955 * | "bvec4"
956 * | "ivec2"
957 * | "ivec3"
958 * | "ivec4"
959 * | "mat2"
960 * | "mat3"
961 * | "mat4"
962 * | "mat2x3"
963 * | "mat3x2"
964 * | "mat2x4"
965 * | "mat4x2"
966 * | "mat3x4"
967 * | "mat4x3"
968 * | "sampler1D"
969 * | "sampler2D"
970 * | "sampler3D"
971 * | "samplerCube"
972 * | "sampler1DShadow"
973 * | "sampler2DShadow"
974 * | "sampler2DRect"
975 * | "sampler2DRectShadow"
976 * | <struct_specifier>
977 * | <type_name>
978 */
979 type_specifier_space
980 "void" .emit TYPE_SPECIFIER_VOID .or
981 "float" .emit TYPE_SPECIFIER_FLOAT .or
982 "int" .emit TYPE_SPECIFIER_INT .or
983 "bool" .emit TYPE_SPECIFIER_BOOL .or
984 "vec2" .emit TYPE_SPECIFIER_VEC2 .or
985 "vec3" .emit TYPE_SPECIFIER_VEC3 .or
986 "vec4" .emit TYPE_SPECIFIER_VEC4 .or
987 "bvec2" .emit TYPE_SPECIFIER_BVEC2 .or
988 "bvec3" .emit TYPE_SPECIFIER_BVEC3 .or
989 "bvec4" .emit TYPE_SPECIFIER_BVEC4 .or
990 "ivec2" .emit TYPE_SPECIFIER_IVEC2 .or
991 "ivec3" .emit TYPE_SPECIFIER_IVEC3 .or
992 "ivec4" .emit TYPE_SPECIFIER_IVEC4 .or
993 "mat2" .emit TYPE_SPECIFIER_MAT2 .or
994 "mat3" .emit TYPE_SPECIFIER_MAT3 .or
995 "mat4" .emit TYPE_SPECIFIER_MAT4 .or
996 "mat2x3" .emit TYPE_SPECIFIER_MAT23 .or
997 "mat3x2" .emit TYPE_SPECIFIER_MAT32 .or
998 "mat2x4" .emit TYPE_SPECIFIER_MAT24 .or
999 "mat4x2" .emit TYPE_SPECIFIER_MAT42 .or
1000 "mat3x4" .emit TYPE_SPECIFIER_MAT34 .or
1001 "mat4x3" .emit TYPE_SPECIFIER_MAT43 .or
1002 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1003 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1004 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1005 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1006 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1007 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1008 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1009 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW .or
1010 type_name .emit TYPE_SPECIFIER_TYPENAME;
1011 type_specifier_nospace
1012 struct_specifier .emit TYPE_SPECIFIER_STRUCT;
1013
1014 /*
1015 * <struct_specifier> ::= "struct" <identifier> "{" <struct_declaration_list> "}"
1016 * | "struct" "{" <struct_declaration_list> "}"
1017 */
1018 struct_specifier
1019 "struct" .and struct_specifier_1 .and optional_space .and lbrace .error LBRACE_EXPECTED .and
1020 struct_declaration_list .and rbrace .emit FIELD_NONE;
1021 struct_specifier_1
1022 struct_specifier_2 .or .true .emit '\0';
1023 struct_specifier_2
1024 space .and identifier;
1025
1026 /*
1027 * <struct_declaration_list> ::= <struct_declaration>
1028 * | <struct_declaration_list> <struct_declaration>
1029 */
1030 struct_declaration_list
1031 struct_declaration .and .loop struct_declaration .emit FIELD_NEXT;
1032
1033 /*
1034 * <struct_declaration> ::= <type_specifier> <struct_declarator_list> ";"
1035 */
1036 struct_declaration
1037 struct_declaration_nospace .or struct_declaration_space;
1038 struct_declaration_space
1039 type_specifier_space .and space .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1040 struct_declaration_nospace
1041 type_specifier_nospace .and struct_declarator_list .and semicolon .emit FIELD_NONE;
1042
1043 /*
1044 * <struct_declarator_list> ::= <struct_declarator>
1045 * | <struct_declarator_list> "," <struct_declarator>
1046 */
1047 struct_declarator_list
1048 struct_declarator .and .loop struct_declarator_list_1 .emit FIELD_NEXT;
1049 struct_declarator_list_1
1050 comma .and struct_declarator;
1051
1052 /*
1053 * <struct_declarator> ::= <identifier>
1054 * | <identifier> "[" <constant_expression> "]"
1055 */
1056 struct_declarator
1057 identifier .and struct_declarator_1;
1058 struct_declarator_1
1059 struct_declarator_2 .emit FIELD_ARRAY .or .true .emit FIELD_NONE;
1060 struct_declarator_2
1061 lbracket .and constant_expression .and rbracket;
1062
1063 /*
1064 * <initializer> ::= <assignment_expression>
1065 */
1066 initializer
1067 assignment_expression .and .true .emit OP_END;
1068
1069 /*
1070 * <declaration_statement> ::= <declaration>
1071 */
1072 declaration_statement
1073 declaration;
1074
1075 /*
1076 * <statement> ::= <compound_statement>
1077 * | <simple_statement>
1078 */
1079 statement
1080 compound_statement .or simple_statement;
1081 statement_space
1082 compound_statement .or statement_space_1;
1083 statement_space_1
1084 space .and simple_statement;
1085
1086 /*
1087 * <simple_statement> ::= <__asm_statement>
1088 * | <selection_statement>
1089 * | <iteration_statement>
1090 * | <jump_statement>
1091 * | <expression_statement>
1092 * | <declaration_statement>
1093 *
1094 * note: this is an extension to the standard language specification.
1095 * normally slang disallows use of __asm statements
1096 */
1097 simple_statement
1098 .if (parsing_builtin != 0) __asm_statement .emit OP_ASM .or
1099 selection_statement .or
1100 iteration_statement .or
1101 precision_stmt .emit OP_PRECISION .or
1102 jump_statement .or
1103 expression_statement .emit OP_EXPRESSION .or
1104 declaration_statement .emit OP_DECLARE;
1105
1106 /*
1107 * <compound_statement> ::= "{" "}"
1108 * | "{" <statement_list> "}"
1109 */
1110 compound_statement
1111 compound_statement_1 .emit OP_BLOCK_BEGIN_NEW_SCOPE .and .true .emit OP_END;
1112 compound_statement_1
1113 compound_statement_2 .or compound_statement_3;
1114 compound_statement_2
1115 lbrace .and rbrace;
1116 compound_statement_3
1117 lbrace .and statement_list .and rbrace;
1118
1119 /*
1120 * <statement_no_new_scope> ::= <compound_statement_no_new_scope>
1121 * | <simple_statement>
1122 */
1123 statement_no_new_scope
1124 compound_statement_no_new_scope .or simple_statement;
1125
1126 /*
1127 * <compound_statement_no_new_scope> ::= "{" "}"
1128 * | "{" <statement_list> "}"
1129 */
1130 compound_statement_no_new_scope
1131 compound_statement_no_new_scope_1 .emit OP_BLOCK_BEGIN_NO_NEW_SCOPE .and .true .emit OP_END;
1132 compound_statement_no_new_scope_1
1133 compound_statement_no_new_scope_2 .or compound_statement_no_new_scope_3;
1134 compound_statement_no_new_scope_2
1135 lbrace .and rbrace;
1136 compound_statement_no_new_scope_3
1137 lbrace .and statement_list .and rbrace;
1138
1139 /*
1140 * <statement_list> ::= <statement>
1141 * | <statement_list> <statement>
1142 */
1143 statement_list
1144 statement .and .loop statement;
1145
1146 /*
1147 * <expression_statement> ::= ";"
1148 * | <expression> ";"
1149 */
1150 expression_statement
1151 expression_statement_1 .or expression_statement_2;
1152 expression_statement_1
1153 semicolon .emit OP_PUSH_VOID .emit OP_END;
1154 expression_statement_2
1155 expression .and semicolon .emit OP_END;
1156
1157 /*
1158 * <selection_statement> ::= "if" "(" <expression> ")" <selection_rest_statement>
1159 */
1160 selection_statement
1161 "if" .emit OP_IF .and lparen .error LPAREN_EXPECTED .and expression .and
1162 rparen .error RPAREN_EXPECTED .emit OP_END .and selection_rest_statement;
1163
1164 /*
1165 * <selection_rest_statement> ::= <statement> "else" <statement>
1166 * | <statement>
1167 */
1168 selection_rest_statement
1169 statement .and selection_rest_statement_1;
1170 selection_rest_statement_1
1171 selection_rest_statement_2 .or .true .emit OP_EXPRESSION .emit OP_PUSH_VOID .emit OP_END;
1172 selection_rest_statement_2
1173 "else" .and optional_space .and statement;
1174
1175 /*
1176 * <condition> ::= <expression>
1177 * | <fully_specified_type> <identifier> "=" <initializer>
1178 *
1179 * note: if <condition_1> is executed, the emit format must
1180 * match <declaration> emit format
1181 */
1182 condition
1183 condition_1 .emit OP_DECLARE .emit DECLARATION_INIT_DECLARATOR_LIST .or
1184 condition_3 .emit OP_EXPRESSION;
1185 condition_1
1186 condition_1_nospace .or condition_1_space;
1187 condition_1_nospace
1188 fully_specified_type_nospace .and condition_2;
1189 condition_1_space
1190 fully_specified_type_space .and space .and condition_2;
1191 condition_2
1192 identifier .emit VARIABLE_IDENTIFIER .and equals .emit VARIABLE_INITIALIZER .and
1193 initializer .and .true .emit DECLARATOR_NONE;
1194 condition_3
1195 expression .and .true .emit OP_END;
1196
1197 /*
1198 * <iteration_statement> ::= "while" "(" <condition> ")" <statement>
1199 * | "do" <statement> "while" "(" <expression> ")" ";"
1200 * | "for" "(" <for_init_statement> <for_rest_statement> ")"
1201 * <statement_no_new_scope>
1202 */
1203 iteration_statement
1204 iteration_statement_1 .or iteration_statement_2 .or iteration_statement_3;
1205 iteration_statement_1
1206 "while" .emit OP_WHILE .and lparen .error LPAREN_EXPECTED .and condition .and
1207 rparen .error RPAREN_EXPECTED .and statement;
1208 iteration_statement_2
1209 "do" .emit OP_DO .and statement_space .and "while" .and lparen .error LPAREN_EXPECTED .and
1210 expression .and rparen .error RPAREN_EXPECTED .emit OP_END .and semicolon;
1211 iteration_statement_3
1212 "for" .emit OP_FOR .and lparen .error LPAREN_EXPECTED .and for_init_statement .and
1213 for_rest_statement .and rparen .error RPAREN_EXPECTED .and statement_no_new_scope;
1214
1215 /*
1216 * <for_init_statement> ::= <expression_statement>
1217 * | <declaration_statement>
1218 */
1219 for_init_statement
1220 expression_statement .emit OP_EXPRESSION .or declaration_statement .emit OP_DECLARE;
1221
1222 /*
1223 * <conditionopt> ::= <condition>
1224 * | ""
1225 *
1226 * note: <conditionopt> is used only by "for" statement.
1227 * if <condition> is ommitted, parser simulates default behaviour,
1228 * that is simulates "true" expression
1229 */
1230 conditionopt
1231 condition .or
1232 .true .emit OP_EXPRESSION .emit OP_PUSH_BOOL .emit 2 .emit '1' .emit '\0' .emit OP_END;
1233
1234 /*
1235 * <for_rest_statement> ::= <conditionopt> ";"
1236 * | <conditionopt> ";" <expression>
1237 */
1238 for_rest_statement
1239 conditionopt .and semicolon .and for_rest_statement_1;
1240 for_rest_statement_1
1241 for_rest_statement_2 .or .true .emit OP_PUSH_VOID .emit OP_END;
1242 for_rest_statement_2
1243 expression .and .true .emit OP_END;
1244
1245 /*
1246 * <jump_statement> ::= "continue" ";"
1247 * | "break" ";"
1248 * | "return" ";"
1249 * | "return" <expression> ";"
1250 * | "discard" ";" // Fragment shader only.
1251 */
1252 jump_statement
1253 jump_statement_1 .or jump_statement_2 .or jump_statement_3 .or jump_statement_4 .or
1254 .if (shader_type == 1) jump_statement_5;
1255 jump_statement_1
1256 "continue" .and semicolon .emit OP_CONTINUE;
1257 jump_statement_2
1258 "break" .and semicolon .emit OP_BREAK;
1259 jump_statement_3
1260 "return" .emit OP_RETURN .and optional_space .and expression .and semicolon .emit OP_END;
1261 jump_statement_4
1262 "return" .emit OP_RETURN .and semicolon .emit OP_PUSH_VOID .emit OP_END;
1263 jump_statement_5
1264 "discard" .and semicolon .emit OP_DISCARD;
1265
1266 /*
1267 * <__asm_statement> ::= "__asm" <identifier> <asm_arguments> ";"
1268 *
1269 * note: this is an extension to the standard language specification.
1270 * normally slang disallows __asm statements
1271 */
1272 __asm_statement
1273 "__asm" .and space .and identifier .and space .and asm_arguments .and semicolon .emit OP_END;
1274
1275 /*
1276 * <asm_arguments> ::= <asm_argument>
1277 * | <asm_arguments> "," <asm_argument>
1278 *
1279 * note: this is an extension to the standard language specification.
1280 * normally slang disallows __asm statements
1281 */
1282 asm_arguments
1283 asm_argument .and .true .emit OP_END .and .loop asm_arguments_1;
1284 asm_arguments_1
1285 comma .and asm_argument .and .true .emit OP_END;
1286
1287 /*
1288 * <asm_argument> ::= <variable_identifier>
1289 * | <floatconstant>
1290 *
1291 * note: this is an extension to the standard language specification.
1292 * normally slang disallows __asm statements
1293 */
1294 asm_argument
1295 var_with_field .or
1296 variable_identifier .or
1297 floatconstant;
1298
1299 var_with_field
1300 variable_identifier .and dot .and field_selection .emit OP_FIELD;
1301
1302
1303 /*
1304 * <translation_unit> ::= <external_declaration>
1305 * | <translation_unit> <external_declaration>
1306 */
1307 translation_unit
1308 optional_space .emit REVISION .and external_declaration .error INVALID_EXTERNAL_DECLARATION .and
1309 .loop external_declaration .and optional_space .and
1310 '\0' .error INVALID_EXTERNAL_DECLARATION .emit EXTERNAL_NULL;
1311
1312
1313 /*
1314 * <external_declaration> ::= <function_definition>
1315 * | <declaration>
1316 */
1317 external_declaration
1318 precision_stmt .emit DEFAULT_PRECISION .or
1319 function_definition .emit EXTERNAL_FUNCTION_DEFINITION .or
1320 invariant_stmt .emit INVARIANT_STMT .or
1321 declaration .emit EXTERNAL_DECLARATION;
1322
1323
1324 /*
1325 * <precision_stmt> ::= "precision" <precision> <prectype>
1326 */
1327 precision_stmt
1328 "precision" .and space .and precision .error INVALID_PRECISION .and space .and prectype .error INVALID_PRECISION_TYPE .and semicolon;
1329
1330 /*
1331 * <precision> ::= "lowp"
1332 * | "mediump"
1333 * | "highp"
1334 */
1335 precision
1336 "lowp" .emit PRECISION_LOW .or
1337 "mediump" .emit PRECISION_MEDIUM .or
1338 "highp" .emit PRECISION_HIGH;
1339
1340 /*
1341 * <prectype> ::= "int"
1342 * | "float"
1343 * | "a sampler type"
1344 */
1345 prectype
1346 "int" .emit TYPE_SPECIFIER_INT .or
1347 "float" .emit TYPE_SPECIFIER_FLOAT .or
1348 "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
1349 "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
1350 "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
1351 "samplerCube" .emit TYPE_SPECIFIER_SAMPLERCUBE .or
1352 "sampler1DShadow" .emit TYPE_SPECIFIER_SAMPLER1DSHADOW .or
1353 "sampler2DShadow" .emit TYPE_SPECIFIER_SAMPLER2DSHADOW .or
1354 "sampler2DRect" .emit TYPE_SPECIFIER_SAMPLER2DRECT .or
1355 "sampler2DRectShadow" .emit TYPE_SPECIFIER_SAMPLER2DRECTSHADOW;
1356
1357
1358 /*
1359 * <invariant_stmt> ::= "invariant" identifier;
1360 */
1361 invariant_stmt
1362 "invariant" .and space .and identifier .and semicolon;
1363
1364
1365 /*
1366 * <function_definition> :: <function_prototype> <compound_statement_no_new_scope>
1367 */
1368 function_definition
1369 function_prototype .and compound_statement_no_new_scope;
1370
1371
1372
1373 /*
1374 * helper rules, not part of the official language syntax
1375 */
1376
1377 digit_oct
1378 '0'-'7';
1379
1380 digit_dec
1381 '0'-'9';
1382
1383 digit_hex
1384 '0'-'9' .or 'A'-'F' .or 'a'-'f';
1385
1386 id_character_first
1387 'a'-'z' .or 'A'-'Z' .or '_';
1388
1389 id_character_next
1390 id_character_first .or digit_dec;
1391
1392 identifier
1393 id_character_first .emit * .and .loop id_character_next .emit * .and .true .emit '\0';
1394
1395 float
1396 float_1 .or float_2 .or float_3;
1397 float_1
1398 float_fractional_constant .and float_optional_exponent_part .and optional_f_suffix;
1399 float_2
1400 float_digit_sequence .and .true .emit '\0' .and float_exponent_part .and optional_f_suffix;
1401 float_3
1402 float_digit_sequence .and .true .emit '\0' .and 'f' .emit '\0';
1403
1404 float_fractional_constant
1405 float_fractional_constant_1 .or float_fractional_constant_2 .or float_fractional_constant_3;
1406 float_fractional_constant_1
1407 float_digit_sequence .and '.' .and float_digit_sequence;
1408 float_fractional_constant_2
1409 float_digit_sequence .and '.' .and .true .emit '\0';
1410 float_fractional_constant_3
1411 '.' .emit '\0' .and float_digit_sequence;
1412
1413 float_optional_exponent_part
1414 float_exponent_part .or .true .emit '\0';
1415
1416 float_digit_sequence
1417 digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1418
1419 float_exponent_part
1420 float_exponent_part_1 .or float_exponent_part_2;
1421 float_exponent_part_1
1422 'e' .and float_optional_sign .and float_digit_sequence;
1423 float_exponent_part_2
1424 'E' .and float_optional_sign .and float_digit_sequence;
1425
1426 float_optional_sign
1427 float_sign .or .true;
1428
1429 float_sign
1430 '+' .or '-' .emit '-';
1431
1432 optional_f_suffix
1433 'f' .or .true;
1434
1435
1436 integer
1437 integer_hex .or integer_oct .or integer_dec;
1438
1439 integer_hex
1440 '0' .and integer_hex_1 .emit 0x10 .and digit_hex .emit * .and .loop digit_hex .emit * .and
1441 .true .emit '\0';
1442 integer_hex_1
1443 'x' .or 'X';
1444
1445 integer_oct
1446 '0' .emit 8 .emit * .and .loop digit_oct .emit * .and .true .emit '\0';
1447
1448 integer_dec
1449 digit_dec .emit 10 .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
1450
1451 boolean
1452 "true" .emit 2 .emit '1' .emit '\0' .or
1453 "false" .emit 2 .emit '0' .emit '\0';
1454
1455 type_name
1456 identifier;
1457
1458 field_selection
1459 identifier;
1460
1461 floatconstant
1462 float .emit OP_PUSH_FLOAT;
1463
1464 intconstant
1465 integer .emit OP_PUSH_INT;
1466
1467 boolconstant
1468 boolean .emit OP_PUSH_BOOL;
1469
1470 optional_space
1471 .loop single_space;
1472
1473 space
1474 single_space .and .loop single_space;
1475
1476 single_space
1477 white_char .or c_style_comment_block .or cpp_style_comment_block;
1478
1479 white_char
1480 ' ' .or '\t' .or new_line .or '\v' .or '\f';
1481
1482 new_line
1483 cr_lf .or lf_cr .or '\n' .or '\r';
1484
1485 cr_lf
1486 '\r' .and '\n';
1487
1488 lf_cr
1489 '\n' .and '\r';
1490
1491 c_style_comment_block
1492 '/' .and '*' .and c_style_comment_rest;
1493
1494 c_style_comment_rest
1495 .loop c_style_comment_char_no_star .and c_style_comment_rest_1;
1496 c_style_comment_rest_1
1497 c_style_comment_end .or c_style_comment_rest_2;
1498 c_style_comment_rest_2
1499 '*' .and c_style_comment_rest;
1500
1501 c_style_comment_char_no_star
1502 '\x2B'-'\xFF' .or '\x01'-'\x29';
1503
1504 c_style_comment_end
1505 '*' .and '/';
1506
1507 cpp_style_comment_block
1508 '/' .and '/' .and cpp_style_comment_block_1;
1509 cpp_style_comment_block_1
1510 cpp_style_comment_block_2 .or cpp_style_comment_block_3;
1511 cpp_style_comment_block_2
1512 .loop cpp_style_comment_char .and new_line;
1513 cpp_style_comment_block_3
1514 .loop cpp_style_comment_char;
1515
1516 cpp_style_comment_char
1517 '\x0E'-'\xFF' .or '\x01'-'\x09' .or '\x0B'-'\x0C';
1518
1519 /* lexical rules */
1520
1521 /*ampersand
1522 optional_space .and '&' .and optional_space;*/
1523
1524 ampersandampersand
1525 optional_space .and '&' .and '&' .and optional_space;
1526
1527 /*ampersandequals
1528 optional_space .and '&' .and '=' .and optional_space;*/
1529
1530 /*bar
1531 optional_space .and '|' .and optional_space;*/
1532
1533 barbar
1534 optional_space .and '|' .and '|' .and optional_space;
1535
1536 /*barequals
1537 optional_space .and '|' .and '=' .and optional_space;*/
1538
1539 bang
1540 optional_space .and '!' .and optional_space;
1541
1542 bangequals
1543 optional_space .and '!' .and '=' .and optional_space;
1544
1545 /*caret
1546 optional_space .and '^' .and optional_space;*/
1547
1548 caretcaret
1549 optional_space .and '^' .and '^' .and optional_space;
1550
1551 /*caretequals
1552 optional_space .and '^' .and '=' .and optional_space;*/
1553
1554 colon
1555 optional_space .and ':' .and optional_space;
1556
1557 comma
1558 optional_space .and ',' .and optional_space;
1559
1560 dot
1561 optional_space .and '.' .and optional_space;
1562
1563 equals
1564 optional_space .and '=' .and optional_space;
1565
1566 equalsequals
1567 optional_space .and '=' .and '=' .and optional_space;
1568
1569 greater
1570 optional_space .and '>' .and optional_space;
1571
1572 greaterequals
1573 optional_space .and '>' .and '=' .and optional_space;
1574
1575 /*greatergreater
1576 optional_space .and '>' .and '>' .and optional_space;*/
1577
1578 /*greatergreaterequals
1579 optional_space .and '>' .and '>' .and '=' .and optional_space;*/
1580
1581 lbrace
1582 optional_space .and '{' .and optional_space;
1583
1584 lbracket
1585 optional_space .and '[' .and optional_space;
1586
1587 less
1588 optional_space .and '<' .and optional_space;
1589
1590 lessequals
1591 optional_space .and '<' .and '=' .and optional_space;
1592
1593 /*lessless
1594 optional_space .and '<' .and '<' .and optional_space;*/
1595
1596 /*lesslessequals
1597 optional_space .and '<' .and '<' .and '=' .and optional_space;*/
1598
1599 lparen
1600 optional_space .and '(' .and optional_space;
1601
1602 minus
1603 optional_space .and '-' .and optional_space;
1604
1605 minusequals
1606 optional_space .and '-' .and '=' .and optional_space;
1607
1608 minusminus
1609 optional_space .and '-' .and '-' .and optional_space;
1610
1611 /*percent
1612 optional_space .and '%' .and optional_space;*/
1613
1614 /*percentequals
1615 optional_space .and '%' .and '=' .and optional_space;*/
1616
1617 plus
1618 optional_space .and '+' .and optional_space;
1619
1620 plusequals
1621 optional_space .and '+' .and '=' .and optional_space;
1622
1623 plusplus
1624 optional_space .and '+' .and '+' .and optional_space;
1625
1626 question
1627 optional_space .and '?' .and optional_space;
1628
1629 rbrace
1630 optional_space .and '}' .and optional_space;
1631
1632 rbracket
1633 optional_space .and ']' .and optional_space;
1634
1635 rparen
1636 optional_space .and ')' .and optional_space;
1637
1638 semicolon
1639 optional_space .and ';' .and optional_space;
1640
1641 slash
1642 optional_space .and '/' .and optional_space;
1643
1644 slashequals
1645 optional_space .and '/' .and '=' .and optional_space;
1646
1647 star
1648 optional_space .and '*' .and optional_space;
1649
1650 starequals
1651 optional_space .and '*' .and '=' .and optional_space;
1652
1653 /*tilde
1654 optional_space .and '~' .and optional_space;*/
1655
1656 /* string rules - these are used internally by the parser when parsing quoted strings */
1657
1658 .string string_lexer;
1659
1660 string_lexer
1661 lex_first_identifier_character .and .loop lex_next_identifier_character;
1662
1663 lex_first_identifier_character
1664 'a'-'z' .or 'A'-'Z' .or '_';
1665
1666 lex_next_identifier_character
1667 'a'-'z' .or 'A'-'Z' .or '0'-'9' .or '_';
1668
1669 /* error rules - these are used by error messages */
1670
1671 err_token
1672 '~' .or '`' .or '!' .or '@' .or '#' .or '$' .or '%' .or '^' .or '&' .or '*' .or '(' .or ')' .or
1673 '-' .or '+' .or '=' .or '|' .or '\\' .or '[' .or ']' .or '{' .or '}' .or ':' .or ';' .or '"' .or
1674 '\'' .or '<' .or ',' .or '>' .or '.' .or '/' .or '?' .or err_identifier;
1675
1676 err_identifier
1677 id_character_first .and .loop id_character_next;
1678