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