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
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
24 .emtcode IDENTIFIER_NO_LOOP 0x00
25 .emtcode IDENTIFIER_LOOP 0x01
28 .emtcode ERROR_NOT_PRESENT 0x00
29 .emtcode ERROR_PRESENT 0x01
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
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"
47 <grammar> ::= ".syntax" <identifier> ";" <declaration_list>
50 grammar_1 .error INVALID_GRAMMAR;
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;
56 <optional_space> ::= <space>
63 <space> ::= <single_space> <single_space>*
66 single_space .and .loop single_space;
69 <single_space> ::= <white_char>
73 white_char .or comment_block;
82 ' ' .or '\t' .or '\n' .or '\r';
85 <comment_block> ::= "/" "*" <comment_char>* "*" "/"
88 '/' .and '*' .and .loop comment_char .and '*' .and '/';
91 <comment_char> ::= <comment_char_no_star>
92 | "*" <comment_char_no_slash>
95 comment_char_no_star .or comment_char_1;
97 '*' .and comment_char_no_slash;
100 <comment_char_no_star> ::= All ASCII characters except "*" and "\0"
103 '\x2B'-'\xFF' .or '\x01'-'\x29';
106 <comment_char_no_slash> ::= All ASCII characters except "/" and "\0"
108 comment_char_no_slash
109 '\x30'-'\xFF' .or '\x01'-'\x2E';
112 <identifier> ::= <identifier>
115 identifier_ne .error IDENTIFIER_EXPECTED;
118 <identifier_ne> ::= <first_idchar> <follow_idchar>*
121 first_idchar .emit * .and .loop follow_idchar .emit * .and .true .emit '\0';
124 <first_idchar> ::= "a"-"z"
129 'a'-'z' .or 'A'-'Z' .or '_';
132 <follow_idchar> ::= <first_idchar>
136 first_idchar .or digit_dec;
139 <digit_dec> ::= "0"-"9"
148 optional_space .and ';' .error MISSING_SEMICOLON .and optional_space;
151 <declaration_list> ::= <declaration>
152 | <declaration_list> <declaration>
155 declaration .and .loop declaration;
158 <declaration> ::= <emitcode_definition>
159 | <errortext_definition>
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;
171 <emitcode_definition> ::= ".emtcode" <identifier> <integer>
174 ".emtcode" .and space .and identifier .and space .and integer .and space_or_null;
177 <integer> ::= <integer_ne>
180 integer_ne .error INTEGER_EXPECTED;
183 <integer_ne> :: <hex_prefix> <digit_hex> <digit_hex>*
186 hex_prefix .and digit_hex .emit * .and .loop digit_hex .emit * .and .true .emit '\0';
189 <hex_prefix> ::= "0x"
193 '0' .and hex_prefix_1;
198 <digit_hex> ::= "0"-"9"
203 '0'-'9' .or 'a'-'f' .or 'A'-'F';
206 <space_or_null> ::= <space>
213 <errortext_definition> ::= ".errtext" <identifier> <string>
216 ".errtext" .and space .and identifier .and space .and string .and space_or_null;
219 <string> ::= <string_ne>
222 string_ne .error STRING_EXPECTED;
225 <string_ne> ::= "\"" <string_char_double_quotes> "\""
228 '"' .and .loop string_char_double_quotes .and '"' .emit '\0';
231 <string_char_double_quotes> ::= <escape_sequence>
235 string_char_double_quotes
236 escape_sequence .or string_char .emit * .or '\'' .emit *;
239 <string_char> ::= All ASCII characters except "\'", "\"", "\n", "\r",
243 '\x5D'-'\xFF' .or '\x28'-'\x5B' .or '\x23'-'\x26' .or '\x0E'-'\x21' .or '\x0B'-'\x0C' .or
247 <escape_sequence> ::= "\\" <escape_code>
250 '\\' .emit * .and escape_code;
253 <escape_code> ::= <simple_escape_code>
258 simple_escape_code .emit * .or hex_escape_code .or oct_escape_code;
261 <simple_escape_code> ::= "\'"
274 '\'' .or '"' .or '?' .or '\\' .or 'a' .or 'b' .or 'f' .or 'n' .or 'r' .or 't' .or 'v';
277 <hex_escape_code> ::= "x" <digit_hex> <digit_hex>*
280 'x' .emit * .and digit_hex .emit * .and .loop digit_hex .emit *;
283 <oct_escape_code> ::= <digit_oct> <optional_digit_oct> <optional_digit_oct>
286 digit_oct .emit * .and optional_digit_oct .and optional_digit_oct;
289 <digit_oct> ::= "0"-"7"
295 <optional_digit_oct> ::= <digit_oct>
299 digit_oct .emit * .or .true;
302 <regbyte_definition> ::= ".regbyte" <identifier> <integer>
305 ".regbyte" .and space .and identifier .and space .and integer .and space_or_null;
308 <lexer_definition> ::= ".string" <identifier> ";"
311 ".string" .and space .and identifier .and semicolon;
314 <rule_definition> ::= <identifier_ne> <definition>
317 identifier_ne .and space .and definition;
320 <definition> ::= <specifier> <optional_specifiers_and_or> ";"
323 specifier .and optional_specifiers_and_or .and semicolon .emit SPECIFIER_END;
326 <optional_specifiers_and_or> ::= <and_specifiers>
330 optional_specifiers_and_or
331 and_specifiers .emit SPECIFIER_AND_TAG .or or_specifiers .emit SPECIFIER_OR_TAG .or .true;
334 <specifier> ::= <specifier_condition> <specifier_rule>
337 specifier_condition .and optional_space .and specifier_rule;
340 <specifier_condition> ::= ".if" "(" <left_operand> <operator> <right_operand> ")"
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 ')';
349 <left_operand> ::= <identifier>
359 operator_1 .or operator_2;
361 optional_space .and '!' .and '=' .and optional_space;
363 optional_space .and '=' .and '=' .and optional_space;
366 <right_operand> ::= <integer>
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>*
381 specifier_rule_1 .and optional_error .and .loop emit .and .true .emit EMIT_NULL;
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;
392 <character> ::= "\'" <string_char_single_quotes "\'"
395 '\'' .and string_char_single_quotes .and '\'' .emit '\0';
398 <string_char_single_quotes> ::= <escape_sequence>
402 string_char_single_quotes
403 escape_sequence .or string_char .emit * .or '"' .emit *;
406 <character_range> ::= <character> "-" <character>
409 character .and optional_space .and '-' .and optional_space .and character;
412 <loop_identifier> ::= <optional_loop> <identifier>
415 optional_loop .and identifier;
418 <optional_loop> ::= ".loop"
422 optional_loop_1 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_NO_LOOP;
427 <optional_error> ::= <error>
431 error .emit ERROR_PRESENT .or .true .emit ERROR_NOT_PRESENT;
434 <error> :: ".error" <identifier>
437 space .and ".error" .and space .and identifier;
440 <emit> ::= <emit_output>
444 emit_output .or emit_regbyte;
447 <emit_output> ::= ".emit" <emit_param>
450 space .and ".emit" .and space .and emit_param;
453 <emit_param> ::= <integer>
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;
467 <emit_regbyte> ::= ".load" <identifier> <emit_param>
470 space .and ".load" .and space .and identifier .and space .and emit_param;
473 <and_specifiers> ::= <and_specifier> <and_specifier>*
476 and_specifier .and .loop and_specifier;
479 <or_specifiers> ::= <or_specifier> <or_specifier>*
482 or_specifier .and .loop or_specifier;
485 <and_specifier> ::= ".and" <specifier>
488 space .and ".and" .and space .and specifier;
491 <or_specifier> ::= ".or" <specifier>
494 space .and ".or" .and space .and specifier;
497 .string __string_filter;
500 <__string_filter> ::= <__first_identifier_char> <__next_identifier_char>*
503 __first_identifier_char .and .loop __next_identifier_char;
506 <__first_identifier_char> ::= "a"-"z"
511 __first_identifier_char
512 'a'-'z' .or 'A'-'Z' .or '_' .or '.';
515 <__next_identifier_char> ::= "a"-"z"
520 __next_identifier_char
521 'a'-'z' .or 'A'-'Z' .or '_' .or '0'-'9';