Grammar package supporting 8-bit registers.

TODO:
  - add checking for duplicate symbols (or is it done already?)
  - move all the statics (grammar objects list and last error message)
    to the GL context state; I think simple pointer initialized in a
    first call to ProgramString() is sufficent.
  - apply an optimized version of match() - this will be needed for
    glslang compiler.
This commit is contained in:
Michal Krol 2004-03-03 18:10:40 +00:00
parent e05d4fbf0f
commit 0e7b1d8811
6 changed files with 3622 additions and 0 deletions

2760
src/mesa/shader/grammar.c Normal file

File diff suppressed because it is too large Load diff

68
src/mesa/shader/grammar.h Normal file
View file

@ -0,0 +1,68 @@
#ifndef GRAMMAR_H
#define GRAMMAR_H
#ifndef GRAMMAR_PORT_INCLUDE
#error Do not include this file directly, include your grammar_XXX.h instead
#endif
#ifdef __cplusplus
extern "C" {
#endif
void grammar_alloc_free (void *);
void *grammar_alloc_malloc (unsigned int);
void *grammar_alloc_realloc (void *, unsigned int, unsigned int);
void *grammar_memory_copy (void *, const void *, unsigned int);
int grammar_string_compare (const byte *, const byte *);
int grammar_string_compare_n (const byte *, const byte *, unsigned int);
byte *grammar_string_copy (byte *, const byte *);
byte *grammar_string_copy_n (byte *, const byte *, unsigned int);
byte *grammar_string_duplicate (const byte *);
unsigned int grammar_string_length (const byte *);
/*
loads grammar script from null-terminated ASCII <text>
returns unique grammar id to grammar object
returns 0 if an error occurs (call grammar_get_last_error to retrieve the error text)
*/
grammar grammar_load_from_text (const byte *text);
/*
sets a new <value> to a register <name> for grammar <id>
returns 0 on error (call grammar_get_last_error to retrieve the error text)
returns 1 on success
*/
int grammar_set_reg8 (grammar id, const byte *name, byte value);
/*
checks if a null-terminated <text> matches given grammar <id>
returns 0 on error (call grammar_get_last_error to retrieve the error text)
returns 1 on success, the <prod> points to newly allocated buffer with production and <size>
is filled with the production size
call grammar_alloc_free to free the memory block pointed by <prod>
*/
int grammar_check (grammar id, const byte *text, byte **prod, unsigned int *size);
/*
destroys grammar object identified by <id>
returns 0 on error (call grammar_get_last_error to retrieve the error text)
returns 1 on success
*/
int grammar_destroy (grammar id);
/*
retrieves last grammar error reported either by grammar_load_from_text, grammar_check
or grammar_destroy
the user allocated <text> buffer receives error description, <pos> points to error position,
<size> is the size of the text buffer to fill in - it must be at least 4 bytes long,
*/
void grammar_get_last_error (byte *text, unsigned int size, int *pos);
#ifdef __cplusplus
}
#endif
#endif

522
src/mesa/shader/grammar.syn Normal file
View file

@ -0,0 +1,522 @@
.syntax grammar;
/* declaration */
.emtcode DECLARATION_END 0x00
.emtcode DECLARATION_EMITCODE 0x01
.emtcode DECLARATION_ERRORTEXT 0x02
.emtcode DECLARATION_REGBYTE 0x03
.emtcode DECLARATION_LEXER 0x04
.emtcode DECLARATION_RULE 0x05
/* specifier */
.emtcode SPECIFIER_END 0x00
.emtcode SPECIFIER_AND_TAG 0x01
.emtcode SPECIFIER_OR_TAG 0x02
.emtcode SPECIFIER_CHARACTER_RANGE 0x03
.emtcode SPECIFIER_CHARACTER 0x04
.emtcode SPECIFIER_STRING 0x05
.emtcode SPECIFIER_IDENTIFIER 0x06
.emtcode SPECIFIER_TRUE 0x07
.emtcode SPECIFIER_FALSE 0x08
.emtcode SPECIFIER_DEBUG 0x09
/* identifier */
.emtcode IDENTIFIER_NO_LOOP 0x00
.emtcode IDENTIFIER_LOOP 0x01
/* error */
.emtcode ERROR_NOT_PRESENT 0x00
.emtcode ERROR_PRESENT 0x01
/* emit */
.emtcode EMIT_NULL 0x00
.emtcode EMIT_INTEGER 0x01
.emtcode EMIT_IDENTIFIER 0x02
.emtcode EMIT_CHARACTER 0x03
.emtcode EMIT_LAST_CHARACTER 0x04
.emtcode EMIT_CURRENT_POSITION 0x05
.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_char>* "*" "/"
*/
comment_block
'/' .and '*' .and .loop comment_char .and '*' .and '/';
/*
<comment_char> ::= <comment_char_no_star>
| "*" <comment_char_no_slash>
*/
comment_char
comment_char_no_star .or comment_char_1;
comment_char_1
'*' .and comment_char_no_slash;
/*
<comment_char_no_star> ::= All ASCII characters except "*" and "\0"
*/
comment_char_no_star
'\x2B'-'\xFF' .or '\x01'-'\x29';
/*
<comment_char_no_slash> ::= All ASCII characters except "/" and "\0"
*/
comment_char_no_slash
'\x30'-'\xFF' .or '\x01'-'\x2E';
/*
<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_prefix> <digit_hex> <digit_hex>*
*/
integer_ne
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';
/*
<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>*
| <loop_identifier> <optional_error> <emit>*
| ".true" <optional_error> <emit>*
| ".false" <optional_error> <emit>*
| ".debug" <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
loop_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;
/*
<loop_identifier> ::= <optional_loop> <identifier>
*/
loop_identifier
optional_loop .and identifier;
/*
<optional_loop> ::= ".loop"
| ""
*/
optional_loop
optional_loop_1 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_NO_LOOP;
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';

