~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/mesa/shader/slang/library/slang_shader.syn

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

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