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