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