summaryrefslogtreecommitdiffstats
path: root/src/mesa/shader/grammar/grammar.syn
blob: 5d99f65bfceae143f53e926f0190f28fc1f2e52f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/*
 * Mesa 3-D graphics library
 * Version:  6.2
 *
 * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
 /**
 * \file grammar.syn
 * syntax of .syn script - used to validate other syntax files
 * \author Michal Krol
 */
 
.syntax grammar;

/* declaration */
.emtcode DECLARATION_END                            0
.emtcode DECLARATION_EMITCODE                       1
.emtcode DECLARATION_ERRORTEXT                      2
.emtcode DECLARATION_REGBYTE                        3
.emtcode DECLARATION_LEXER                          4
.emtcode DECLARATION_RULE                           5

/* specifier */
.emtcode SPECIFIER_END                              0
.emtcode SPECIFIER_AND_TAG                          1
.emtcode SPECIFIER_OR_TAG                           2
.emtcode SPECIFIER_CHARACTER_RANGE                  3
.emtcode SPECIFIER_CHARACTER                        4
.emtcode SPECIFIER_STRING                           5
.emtcode SPECIFIER_IDENTIFIER                       6
.emtcode SPECIFIER_TRUE                             7
.emtcode SPECIFIER_FALSE                            8
.emtcode SPECIFIER_DEBUG                            9

/* identifier */
.emtcode IDENTIFIER_SIMPLE                          0
.emtcode IDENTIFIER_LOOP                            1

/* error */
.emtcode ERROR_NOT_PRESENT                          0
.emtcode ERROR_PRESENT                              1

/* emit */
.emtcode EMIT_NULL                                  0
.emtcode EMIT_INTEGER                               1
.emtcode EMIT_IDENTIFIER                            2
.emtcode EMIT_CHARACTER                             3
.emtcode EMIT_LAST_CHARACTER                        4
.emtcode EMIT_CURRENT_POSITION                      5

.errtext INVALID_GRAMMAR                            "internal error 2001: invalid grammar script"
.errtext SYNTAX_EXPECTED                            "internal error 2002: '.syntax' keyword expected"
.errtext IDENTIFIER_EXPECTED                        "internal error 2003: identifier expected"
.errtext MISSING_SEMICOLON                          "internal error 2004: missing ';'"
.errtext INTEGER_EXPECTED                           "internal error 2005: integer value expected"
.errtext STRING_EXPECTED                            "internal error 2006: string expected"

/*
    <grammar>                           ::= ".syntax" <identifier> ";" <declaration_list>
*/
grammar
    grammar_1 .error INVALID_GRAMMAR;
grammar_1
    optional_space .and ".syntax" .error SYNTAX_EXPECTED .and space .and identifier .and
    semicolon .and declaration_list .and optional_space .and '\0' .emit DECLARATION_END;

/*
    <optional_space>                    ::= <space>
                                          | ""
*/
optional_space
    space .or .true;

/*
    <space>                             ::= <single_space> <single_space>*
*/
space
    single_space .and .loop single_space;

/*
    <single_space>                      ::= <white_char>
                                          | <comment_block>
*/
single_space
    white_char .or comment_block;

/*
    <white_char>                        ::= " " 
                                          | "\t"
                                          | "\n"
                                          | "\r"
*/
white_char
    ' ' .or '\t' .or '\n' .or '\r';

/*
    <comment_block>                     ::= "/" "*" <comment_rest>
*/
comment_block
    '/' .and '*' .and comment_rest;

/*
    <comment_rest>                      ::= <comment_char_no_star>* <comment_end>
                                          | <comment_char_no_star>* "*" <comment_rest>
*/
comment_rest
    .loop comment_char_no_star .and comment_rest_1;
comment_rest_1
    comment_end .or comment_rest_2;
comment_rest_2
    '*' .and comment_rest;

/*
    <comment_char_no_star>              ::= All ASCII characters except "*" and "\0"
*/
comment_char_no_star
    '\x2B'-'\xFF' .or '\x01'-'\x29';

