- add decimal literal integer support
authorMichal Krol <mjkrol@gmail.org>
Fri, 22 Oct 2004 12:42:37 +0000 (12:42 +0000)
committerMichal Krol <mjkrol@gmail.org>
Fri, 22 Oct 2004 12:42:37 +0000 (12:42 +0000)
- fix bug with c-style comment closing - sequences
  like /***/ were not correctly parsed

src/mesa/shader/grammar.syn
src/mesa/shader/grammar_syn.h

index 62141df..5d99f65 100644 (file)
-.syntax grammar;\r
-\r
-/* declaration */\r
-.emtcode DECLARATION_END                            0x00\r
-.emtcode DECLARATION_EMITCODE                       0x01\r
-.emtcode DECLARATION_ERRORTEXT                      0x02\r
-.emtcode DECLARATION_REGBYTE                        0x03\r
-.emtcode DECLARATION_LEXER                          0x04\r
-.emtcode DECLARATION_RULE                           0x05\r
-\r
-/* specifier */\r
-.emtcode SPECIFIER_END                              0x00\r
-.emtcode SPECIFIER_AND_TAG                          0x01\r
-.emtcode SPECIFIER_OR_TAG                           0x02\r
-.emtcode SPECIFIER_CHARACTER_RANGE                  0x03\r
-.emtcode SPECIFIER_CHARACTER                        0x04\r
-.emtcode SPECIFIER_STRING                           0x05\r
-.emtcode SPECIFIER_IDENTIFIER                       0x06\r
-.emtcode SPECIFIER_TRUE                             0x07\r
-.emtcode SPECIFIER_FALSE                            0x08\r
-.emtcode SPECIFIER_DEBUG                            0x09\r
-\r
-/* identifier */\r
-.emtcode IDENTIFIER_NO_LOOP                         0x00\r
-.emtcode IDENTIFIER_LOOP                            0x01\r
-\r
-/* error */\r
-.emtcode ERROR_NOT_PRESENT                          0x00\r
-.emtcode ERROR_PRESENT                              0x01\r
-\r
-/* emit */\r
-.emtcode EMIT_NULL                                  0x00\r
-.emtcode EMIT_INTEGER                               0x01\r
-.emtcode EMIT_IDENTIFIER                            0x02\r
-.emtcode EMIT_CHARACTER                             0x03\r
-.emtcode EMIT_LAST_CHARACTER                        0x04\r
-.emtcode EMIT_CURRENT_POSITION                      0x05\r
-\r
-.errtext INVALID_GRAMMAR                            "internal error 2001: invalid grammar script"\r
-.errtext SYNTAX_EXPECTED                            "internal error 2002: '.syntax' keyword expected"\r
-.errtext IDENTIFIER_EXPECTED                        "internal error 2003: identifier expected"\r
-.errtext MISSING_SEMICOLON                          "internal error 2004: missing ';'"\r
-.errtext INTEGER_EXPECTED                           "internal error 2005: integer value expected"\r
-.errtext STRING_EXPECTED                            "internal error 2006: string expected"\r
-\r
-/*\r
-    <grammar>                           ::= ".syntax" <identifier> ";" <declaration_list>\r
-*/\r
-grammar\r
-    grammar_1 .error INVALID_GRAMMAR;\r
-grammar_1\r
-    optional_space .and ".syntax" .error SYNTAX_EXPECTED .and space .and identifier .and\r
-    semicolon .and declaration_list .and optional_space .and '\0' .emit DECLARATION_END;\r
-\r
-/*\r
-    <optional_space>                    ::= <space>\r
-                                          | ""\r
-*/\r
-optional_space\r
-    space .or .true;\r
-\r
-/*\r
-    <space>                             ::= <single_space> <single_space>*\r
-*/\r
-space\r
-    single_space .and .loop single_space;\r
-\r
-/*\r
-    <single_space>                      ::= <white_char>\r
-                                          | <comment_block>\r
-*/\r
-single_space\r
-    white_char .or comment_block;\r
-\r
-/*\r
-    <white_char>                        ::= " " \r
-                                          | "\t"\r
-                                          | "\n"\r
-                                          | "\r"\r
-*/\r
-white_char\r
-    ' ' .or '\t' .or '\n' .or '\r';\r
-\r
-/*\r
-    <comment_block>                     ::= "/" "*" <comment_char>* "*" "/"\r
-*/\r
-comment_block\r
-    '/' .and '*' .and .loop comment_char .and '*' .and '/';\r
-\r
-/*\r
-    <comment_char>                      ::= <comment_char_no_star>\r
-                                          | "*" <comment_char_no_slash>\r
-*/\r
-comment_char\r
-    comment_char_no_star .or comment_char_1;\r
-comment_char_1\r
-    '*' .and comment_char_no_slash;\r
-\r
-/*\r
-    <comment_char_no_star>              ::= All ASCII characters except "*" and "\0"\r
-*/\r
-comment_char_no_star\r
-    '\x2B'-'\xFF' .or '\x01'-'\x29';\r
-\r
-/*\r
-    <comment_char_no_slash>             ::= All ASCII characters except "/" and "\0"\r
-*/\r
-comment_char_no_slash\r
-    '\x30'-'\xFF' .or '\x01'-'\x2E';\r
-\r
-/*\r
-    <identifier>                        ::= <identifier>\r
-*/\r
-identifier\r
-    identifier_ne .error IDENTIFIER_EXPECTED;\r
-\r
-/*\r
-    <identifier_ne>                     ::= <first_idchar> <follow_idchar>*\r
-*/\r
-identifier_ne\r
-    first_idchar .emit * .and .loop follow_idchar .emit * .and .true .emit '\0';\r
-\r
-/*\r
-    <first_idchar>                      ::= "a"-"z"\r
-                                          | "A"-"Z"\r
-                                          | "_"\r
-*/\r
-first_idchar\r
-    'a'-'z' .or 'A'-'Z' .or '_';\r
-\r
-/*\r
-    <follow_idchar>                     ::= <first_idchar>\r
-                                          | <digit_dec>\r
-*/\r
-follow_idchar\r
-    first_idchar .or digit_dec;\r
-\r
-/*\r
-    <digit_dec>                         ::= "0"-"9"\r
-*/\r
-digit_dec\r
-    '0'-'9';\r
-\r
-/*\r
-    <semicolon>                         ::= ";"\r
-*/\r
-semicolon\r
-    optional_space .and ';' .error MISSING_SEMICOLON .and optional_space;\r
-\r
-/*\r
-    <declaration_list>                  ::= <declaration>\r
-                                          | <declaration_list> <declaration>\r
-*/\r
-declaration_list\r
-    declaration .and .loop declaration;\r
-\r
-/*\r
-    <declaration>                       ::= <emitcode_definition>\r
-                                          | <errortext_definition>\r
-                                          | <lexer_definition>\r
-                                          | <rule_definition>\r
-*/\r
-declaration\r
-    emitcode_definition .emit DECLARATION_EMITCODE .or\r
-    errortext_definition .emit DECLARATION_ERRORTEXT .or\r
-    regbyte_definition .emit DECLARATION_REGBYTE .or\r
-    lexer_definition .emit DECLARATION_LEXER .or\r
-    rule_definition .emit DECLARATION_RULE;\r
-\r
-/*\r
-    <emitcode_definition>               ::= ".emtcode" <identifier> <integer>\r
-*/\r
-emitcode_definition\r
-    ".emtcode" .and space .and identifier .and space .and integer .and space_or_null;\r
-\r
-/*\r
-    <integer>                           ::= <integer_ne>\r
-*/\r
-integer\r
-    integer_ne .error INTEGER_EXPECTED;\r
-\r
-/*\r
-    <integer_ne>                        :: <hex_prefix> <digit_hex> <digit_hex>*\r
-*/\r
-integer_ne\r
-    hex_prefix .and digit_hex .emit * .and .loop digit_hex .emit * .and .true .emit '\0';\r
-\r
-/*\r
-    <hex_prefix>                        ::= "0x"\r
-                                          | "0X"\r
-*/\r
-hex_prefix\r
-    '0' .and hex_prefix_1;\r
-hex_prefix_1\r
-    'x' .or 'X';\r
-\r
-/*\r
-    <digit_hex>                         ::= "0"-"9"\r
-                                          | "a"-"f"\r
-                                          | "A"-"F"\r
-*/\r
-digit_hex\r
-    '0'-'9' .or 'a'-'f' .or 'A'-'F';\r
-\r
-/*\r
-    <space_or_null>                     ::= <space>\r
-                                          | "\0"\r
-*/\r
-space_or_null\r
-    space .or '\0';\r
-\r
-/*\r
-    <errortext_definition>              ::= ".errtext" <identifier> <string>\r
-*/\r
-errortext_definition\r
-    ".errtext" .and space .and identifier .and space .and string .and space_or_null;\r
-\r
-/*\r
-    <string>                            ::= <string_ne>\r
-*/\r
-string\r
-    string_ne .error STRING_EXPECTED;\r
-\r
-/*\r
-    <string_ne>                         ::= "\"" <string_char_double_quotes> "\""\r
-*/\r
-string_ne\r
-    '"' .and .loop string_char_double_quotes .and '"' .emit '\0';\r
-\r
-/*\r
-    <string_char_double_quotes>         ::= <escape_sequence>\r
-                                          | <string_char>\r
-                                          | "\'"\r
-*/\r
-string_char_double_quotes\r
-    escape_sequence .or string_char .emit * .or '\'' .emit *;\r
-\r
-/*\r
-    <string_char>                       ::= All ASCII characters except "\'", "\"", "\n", "\r",\r
-                                            "\0" and "\\"\r
-*/\r
-string_char\r
-    '\x5D'-'\xFF' .or '\x28'-'\x5B' .or '\x23'-'\x26' .or '\x0E'-'\x21' .or '\x0B'-'\x0C' .or\r
-    '\x01'-'\x09';\r
-\r
-/*\r
-    <escape_sequence>                   ::= "\\" <escape_code>\r
-*/\r
-escape_sequence\r
-    '\\' .emit * .and escape_code;\r
-\r
-/*\r
-    <escape_code>                       ::= <simple_escape_code>\r
-                                          | <hex_escape_code>\r
-                                          | <oct_escape_code>\r
-*/\r
-escape_code\r
-    simple_escape_code .emit * .or hex_escape_code .or oct_escape_code;\r
-\r
-/*\r
-    <simple_escape_code>                ::= "\'"\r
-                                          | "\""\r
-                                          | "?"\r
-                                          | "\\"\r
-                                          | "a"\r
-                                          | "b"\r
-                                          | "f"\r
-                                          | "n"\r
-                                          | "r"\r
-                                          | "t"\r
-                                          | "v"\r
-*/\r
-simple_escape_code\r
-    '\'' .or '"' .or '?' .or '\\' .or 'a' .or 'b' .or 'f' .or 'n' .or 'r' .or 't' .or 'v';\r
-\r
-/*\r
-    <hex_escape_code>                   ::= "x" <digit_hex> <digit_hex>*\r
-*/\r
-hex_escape_code\r
-    'x' .emit * .and digit_hex .emit * .and .loop digit_hex .emit *;\r
-\r
-/*\r
-    <oct_escape_code>                   ::= <digit_oct> <optional_digit_oct> <optional_digit_oct>\r
-*/\r
-oct_escape_code\r
-    digit_oct .emit * .and optional_digit_oct .and optional_digit_oct;\r
-\r
-/*\r
-    <digit_oct>                         ::= "0"-"7"\r
-*/\r
-digit_oct\r
-    '0'-'7';\r
-\r
-/*\r
-    <optional_digit_oct>                ::= <digit_oct>\r
-                                          | ""\r
-*/\r
-optional_digit_oct\r
-    digit_oct .emit * .or .true;\r
-\r
-/*\r
-    <regbyte_definition>                ::= ".regbyte" <identifier> <integer>\r
-*/\r
-regbyte_definition\r
-    ".regbyte" .and space .and identifier .and space .and integer .and space_or_null;\r
-\r
-/*\r
-    <lexer_definition>                  ::= ".string" <identifier> ";"\r
-*/\r
-lexer_definition\r
-    ".string" .and space .and identifier .and semicolon;\r
-\r
-/*\r
-    <rule_definition>                   ::= <identifier_ne> <definition>\r
-*/\r
-rule_definition\r
-    identifier_ne .and space .and definition;\r
-\r
-/*\r
-    <definition>                        ::= <specifier> <optional_specifiers_and_or> ";"\r
-*/\r
-definition\r
-    specifier .and optional_specifiers_and_or .and semicolon .emit SPECIFIER_END;\r
-\r
-/*\r
-    <optional_specifiers_and_or>        ::= <and_specifiers>\r
-                                          | <or_specifiers>\r
-                                          | ""\r
-*/\r
-optional_specifiers_and_or\r
-    and_specifiers .emit SPECIFIER_AND_TAG .or or_specifiers .emit SPECIFIER_OR_TAG .or .true;\r
-\r
-/*\r
-    <specifier>                         ::= <specifier_condition> <specifier_rule>\r
-*/\r
-specifier\r
-    specifier_condition .and optional_space .and specifier_rule;\r
-\r
-/*\r
-    <specifier_condition>               ::= ".if" "(" <left_operand> <operator> <right_operand> ")"\r
-*/\r
-specifier_condition\r
-    specifier_condition_1 .or .true;\r
-specifier_condition_1\r
-    ".if" .and optional_space .and '(' .and optional_space .and left_operand .and operator .and\r
-    right_operand .and optional_space .and ')';\r
-\r
-/*\r
-    <left_operand>                      ::= <identifier>\r
-*/\r
-left_operand\r
-    identifier;\r
-\r
-/*\r
-    <operator>                          ::= "!="\r
-                                          | "=="\r
-*/\r
-operator\r
-    operator_1 .or operator_2;\r
-operator_1\r
-    optional_space .and '!' .and '=' .and optional_space;\r
-operator_2\r
-    optional_space .and '=' .and '=' .and optional_space;\r
-\r
-/*\r
-    <right_operand>                     ::= <integer>\r
-*/\r
-right_operand\r
-    integer;\r
-\r
-/*\r
-    <specifier_rule>                    ::= <character_range> <optional_error> <emit>*\r
-                                          | <character> <optional_error> <emit>*\r
-                                          | <string> <optional_error> <emit>*\r
-                                          | <loop_identifier> <optional_error> <emit>*\r
-                                          | ".true" <optional_error> <emit>*\r
-                                          | ".false" <optional_error> <emit>*\r
-                                          | ".debug" <optional_error> <emit>*\r
-*/\r
-specifier_rule\r
-    specifier_rule_1 .and optional_error .and .loop emit .and .true .emit EMIT_NULL;\r
-specifier_rule_1\r
-    character_range .emit SPECIFIER_CHARACTER_RANGE .or\r
-    character .emit SPECIFIER_CHARACTER .or\r
-    string_ne .emit SPECIFIER_STRING .or\r
-    ".true" .emit SPECIFIER_TRUE .or\r
-    ".false" .emit SPECIFIER_FALSE .or\r
-    ".debug" .emit SPECIFIER_DEBUG .or\r
-    loop_identifier .emit SPECIFIER_IDENTIFIER;\r
-\r
-/*\r
-    <character>                         ::= "\'" <string_char_single_quotes "\'"\r
-*/\r
-character\r
-    '\'' .and string_char_single_quotes .and '\'' .emit '\0';\r
-\r
-/*\r
-    <string_char_single_quotes>         ::= <escape_sequence>\r
-                                          | <string_char>\r
-                                          | "\""\r
-*/\r
-string_char_single_quotes\r
-    escape_sequence .or string_char .emit * .or '"' .emit *;\r
-\r
-/*\r
-    <character_range>                   ::= <character> "-" <character>\r
-*/\r
-character_range\r
-    character .and optional_space .and '-' .and optional_space .and character;\r
-\r
-/*\r
-    <loop_identifier>                   ::= <optional_loop> <identifier>\r
-*/\r
-loop_identifier\r
-    optional_loop .and identifier;\r
-\r
-/*\r
-    <optional_loop>                     ::= ".loop"\r
-                                          | ""\r
-*/\r
-optional_loop\r
-    optional_loop_1 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_NO_LOOP;\r
-optional_loop_1\r
-    ".loop" .and space;\r
-\r
-/*\r
-    <optional_error>                    ::= <error>\r
-                                          | ""\r
-*/\r
-optional_error\r
-    error .emit ERROR_PRESENT .or .true .emit ERROR_NOT_PRESENT;\r
-\r
-/*\r
-    <error>                             :: ".error" <identifier>\r
-*/\r
-error\r
-    space .and ".error" .and space .and identifier;\r
-\r
-/*\r
-    <emit>                              ::= <emit_output>\r
-                                          | <emit_regbyte>\r
-*/\r
-emit\r
-    emit_output .or emit_regbyte;\r
-\r
-/*\r
-    <emit_output>                       ::= ".emit" <emit_param>\r
-*/\r
-emit_output\r
-    space .and ".emit" .and space .and emit_param;\r
-\r
-/*\r
-    <emit_param>                        ::= <integer>\r
-                                          | <identifier>\r
-                                          | <character>\r
-                                          | "*"\r
-                                          | "$"\r
-*/\r
-emit_param\r
-    integer_ne .emit EMIT_INTEGER .or\r
-    identifier_ne .emit EMIT_IDENTIFIER .or\r
-    character .emit EMIT_CHARACTER .or\r
-    '*' .emit EMIT_LAST_CHARACTER .or\r
-    '$' .emit EMIT_CURRENT_POSITION;\r
-\r
-/*\r
-    <emit_regbyte>                      ::= ".load" <identifier> <emit_param>\r
-*/\r
-emit_regbyte\r
-    space .and ".load" .and space .and identifier .and space .and emit_param;\r
-\r
-/*\r
-    <and_specifiers>                    ::= <and_specifier> <and_specifier>*\r
-*/\r
-and_specifiers\r
-    and_specifier .and .loop and_specifier;\r
-\r
-/*\r
-    <or_specifiers>                     ::= <or_specifier> <or_specifier>*\r
-*/\r
-or_specifiers\r
-    or_specifier .and .loop or_specifier;\r
-\r
-/*\r
-    <and_specifier>                     ::= ".and" <specifier>\r
-*/\r
-and_specifier\r
-    space .and ".and" .and space .and specifier;\r
-\r
-/*\r
-    <or_specifier>                      ::= ".or" <specifier>\r
-*/\r
-or_specifier\r
-    space .and ".or" .and space .and specifier;\r
-\r
-\r
-.string __string_filter;\r
-\r
-/*\r
-    <__string_filter>                   ::= <__first_identifier_char> <__next_identifier_char>*\r
-*/\r
-__string_filter\r
-    __first_identifier_char .and .loop __next_identifier_char;\r
-\r
-/*\r
-    <__first_identifier_char>           ::= "a"-"z"\r
-                                          | "A"-"Z"\r
-                                          | "_"\r
-                                          | "."\r
-*/\r
-__first_identifier_char\r
-    'a'-'z' .or 'A'-'Z' .or '_' .or '.';\r
-\r
-/*\r
-    <__next_identifier_char>            ::= "a"-"z"\r
-                                          | "A"-"Z"\r
-                                          | "_"\r
-                                          | "0"-"9"\r
-*/\r
-__next_identifier_char\r
-    'a'-'z' .or 'A'-'Z' .or '_' .or '0'-'9';\r
-\r
+/*
+ * 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';
+
index 9c3419e..840a1ab 100644 (file)
@@ -1,60 +1,30 @@
-/*
- * Mesa 3-D graphics library
- * Version:  6.1
- *
- * 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.h
- * syntax parsing engine language syntax
- * \author Michal Krol
- */
-
 ".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"
