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