/*
    <comment_end>                       ::= "*" "/"
*/
comment_end
    '*' .and '/';

/*
    <identifier>                        ::= <identifier>
*/
identifier
    identifier_ne .error IDENTIFIER_EXPECTED;

/*
    <identifier_ne>                     ::= <first_idchar> <follow_idchar>*
*/
identifier_ne
    first_idchar .emit * .and .loop follow_idchar .emit * .and .true .emit '\0';

/*
    <first_idchar>                      ::= "a"-"z"
                                          | "A"-"Z"
                                          | "_"
*/
first_idchar
    'a'-'z' .or 'A'-'Z' .or '_';

/*
    <follow_idchar>                     ::= <first_idchar>
                                          | <digit_dec>
*/
follow_idchar
    first_idchar .or digit_dec;

/*
    <digit_dec>                         ::= "0"-"9"
*/
digit_dec
    '0'-'9';

/*
    <semicolon>                         ::= ";"
*/
semicolon
    optional_space .and ';' .error MISSING_SEMICOLON .and optional_space;

/*
    <declaration_list>                  ::= <declaration>
                                          | <declaration_list> <declaration>
*/
declaration_list
    declaration .and .loop declaration;

/*
    <declaration>                       ::= <emitcode_definition>
                                          | <errortext_definition>
                                          | <lexer_definition>
                                          | <rule_definition>
*/
declaration
    emitcode_definition .emit DECLARATION_EMITCODE .or
    errortext_definition .emit DECLARATION_ERRORTEXT .or
    regbyte_definition .emit DECLARATION_REGBYTE .or
    lexer_definition .emit DECLARATION_LEXER .or
    rule_definition .emit DECLARATION_RULE;

/*
    <emitcode_definition>               ::= ".emtcode" <identifier> <integer>
*/
emitcode_definition
    ".emtcode" .and space .and identifier .and space .and integer .and space_or_null;

/*
    <integer>                           ::= <integer_ne>
*/
integer
    integer_ne .error INTEGER_EXPECTED;

/*
    <integer_ne>                        ::= <hex_integer>
                                          | <dec_integer>
*/
integer_ne
    hex_integer .emit 0x10 .or dec_integer .emit 10;

/*
    <hex_integer>                       :: <hex_prefix> <digit_hex> <digit_hex>*
*/
hex_integer
    hex_prefix .and digit_hex .emit * .and .loop digit_hex .emit * .and .true .emit '\0';

/*
    <hex_prefix>                        ::= "0x"
                                          | "0X"
*/
hex_prefix
    '0' .and hex_prefix_1;
hex_prefix_1
    'x' .or 'X';

/*
    <digit_hex>                         ::= "0"-"9"
                                          | "a"-"f"
                                          | "A"-"F"
*/
digit_hex
    '0'-'9' .or 'a'-'f' .or 'A'-'F';

/*
    <dec_integer>                       :: <digit_dec> <digit_dec>*
*/
dec_integer
    digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';

/*
    <space_or_null>                     ::= <space>
                                          | "\0"
*/
space_or_null
    space .or '\0';

/*
    <errortext_definition>              ::= ".errtext" <identifier> <string>
*/
errortext_definition
    ".errtext" .and space .and identifier .and space .and string .and space_or_null;

/*
    <string>                            ::= <string_ne>
*/
string
    string_ne .error STRING_EXPECTED;

/*
    <string_ne>                         ::= "\"" <string_char_double_quotes> "\""
*/
string_ne
    '"' .and .loop string_char_double_quotes .and '"' .emit '\0';

/*
    <string_char_double_quotes>         ::= <escape_sequence>
                                          | <string_char>
                                          | "\'"
*/
string_char_double_quotes
    escape_sequence .or string_char .emit * .or '\'' .emit *;