View file

@ -0,0 +1,57 @@
#include "grammar_mesa.h"
#define GRAMMAR_PORT_BUILD 1
#include "grammar.c"
#undef GRAMMAR_PORT_BUILD
void grammar_alloc_free (void *ptr)
{
_mesa_free (ptr);
}
void *grammar_alloc_malloc (unsigned int size)
{
return _mesa_malloc (size);
}
void *grammar_alloc_realloc (void *ptr, unsigned int old_size, unsigned int size)
{
return _mesa_realloc (ptr, old_size, size);
}
void *grammar_memory_copy (void *dst, const void * src, unsigned int size)
{
return _mesa_memcpy (dst, src, size);
}
int grammar_string_compare (const byte *str1, const byte *str2)
{
return _mesa_strcmp ((const char *) str1, (const char *) str2);
}
int grammar_string_compare_n (const byte *str1, const byte *str2, unsigned int n)
{
return _mesa_strncmp ((const char *) str1, (const char *) str2, n);
}
byte *grammar_string_copy (byte *dst, const byte *src)
{
return (byte *) _mesa_strcpy ((char *) dst, (const char *) src);
}
byte *grammar_string_copy_n (byte *dst, const byte *src, unsigned int n)
{
return (byte *) _mesa_strncpy ((char *) dst, (const char *) src, n);
}
byte *grammar_string_duplicate (const byte *src)
{
return (byte *) _mesa_strdup ((const char *) src);
}
unsigned int grammar_string_length (const byte *str)
{
return _mesa_strlen ((const char *) str);
}

View file

@ -0,0 +1,19 @@
#ifndef GRAMMAR_MESA_H
#define GRAMMAR_MESA_H
#include "imports.h"
/* NOTE: include Mesa 3-D specific headers here */
typedef GLuint grammar;
typedef GLubyte byte;
#define GRAMMAR_PORT_INCLUDE 1
#include "grammar.h"
#undef GRAMMAR_PORT_INCLUDE
#endif

View file

