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