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