/*
    <string_char>                       ::= All ASCII characters except "\'", "\"", "\n", "\r",
                                            "\0" and "\\"
*/
string_char
    '\x5D'-'\xFF' .or '\x28'-'\x5B' .or '\x23'-'\x26' .or '\x0E'-'\x21' .or '\x0B'-'\x0C' .or
    '\x01'-'\x09';

/*
    <escape_sequence>                   ::= "\\" <escape_code>
*/
escape_sequence
    '\\' .emit * .and escape_code;

/*
    <escape_code>                       ::= <simple_escape_code>
                                          | <hex_escape_code>
                                          | <oct_escape_code>
*/
escape_code
    simple_escape_code .emit * .or hex_escape_code .or oct_escape_code;

/*
    <simple_escape_code>                ::= "\'"
                                          | "\""
                                          | "?"
                                          | "\\"
                                          | "a"
                                          | "b"
                                          | "f"
                                          | "n"
                                          | "r"
                                          | "t"
                                          | "v"
*/
simple_escape_code
    '\'' .or '"' .or '?' .or '\\' .or 'a' .or 'b' .or 'f' .or 'n' .or 'r' .or 't' .or 'v';

/*
    <hex_escape_code>                   ::= "x" <digit_hex> <digit_hex>*
*/
hex_escape_code
    'x' .emit * .and digit_hex .emit * .and .loop digit_hex .emit *;

/*
    <oct_escape_code>                   ::= <digit_oct> <optional_digit_oct> <optional_digit_oct>
*/
oct_escape_code
    digit_oct .emit * .and optional_digit_oct .and optional_digit_oct;

/*
    <digit_oct>                         ::= "0"-"7"
*/
digit_oct
    '0'-'7';

/*
    <optional_digit_oct>                ::= <digit_oct>
                                          | ""
*/
optional_digit_oct
    digit_oct .emit * .or .true;

/*
    <regbyte_definition>                ::= ".regbyte" <identifier> <integer>
*/
regbyte_definition
    ".regbyte" .and space .and identifier .and space .and integer .and space_or_null;

/*
    <lexer_definition>                  ::= ".string" <identifier> ";"
*/
lexer_definition
    ".string" .and space .and identifier .and semicolon;

/*
    <rule_definition>                   ::= <identifier_ne> <definition>
*/
rule_definition
    identifier_ne .and space .and definition;

/*
    <definition>                        ::= <specifier> <optional_specifiers_and_or> ";"
*/
definition
    specifier .and optional_specifiers_and_or .and semicolon .emit SPECIFIER_END;

/*
    <optional_specifiers_and_or>        ::= <and_specifiers>
                                          | <or_specifiers>
                                          | ""
*/
optional_specifiers_and_or
    and_specifiers .emit SPECIFIER_AND_TAG .or or_specifiers .emit SPECIFIER_OR_TAG .or .true;

/*
    <specifier>                         ::= <specifier_condition> <specifier_rule>
*/
specifier
    specifier_condition .and optional_space .and specifier_rule;

/*
    <specifier_condition>               ::= ".if" "(" <left_operand> <operator> <right_operand> ")"
*/
specifier_condition
    specifier_condition_1 .or .true;
specifier_condition_1
    ".if" .and optional_space .and '(' .and optional_space .and left_operand .and operator .and
    right_operand .and optional_space .and ')';

/*
    <left_operand>                      ::= <identifier>
*/
left_operand
    identifier;

/*
    <operator>                          ::= "!="
                                          | "=="
*/
operator
    operator_1 .or operator_2;
operator_1
    optional_space .and '!' .and '=' .and optional_space;
operator_2
    optional_space .and '=' .and '=' .and optional_space;

/*
    <right_operand>                     ::= <integer>
*/
right_operand
    integer;

/*
    <specifier_rule>                    ::= <character_range> <optional_error> <emit>*
                                          | <character> <optional_error> <emit>*
                                          | <string> <optional_error> <emit>*
                                          | ".true" <optional_error> <emit>*
                                          | ".false" <optional_error> <emit>*
                                          | ".debug" <optional_error> <emit>*
                                          | <advanced_identifier> <optional_error> <emit>*
*/
specifier_rule
    specifier_rule_1 .and optional_error .and .loop emit .and .true .emit EMIT_NULL;