+".emtcode DECLARATION_END 0\n"
+".emtcode DECLARATION_EMITCODE 1\n"
+".emtcode DECLARATION_ERRORTEXT 2\n"
+".emtcode DECLARATION_REGBYTE 3\n"
+".emtcode DECLARATION_LEXER 4\n"
+".emtcode DECLARATION_RULE 5\n"
+".emtcode SPECIFIER_END 0\n"
+".emtcode SPECIFIER_AND_TAG 1\n"
+".emtcode SPECIFIER_OR_TAG 2\n"
+".emtcode SPECIFIER_CHARACTER_RANGE 3\n"
+".emtcode SPECIFIER_CHARACTER 4\n"
+".emtcode SPECIFIER_STRING 5\n"
+".emtcode SPECIFIER_IDENTIFIER 6\n"
+".emtcode SPECIFIER_TRUE 7\n"
+".emtcode SPECIFIER_FALSE 8\n"
+".emtcode SPECIFIER_DEBUG 9\n"
+".emtcode IDENTIFIER_SIMPLE 0\n"
+".emtcode IDENTIFIER_LOOP 1\n"
+".emtcode ERROR_NOT_PRESENT 0\n"
+".emtcode ERROR_PRESENT 1\n"
+".emtcode EMIT_NULL 0\n"
+".emtcode EMIT_INTEGER 1\n"
+".emtcode EMIT_IDENTIFIER 2\n"
+".emtcode EMIT_CHARACTER 3\n"
+".emtcode EMIT_LAST_CHARACTER 4\n"
+".emtcode EMIT_CURRENT_POSITION 5\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"
 "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"
