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