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