+" '/' .and '*' .and comment_rest;\n"
+"comment_rest\n"
+" .loop comment_char_no_star .and comment_rest_1;\n"
+"comment_rest_1\n"
+" comment_end .or comment_rest_2;\n"
+"comment_rest_2\n"
+" '*' .and comment_rest;\n"
 "comment_char_no_star\n"
 " '\\x2B'-'\\xFF' .or '\\x01'-'\\x29';\n"
-"comment_char_no_slash\n"
-" '\\x30'-'\\xFF' .or '\\x01'-'\\x2E';\n"
+"comment_end\n"
+" '*' .and '/';\n"
 "identifier\n"
 " identifier_ne .error IDENTIFIER_EXPECTED;\n"
 "identifier_ne\n"
 "integer\n"
 " integer_ne .error INTEGER_EXPECTED;\n"
 "integer_ne\n"
+" hex_integer .emit 0x10 .or dec_integer .emit 10;\n"
+"hex_integer\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"
 " 'x' .or 'X';\n"
 "digit_hex\n"
 " '0'-'9' .or 'a'-'f' .or 'A'-'F';\n"
+"dec_integer\n"
+" digit_dec .emit * .and .loop digit_dec .emit * .and .true .emit '\\0';\n"
 "space_or_null\n"
 " space .or '\\0';\n"
 "errortext_definition\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"
+" advanced_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"
+"advanced_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 .emit IDENTIFIER_LOOP .or .true .emit IDENTIFIER_SIMPLE;\n"
 "optional_loop_1\n"
 " \".loop\" .and space;\n"
 "optional_error\n"