specifier_rule_1
    character_range .emit SPECIFIER_CHARACTER_RANGE .or
    character .emit SPECIFIER_CHARACTER .or
    string_ne .emit SPECIFIER_STRING .or
    ".true" .emit SPECIFIER_TRUE .or
    ".false" .emit SPECIFIER_FALSE .or
    ".debug" .emit SPECIFIER_DEBUG .or
    advanced_identifier .emit SPECIFIER_IDENTIFIER;

/*
    <character>                         ::= "\'" <string_char_single_quotes "\'"
*/
character
    '\'' .and string_char_single_quotes .and '\'' .emit '\0';

/*
    <string_char_single_quotes>         ::= <escape_sequence>
                                          | <string_char>
                                          | "\""
*/
string_char_single_quotes
    escape_sequence .or string_char .emit * .or '"' .emit *;

/*
    <character_range>                   ::= <character> "-" <character>
*/
character_range
    character .and optional_space .and '-' .and optional_space .and character;

/*
    <advanced_identifier>               ::= <optional_loop> <identifier>
*/
advanced_identifier
    optional_loop .and identifier;

/*
    <optional_loop>                     ::= ".loop"
                                          | ""
*/
optional_loop
    optional_loop_1 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_SIMPLE;
optional_loop_1
    ".loop" .and space;

/*
    <optional_error>                    ::= <error>
                                          | ""
*/
optional_error
    error .emit ERROR_PRESENT .or .true .emit ERROR_NOT_PRESENT;

/*
    <error>                             :: ".error" <identifier>
*/
error
    space .and ".error" .and space .and identifier;

/*
    <emit>                              ::= <emit_output>
                                          | <emit_regbyte>
*/
emit
    emit_output .or emit_regbyte;

/*
    <emit_output>                       ::= ".emit" <emit_param>
*/
emit_output
    space .and ".emit" .and space .and emit_param;

/*
    <emit_param>                        ::= <integer>
                                          | <identifier>
                                          | <character>
                                          | "*"
                                          | "$"
*/
emit_param
    integer_ne .emit EMIT_INTEGER .or
    identifier_ne .emit EMIT_IDENTIFIER .or
    character .emit EMIT_CHARACTER .or
    '*' .emit EMIT_LAST_CHARACTER .or
    '$' .emit EMIT_CURRENT_POSITION;

/*
    <emit_regbyte>                      ::= ".load" <identifier> <emit_param>
*/
emit_regbyte
    space .and ".load" .and space .and identifier .and space .and emit_param;

/*
    <and_specifiers>                    ::= <and_specifier> <and_specifier>*
*/
and_specifiers
    and_specifier .and .loop and_specifier;

/*
    <or_specifiers>                     ::= <or_specifier> <or_specifier>*
*/
or_specifiers
    or_specifier .and .loop or_specifier;

/*
    <and_specifier>                     ::= ".and" <specifier>
*/
and_specifier
    space .and ".and" .and space .and specifier;

/*
    <or_specifier>                      ::= ".or" <specifier>
*/
or_specifier
    space .and ".or" .and space .and specifier;


.string __string_filter;

/*
    <__string_filter>                   ::= <__first_identifier_char> <__next_identifier_char>*
*/
__string_filter
    __first_identifier_char .and .loop __next_identifier_char;

/*
    <__first_identifier_char>           ::= "a"-"z"
                                          | "A"-"Z"
                                          | "_"
                                          | "."
*/
__first_identifier_char
    'a'-'z' .or 'A'-'Z' .or '_' .or '.';

/*
    <__next_identifier_char>            ::= "a"-"z"
                                          | "A"-"Z"
                                          | "_"
                                          | "0"-"9"
*/
__next_identifier_char
    'a'-'z' .or 'A'-'Z' .or '_' .or '0'-'9';