@ -0,0 +1,196 @@
".syntax grammar;\n"
".emtcode DECLARATION_END 0x00\n"
".emtcode DECLARATION_EMITCODE 0x01\n"
".emtcode DECLARATION_ERRORTEXT 0x02\n"
".emtcode DECLARATION_REGBYTE 0x03\n"
".emtcode DECLARATION_LEXER 0x04\n"
".emtcode DECLARATION_RULE 0x05\n"
".emtcode SPECIFIER_END 0x00\n"
".emtcode SPECIFIER_AND_TAG 0x01\n"
".emtcode SPECIFIER_OR_TAG 0x02\n"
".emtcode SPECIFIER_CHARACTER_RANGE 0x03\n"
".emtcode SPECIFIER_CHARACTER 0x04\n"
".emtcode SPECIFIER_STRING 0x05\n"
".emtcode SPECIFIER_IDENTIFIER 0x06\n"
".emtcode SPECIFIER_TRUE 0x07\n"
".emtcode SPECIFIER_FALSE 0x08\n"
".emtcode SPECIFIER_DEBUG 0x09\n"
".emtcode IDENTIFIER_NO_LOOP 0x00\n"
".emtcode IDENTIFIER_LOOP 0x01\n"
".emtcode ERROR_NOT_PRESENT 0x00\n"
".emtcode ERROR_PRESENT 0x01\n"
".emtcode EMIT_NULL 0x00\n"
".emtcode EMIT_INTEGER 0x01\n"
".emtcode EMIT_IDENTIFIER 0x02\n"
".emtcode EMIT_CHARACTER 0x03\n"
".emtcode EMIT_LAST_CHARACTER 0x04\n"
".emtcode EMIT_CURRENT_POSITION 0x05\n"
".errtext INVALID_GRAMMAR \"internal error 2001: invalid grammar script\"\n"
".errtext SYNTAX_EXPECTED \"internal error 2002: '.syntax' keyword expected\"\n"
".errtext IDENTIFIER_EXPECTED \"internal error 2003: identifier expected\"\n"
".errtext MISSING_SEMICOLON \"internal error 2004: missing ';'\"\n"
".errtext INTEGER_EXPECTED \"internal error 2005: integer value expected\"\n"
".errtext STRING_EXPECTED \"internal error 2006: string expected\"\n"
"grammar\n"
" grammar_1 .error INVALID_GRAMMAR;\n"
"grammar_1\n"
" optional_space .and \".syntax\" .error SYNTAX_EXPECTED .and space .and identifier .and\n"
" semicolon .and declaration_list .and optional_space .and '\\0' .emit DECLARATION_END;\n"
"optional_space\n"
" space .or .true;\n"
"space\n"
" single_space .and .loop single_space;\n"
"single_space\n"
" white_char .or comment_block;\n"
"white_char\n"
" ' ' .or '\\t' .or '\\n' .or '\\r';\n"
"comment_block\n"
" '/' .and '*' .and .loop comment_char .and '*' .and '/';\n"
"comment_char\n"
" comment_char_no_star .or comment_char_1;\n"
"comment_char_1\n"
" '*' .and comment_char_no_slash;\n"
"comment_char_no_star\n"
" '\\x2B'-'\\xFF' .or '\\x01'-'\\x29';\n"
"comment_char_no_slash\n"
" '\\x30'-'\\xFF' .or '\\x01'-'\\x2E';\n"
"identifier\n"
" identifier_ne .error IDENTIFIER_EXPECTED;\n"
"identifier_ne\n"
" first_idchar .emit * .and .loop follow_idchar .emit * .and .true .emit '\\0';\n"
"first_idchar\n"
" 'a'-'z' .or 'A'-'Z' .or '_';\n"
"follow_idchar\n"
" first_idchar .or digit_dec;\n"
"digit_dec\n"
" '0'-'9';\n"
"semicolon\n"
" optional_space .and ';' .error MISSING_SEMICOLON .and optional_space;\n"
"declaration_list\n"
" declaration .and .loop declaration;\n"
"declaration\n"
" emitcode_definition .emit DECLARATION_EMITCODE .or\n"
" errortext_definition .emit DECLARATION_ERRORTEXT .or\n"
" regbyte_definition .emit DECLARATION_REGBYTE .or\n"
" lexer_definition .emit DECLARATION_LEXER .or\n"
" rule_definition .emit DECLARATION_RULE;\n"
"emitcode_definition\n"
" \".emtcode\" .and space .and identifier .and space .and integer .and space_or_null;\n"
"integer\n"
" integer_ne .error INTEGER_EXPECTED;\n"
"integer_ne\n"
" hex_prefix .and digit_hex .emit * .and .loop digit_hex .emit * .and .true .emit '\\0';\n"
"hex_prefix\n"
" '0' .and hex_prefix_1;\n"
"hex_prefix_1\n"
" 'x' .or 'X';\n"
"digit_hex\n"
" '0'-'9' .or 'a'-'f' .or 'A'-'F';\n"
"space_or_null\n"
" space .or '\\0';\n"
"errortext_definition\n"
" \".errtext\" .and space .and identifier .and space .and string .and space_or_null;\n"
"string\n"
" string_ne .error STRING_EXPECTED;\n"
"string_ne\n"
" '\"' .and .loop string_char_double_quotes .and '\"' .emit '\\0';\n"
"string_char_double_quotes\n"
" escape_sequence .or string_char .emit * .or '\\'' .emit *;\n"
"string_char\n"
" '\\x5D'-'\\xFF' .or '\\x28'-'\\x5B' .or '\\x23'-'\\x26' .or '\\x0E'-'\\x21' .or '\\x0B'-'\\x0C' .or\n"
" '\\x01'-'\\x09';\n"
"escape_sequence\n"
" '\\\\' .emit * .and escape_code;\n"
"escape_code\n"
" simple_escape_code .emit * .or hex_escape_code .or oct_escape_code;\n"
"simple_escape_code\n"
" '\\'' .or '\"' .or '?' .or '\\\\' .or 'a' .or 'b' .or 'f' .or 'n' .or 'r' .or 't' .or 'v';\n"
"hex_escape_code\n"
" 'x' .emit * .and digit_hex .emit * .and .loop digit_hex .emit *;\n"
"oct_escape_code\n"
" digit_oct .emit * .and optional_digit_oct .and optional_digit_oct;\n"
"digit_oct\n"
" '0'-'7';\n"
"optional_digit_oct\n"
" digit_oct .emit * .or .true;\n"
"regbyte_definition\n"
" \".regbyte\" .and space .and identifier .and space .and integer .and space_or_null;\n"
"lexer_definition\n"
" \".string\" .and space .and identifier .and semicolon;\n"
"rule_definition\n"
" identifier_ne .and space .and definition;\n"
"definition\n"
" specifier .and optional_specifiers_and_or .and semicolon .emit SPECIFIER_END;\n"
"optional_specifiers_and_or\n"
" and_specifiers .emit SPECIFIER_AND_TAG .or or_specifiers .emit SPECIFIER_OR_TAG .or .true;\n"
"specifier\n"
" specifier_condition .and optional_space .and specifier_rule;\n"
"specifier_condition\n"
" specifier_condition_1 .or .true;\n"
"specifier_condition_1\n"
" \".if\" .and optional_space .and '(' .and optional_space .and left_operand .and operator .and\n"
" right_operand .and optional_space .and ')';\n"
"left_operand\n"
" identifier;\n"
"operator\n"
" operator_1 .or operator_2;\n"
"operator_1\n"
" optional_space .and '!' .and '=' .and optional_space;\n"
"operator_2\n"
" optional_space .and '=' .and '=' .and optional_space;\n"
"right_operand\n"
" integer;\n"
"specifier_rule\n"
" specifier_rule_1 .and optional_error .and .loop emit .and .true .emit EMIT_NULL;\n"
"specifier_rule_1\n"
" character_range .emit SPECIFIER_CHARACTER_RANGE .or\n"
" character .emit SPECIFIER_CHARACTER .or\n"
" string_ne .emit SPECIFIER_STRING .or\n"
" \".true\" .emit SPECIFIER_TRUE .or\n"
" \".false\" .emit SPECIFIER_FALSE .or\n"
" \".debug\" .emit SPECIFIER_DEBUG .or\n"
" loop_identifier .emit SPECIFIER_IDENTIFIER;\n"
"character\n"
" '\\'' .and string_char_single_quotes .and '\\'' .emit '\\0';\n"
"string_char_single_quotes\n"
" escape_sequence .or string_char .emit * .or '\"' .emit *;\n"
"character_range\n"
" character .and optional_space .and '-' .and optional_space .and character;\n"
"loop_identifier\n"
" optional_loop .and identifier;\n"
"optional_loop\n"
" optional_loop_1 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_NO_LOOP;\n"
"optional_loop_1\n"
" \".loop\" .and space;\n"
"optional_error\n"
" error .emit ERROR_PRESENT .or .true .emit ERROR_NOT_PRESENT;\n"
"error\n"
" space .and \".error\" .and space .and identifier;\n"
"emit\n"
" emit_output .or emit_regbyte;\n"
"emit_output\n"
" space .and \".emit\" .and space .and emit_param;\n"
"emit_param\n"
" integer_ne .emit EMIT_INTEGER .or\n"
" identifier_ne .emit EMIT_IDENTIFIER .or\n"
" character .emit EMIT_CHARACTER .or\n"
" '*' .emit EMIT_LAST_CHARACTER .or\n"
" '$' .emit EMIT_CURRENT_POSITION;\n"
"emit_regbyte\n"
" space .and \".load\" .and space .and identifier .and space .and emit_param;\n"
"and_specifiers\n"
" and_specifier .and .loop and_specifier;\n"
"or_specifiers\n"
" or_specifier .and .loop or_specifier;\n"
"and_specifier\n"
" space .and \".and\" .and space .and specifier;\n"
"or_specifier\n"
" space .and \".or\" .and space .and specifier;\n"
".string __string_filter;\n"
"__string_filter\n"
" __first_identifier_char .and .loop __next_identifier_char;\n"
"__first_identifier_char\n"
" 'a'-'z' .or 'A'-'Z' .or '_' .or '.';\n"
"__next_identifier_char\n"
" 'a'-'z' .or 'A'-'Z' .or '_' .or '0'-'9';\n"
""