slang: Delete a file that is now autogenerated.
[mesa.git] / src / mesa / shader / grammar / grammar.syn
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.2
4 *
5 * Copyright (C) 1999-2004 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 grammar.syn
27 * syntax of .syn script - used to validate other syntax files
28 * \author Michal Krol
29 */
30
31 .syntax grammar;
32
33 /* declaration */
34 .emtcode DECLARATION_END 0
35 .emtcode DECLARATION_EMITCODE 1
36 .emtcode DECLARATION_ERRORTEXT 2
37 .emtcode DECLARATION_REGBYTE 3
38 .emtcode DECLARATION_LEXER 4
39 .emtcode DECLARATION_RULE 5
40
41 /* specifier */
42 .emtcode SPECIFIER_END 0
43 .emtcode SPECIFIER_AND_TAG 1
44 .emtcode SPECIFIER_OR_TAG 2
45 .emtcode SPECIFIER_CHARACTER_RANGE 3
46 .emtcode SPECIFIER_CHARACTER 4
47 .emtcode SPECIFIER_STRING 5
48 .emtcode SPECIFIER_IDENTIFIER 6
49 .emtcode SPECIFIER_TRUE 7
50 .emtcode SPECIFIER_FALSE 8
51 .emtcode SPECIFIER_DEBUG 9
52
53 /* identifier */
54 .emtcode IDENTIFIER_SIMPLE 0
55 .emtcode IDENTIFIER_LOOP 1
56
57 /* error */
58 .emtcode ERROR_NOT_PRESENT 0
59 .emtcode ERROR_PRESENT 1
60
61 /* emit */
62 .emtcode EMIT_NULL 0
63 .emtcode EMIT_INTEGER 1
64 .emtcode EMIT_IDENTIFIER 2
65 .emtcode EMIT_CHARACTER 3
66 .emtcode EMIT_LAST_CHARACTER 4
67 .emtcode EMIT_CURRENT_POSITION 5
68
69 .errtext INVALID_GRAMMAR "internal error 2001: invalid grammar script"
70 .errtext SYNTAX_EXPECTED "internal error 2002: '.syntax' keyword expected"
71 .errtext IDENTIFIER_EXPECTED "internal error 2003: identifier expected"
72 .errtext MISSING_SEMICOLON "internal error 2004: missing ';'"
73 .errtext INTEGER_EXPECTED "internal error 2005: integer value expected"
74 .errtext STRING_EXPECTED "internal error 2006: string expected"
75
76 /*
77 <grammar> ::= ".syntax" <identifier> ";" <declaration_list>
78 */
79 grammar
80 grammar_1 .error INVALID_GRAMMAR;
81 grammar_1
82 optional_space .and ".syntax" .error SYNTAX_EXPECTED .and space .and identifier .and
83 semicolon .and declaration_list .and optional_space .and '\0' .emit DECLARATION_END;
84
85 /*
86 <optional_space> ::= <space>
87 | ""
88 */
89 optional_space
90 space .or .true;
91
92 /*
93 <space> ::= <single_space> <single_space>*
94 */
95 space
96 single_space .and .loop single_space;
97
98 /*
99 <single_space> ::= <white_char>
100 | <comment_block>
101 */
102 single_space
103 white_char .or comment_block;
104
105 /*
106 <white_char> ::= " "
107 | "\t"
108 | "\n"
109 | "\r"
110 */
111 white_char
112 ' ' .or '\t' .or '\n' .or '\r';
113
114 /*
115 <comment_block> ::= "/" "*" <comment_rest>
116 */
117 comment_block
118 '/' .and '*' .and comment_rest;
119
120 /*
121 <comment_rest> ::= <comment_char_no_star>* <comment_end>
122 | <comment_char_no_star>* "*" <comment_rest>
123 */
124 comment_rest
125 .loop comment_char_no_star .and comment_rest_1;
126 comment_rest_1
127 comment_end .or comment_rest_2;
128 comment_rest_2
129 '*' .and comment_rest;
130
131 /*
132 <comment_char_no_star> ::= All ASCII characters except "*" and "\0"
133 */
134 comment_char_no_star
135 '\x2B'-'\xFF' .or '\x01'-'\x29';
136
137 /*
138 <comment_end> ::= "*" "/"
139 */
140 comment_end
141 '*' .and '/';
142
143 /*
144 <identifier> ::= <identifier>
145 */
146 identifier
147 identifier_ne .error IDENTIFIER_EXPECTED;
148
149 /*
150 <identifier_ne> ::= <first_idchar> <follow_idchar>*
151 */
152 identifier_ne
153 first_idchar .emit * .and .loop follow_idchar .emit * .and .true .emit '\0';
154
155 /*
156 <first_idchar> ::= "a"-"z"
157 | "A"-"Z"
158 | "_"
159 */
160 first_idchar
161 'a'-'z' .or 'A'-'Z' .or '_';
162
163 /*
164 <follow_idchar> ::= <first_idchar>
165 | <digit_dec>
166 */
167 follow_idchar
168 first_idchar .or digit_dec;
169
170 /*
171 <digit_dec> ::= "0"-"9"
172 */
173 digit_dec
174 '0'-'9';
175
176 /*
177 <semicolon> ::= ";"
178 */
179 semicolon
180 optional_space .and ';' .error MISSING_SEMICOLON .and optional_space;
181
182 /*
183 <declaration_list> ::= <declaration>
184 | <declaration_list> <declaration>
185 */
186 declaration_list
187 declaration .and .loop declaration;
188
189 /*
190 <declaration> ::= <emitcode_definition>
191 | <errortext_definition>
192 | <lexer_definition>
193 | <rule_definition>
194 */
195 declaration
196 emitcode_definition .emit DECLARATION_EMITCODE .or
197 errortext_definition .emit DECLARATION_ERRORTEXT .or
198 regbyte_definition .emit DECLARATION_REGBYTE .or
199 lexer_definition .emit DECLARATION_LEXER .or
200 rule_definition .emit DECLARATION_RULE;
201
202 /*
203 <emitcode_definition> ::= ".emtcode" <identifier> <integer>
204 */
205 emitcode_definition
206 ".emtcode" .and space .and identifier .and space .and integer .and space_or_null;
207
208 /*
209 <integer> ::= <integer_ne>
210 */
211 integer
212 integer_ne .error INTEGER_EXPECTED;
213
214 /*
215 <integer_ne> ::= <hex_integer>
216 | <dec_integer>
217 */
218 integer_ne
219 hex_integer .emit 0x10 .or dec_integer .emit 10;
220
221 /*
222 <hex_integer> :: <hex_prefix> <digit_hex> <digit_hex>*
223 */
224 hex_integer
225 hex_prefix .and digit_hex .emit * .and .loop digit_hex .emit * .and .true .emit '\0';
226
227 /*
228 <hex_prefix> ::= "0x"
229 | "0X"
230 */
231 hex_prefix
232 '0' .and hex_prefix_1;
233 hex_prefix_1
234 'x' .or 'X';
235
236 /*
237 <digit_hex> ::= "0"-"9"
238 | "a"-"f"
239 | "A"-"F"
240 */
241 digit_hex
242 '0'-'9' .or 'a'-'f' .or 'A'-'F';
243
244 /*
245 <dec_integer> :: <digit_dec> <digit_dec>*
246 */
247 dec_integer
248 digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\0';
249
250 /*
251 <space_or_null> ::= <space>
252 | "\0"
253 */
254 space_or_null
255 space .or '\0';
256
257 /*
258 <errortext_definition> ::= ".errtext" <identifier> <string>
259 */
260 errortext_definition
261 ".errtext" .and space .and identifier .and space .and string .and space_or_null;
262
263 /*
264 <string> ::= <string_ne>
265 */
266 string
267 string_ne .error STRING_EXPECTED;
268
269 /*
270 <string_ne> ::= "\"" <string_char_double_quotes> "\""
271 */
272 string_ne
273 '"' .and .loop string_char_double_quotes .and '"' .emit '\0';
274
275 /*
276 <string_char_double_quotes> ::= <escape_sequence>
277 | <string_char>
278 | "\'"
279 */
280 string_char_double_quotes
281 escape_sequence .or string_char .emit * .or '\'' .emit *;
282
283 /*
284 <string_char> ::= All ASCII characters except "\'", "\"", "\n", "\r",
285 "\0" and "\\"
286 */
287 string_char
288 '\x5D'-'\xFF' .or '\x28'-'\x5B' .or '\x23'-'\x26' .or '\x0E'-'\x21' .or '\x0B'-'\x0C' .or
289 '\x01'-'\x09';
290
291 /*
292 <escape_sequence> ::= "\\" <escape_code>
293 */
294 escape_sequence
295 '\\' .emit * .and escape_code;
296
297 /*
298 <escape_code> ::= <simple_escape_code>
299 | <hex_escape_code>
300 | <oct_escape_code>
301 */
302 escape_code
303 simple_escape_code .emit * .or hex_escape_code .or oct_escape_code;
304
305 /*
306 <simple_escape_code> ::= "\'"
307 | "\""
308 | "?"
309 | "\\"
310 | "a"
311 | "b"
312 | "f"
313 | "n"
314 | "r"
315 | "t"
316 | "v"
317 */
318 simple_escape_code
319 '\'' .or '"' .or '?' .or '\\' .or 'a' .or 'b' .or 'f' .or 'n' .or 'r' .or 't' .or 'v';
320
321 /*
322 <hex_escape_code> ::= "x" <digit_hex> <digit_hex>*
323 */
324 hex_escape_code
325 'x' .emit * .and digit_hex .emit * .and .loop digit_hex .emit *;
326
327 /*
328 <oct_escape_code> ::= <digit_oct> <optional_digit_oct> <optional_digit_oct>
329 */
330 oct_escape_code
331 digit_oct .emit * .and optional_digit_oct .and optional_digit_oct;
332
333 /*
334 <digit_oct> ::= "0"-"7"
335 */
336 digit_oct
337 '0'-'7';
338
339 /*
340 <optional_digit_oct> ::= <digit_oct>
341 | ""
342 */
343 optional_digit_oct
344 digit_oct .emit * .or .true;
345
346 /*
347 <regbyte_definition> ::= ".regbyte" <identifier> <integer>
348 */
349 regbyte_definition
350 ".regbyte" .and space .and identifier .and space .and integer .and space_or_null;
351
352 /*
353 <lexer_definition> ::= ".string" <identifier> ";"
354 */
355 lexer_definition
356 ".string" .and space .and identifier .and semicolon;
357
358 /*
359 <rule_definition> ::= <identifier_ne> <definition>
360 */
361 rule_definition
362 identifier_ne .and space .and definition;
363
364 /*
365 <definition> ::= <specifier> <optional_specifiers_and_or> ";"
366 */
367 definition
368 specifier .and optional_specifiers_and_or .and semicolon .emit SPECIFIER_END;
369
370 /*
371 <optional_specifiers_and_or> ::= <and_specifiers>
372 | <or_specifiers>
373 | ""
374 */
375 optional_specifiers_and_or
376 and_specifiers .emit SPECIFIER_AND_TAG .or or_specifiers .emit SPECIFIER_OR_TAG .or .true;
377
378 /*
379 <specifier> ::= <specifier_condition> <specifier_rule>
380 */
381 specifier
382 specifier_condition .and optional_space .and specifier_rule;
383
384 /*
385 <specifier_condition> ::= ".if" "(" <left_operand> <operator> <right_operand> ")"
386 */
387 specifier_condition
388 specifier_condition_1 .or .true;
389 specifier_condition_1
390 ".if" .and optional_space .and '(' .and optional_space .and left_operand .and operator .and
391 right_operand .and optional_space .and ')';
392
393 /*
394 <left_operand> ::= <identifier>
395 */
396 left_operand
397 identifier;
398
399 /*
400 <operator> ::= "!="
401 | "=="
402 */
403 operator
404 operator_1 .or operator_2;
405 operator_1
406 optional_space .and '!' .and '=' .and optional_space;
407 operator_2
408 optional_space .and '=' .and '=' .and optional_space;
409
410 /*
411 <right_operand> ::= <integer>
412 */
413 right_operand
414 integer;
415
416 /*
417 <specifier_rule> ::= <character_range> <optional_error> <emit>*
418 | <character> <optional_error> <emit>*
419 | <string> <optional_error> <emit>*
420 | ".true" <optional_error> <emit>*
421 | ".false" <optional_error> <emit>*
422 | ".debug" <optional_error> <emit>*
423 | <advanced_identifier> <optional_error> <emit>*
424 */
425 specifier_rule
426 specifier_rule_1 .and optional_error .and .loop emit .and .true .emit EMIT_NULL;
427 specifier_rule_1
428 character_range .emit SPECIFIER_CHARACTER_RANGE .or
429 character .emit SPECIFIER_CHARACTER .or
430 string_ne .emit SPECIFIER_STRING .or
431 ".true" .emit SPECIFIER_TRUE .or
432 ".false" .emit SPECIFIER_FALSE .or
433 ".debug" .emit SPECIFIER_DEBUG .or
434 advanced_identifier .emit SPECIFIER_IDENTIFIER;
435
436 /*
437 <character> ::= "\'" <string_char_single_quotes "\'"
438 */
439 character
440 '\'' .and string_char_single_quotes .and '\'' .emit '\0';
441
442 /*
443 <string_char_single_quotes> ::= <escape_sequence>
444 | <string_char>
445 | "\""
446 */
447 string_char_single_quotes
448 escape_sequence .or string_char .emit * .or '"' .emit *;
449
450 /*
451 <character_range> ::= <character> "-" <character>
452 */
453 character_range
454 character .and optional_space .and '-' .and optional_space .and character;
455
456 /*
457 <advanced_identifier> ::= <optional_loop> <identifier>
458 */
459 advanced_identifier
460 optional_loop .and identifier;
461
462 /*
463 <optional_loop> ::= ".loop"
464 | ""
465 */
466 optional_loop
467 optional_loop_1 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_SIMPLE;
468 optional_loop_1
469 ".loop" .and space;
470
471 /*
472 <optional_error> ::= <error>
473 | ""
474 */
475 optional_error
476 error .emit ERROR_PRESENT .or .true .emit ERROR_NOT_PRESENT;
477
478 /*
479 <error> :: ".error" <identifier>
480 */
481 error
482 space .and ".error" .and space .and identifier;
483
484 /*
485 <emit> ::= <emit_output>
486 | <emit_regbyte>
487 */
488 emit
489 emit_output .or emit_regbyte;
490
491 /*
492 <emit_output> ::= ".emit" <emit_param>
493 */
494 emit_output
495 space .and ".emit" .and space .and emit_param;
496
497 /*
498 <emit_param> ::= <integer>
499 | <identifier>
500 | <character>
501 | "*"
502 | "$"
503 */
504 emit_param
505 integer_ne .emit EMIT_INTEGER .or
506 identifier_ne .emit EMIT_IDENTIFIER .or
507 character .emit EMIT_CHARACTER .or
508 '*' .emit EMIT_LAST_CHARACTER .or
509 '$' .emit EMIT_CURRENT_POSITION;
510
511 /*
512 <emit_regbyte> ::= ".load" <identifier> <emit_param>
513 */
514 emit_regbyte
515 space .and ".load" .and space .and identifier .and space .and emit_param;
516
517 /*
518 <and_specifiers> ::= <and_specifier> <and_specifier>*
519 */
520 and_specifiers
521 and_specifier .and .loop and_specifier;
522
523 /*
524 <or_specifiers> ::= <or_specifier> <or_specifier>*
525 */
526 or_specifiers
527 or_specifier .and .loop or_specifier;
528
529 /*
530 <and_specifier> ::= ".and" <specifier>
531 */
532 and_specifier
533 space .and ".and" .and space .and specifier;
534
535 /*
536 <or_specifier> ::= ".or" <specifier>
537 */
538 or_specifier
539 space .and ".or" .and space .and specifier;
540
541
542 .string __string_filter;
543
544 /*
545 <__string_filter> ::= <__first_identifier_char> <__next_identifier_char>*
546 */
547 __string_filter
548 __first_identifier_char .and .loop __next_identifier_char;
549
550 /*
551 <__first_identifier_char> ::= "a"-"z"
552 | "A"-"Z"
553 | "_"
554 | "."
555 */
556 __first_identifier_char
557 'a'-'z' .or 'A'-'Z' .or '_' .or '.';
558
559 /*
560 <__next_identifier_char> ::= "a"-"z"
561 | "A"-"Z"
562 | "_"
563 | "0"-"9"
564 */
565 __next_identifier_char
566 'a'-'z' .or 'A'-'Z' .or '_' .or '0'-'9';
567