From c4db405fbea8b16f31889523165cb16eae30ae03 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Sun, 5 May 2024 15:11:10 +0300 Subject: [PATCH] Refactoring: cleanup grammar and upgrade Bison --- .clang-tidy | 1 + .vscode/settings.json | 97 +- README.md | 2 +- ccl/rslang/header/RSParserImpl.h | 693 ++++++--- ccl/rslang/header/SDImplementation.h | 2 +- ccl/rslang/include/ccl/rslang/ParserState.hpp | 3 + .../include/ccl/rslang/RSErrorCodes.hpp | 2 +- ccl/rslang/src/Interpreter.cpp | 2 + ccl/rslang/src/RSParser.cpp | 91 +- ccl/rslang/src/RSParserImpl.cpp | 1333 +++++++++-------- ccl/rslang/src/RSParserImpl.y | 679 +++++---- ccl/rslang/src/SDImplementation.cpp | 4 +- ccl/rslang/src/SDataCompact.cpp | 4 + ccl/rslang/test/src/testStructuredData.cpp | 38 +- scripts/BuildParser.ps1 | 2 +- 15 files changed, 1774 insertions(+), 1179 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index e388b2b..fa906dd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,6 +20,7 @@ Checks: "*,\ -google-readability-todo,\ -google-global-names-in-headers,\ -readability-redundant-access-specifiers,\ + -readability-redundant-member-init,\ -readability-else-after-return,\ -readability-implicit-bool-conversion,\ -readability-use-anyofallof,\ diff --git a/.vscode/settings.json b/.vscode/settings.json index eecda43..6ba9f24 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,9 +20,12 @@ "coredll", "DCMAKE", "debool", + "DECART", "Decartian", "defexpr", + "GNUC", "gtest", + "ifdef", "MSVC", "nlohmann", "noteq", @@ -30,6 +33,96 @@ "pybind", "pyconcept", "rslang", - "symmdiff" - ] + "setexpr", + "struct", + "symmdiff", + "yylex", + "yylval", + "YYSTYPE", + "Булеан", + "Кардинальность", + "Родоструктурные" + ], + "files.associations": { + "vector": "cpp", + "locale": "cpp", + "xlocale": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "algorithm": "cpp", + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "exception": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "filesystem": "cpp", + "format": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "iterator": "cpp", + "limits": "cpp", + "memory": "cpp", + "new": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ostream": "cpp", + "random": "cpp", + "ranges": "cpp", + "ratio": "cpp", + "regex": "cpp", + "span": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp", + "valarray": "cpp", + "variant": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xmemory": "cpp", + "xstring": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" + } } diff --git a/README.md b/README.md index 3bf66e9..733f777 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ C++ library for manipulating concepts in formal language of advanced set theory After changing grammar / syntax you can rebuild lexers and parser using 'scripts' folder. -- parser requires [Bison](https://www.gnu.org/software/bison/) installed +- parser requires [Bison](https://www.gnu.org/software/bison/) installed on through chocolatey: 'choco install winflexbison3' - lexer requires [Re-flex](https://github.com/Genivia/RE-flex) To run terminal after building docker container use command diff --git a/ccl/rslang/header/RSParserImpl.h b/ccl/rslang/header/RSParserImpl.h index 054bfc1..bdfa186 100644 --- a/ccl/rslang/header/RSParserImpl.h +++ b/ccl/rslang/header/RSParserImpl.h @@ -1,8 +1,8 @@ -// A Bison parser, made by GNU Bison 3.3.2. +// A Bison parser, made by GNU Bison 3.7.4. // Skeleton interface for Bison LALR(1) parsers in C++ -// Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +// Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -38,13 +38,14 @@ // C++ LALR(1) parser skeleton written by Akim Demaille. -// Undocumented macros, especially those whose name start with YY_, -// are private implementation details. Do not rely on them. +// DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, +// especially those whose name start with YY_ or yy_. They are +// private implementation details that can be changed or removed. #ifndef YY_YY_HEADER_RSPARSERIMPL_H_INCLUDED # define YY_YY_HEADER_RSPARSERIMPL_H_INCLUDED -// // "%code requires" blocks. -#line 36 "RSParserImpl.y" // lalr1.cc:401 +// "%code requires" blocks. +#line 48 "RSParserImpl.y" #include "ccl/rslang/SyntaxTree.h" #include "ccl/rslang/ParserState.hpp" @@ -54,32 +55,89 @@ namespace ccl::rslang::detail { #define YYSTYPE RawNode struct ParserState; +int yylex(RawNode* yylval, ParserState* state); + RawNode AddNode(TokenID token, RawNode son); RawNode AddNode(TokenID token, RawNode son1, RawNode son2); -RawNode BinaryOperation(RawNode op1, RawNode operation, RawNode op2); -RawNode UnaryOperation(RawNode operation, RawNode operand); RawNode RemoveBrackets(RawNode br1, RawNode operand, RawNode br2); RawNode ReplaceBrackets(TokenID token, RawNode br1, RawNode argList, RawNode br2); +RawNode BinaryOperation(RawNode op1, RawNode operation, RawNode op2); +RawNode UnaryOperation(RawNode operation, RawNode operand); RawNode Enumeration(TokenID token, RawNode el1, RawNode el2); -RawNode Decartian(RawNode op1, RawNode decart, RawNode op2); -RawNode Quantifier(RawNode quant, RawNode declaration, RawNode domain, RawNode predicate); -RawNode FunctionDeclaration(RawNode start, RawNode argdecl, RawNode expr); -RawNode FunctionCall(RawNode function, RawNode args, RawNode rs); -RawNode FilterCall(RawNode filter, RawNode params, RawNode argument, RawNode rp); -RawNode TextOperator(RawNode oper, RawNode args, RawNode rp); -RawNode TermDeclaration(RawNode lc, RawNode declaration, RawNode domain, RawNode predicate, RawNode rc); -RawNode FullRecursion(RawNode rec, RawNode localid, RawNode domain, RawNode condition, RawNode iteration, RawNode rc); -RawNode ShortRecursion(RawNode rec, RawNode localid, RawNode domain, RawNode iteration, RawNode rc); -RawNode Imperative(RawNode imp, RawNode value, RawNode actions, RawNode rc); +RawNode Decartian( + RawNode op1, + RawNode decartian, + RawNode op2 +); -int yylex(RawNode* yylval, ParserState* state); +RawNode Quantifier( + RawNode quant, + RawNode declaration, + RawNode domain, + RawNode predicate +); + +RawNode FunctionDeclaration( + RawNode start, + RawNode argumentsDeclaration, + RawNode expr +); + +RawNode FunctionCall( + RawNode function, + RawNode args, RawNode + rs +); + +RawNode FilterCall( + RawNode filter, + RawNode params, + RawNode argument, + RawNode rp +); + +RawNode TextOperator( + RawNode operatorName, + RawNode args, + RawNode rp +); + +RawNode TermDeclaration( + RawNode lc, + RawNode declaration, + RawNode domain, + RawNode predicate, + RawNode rc); + +RawNode FullRecursion( + RawNode rec, + RawNode declaration, + RawNode domain, + RawNode condition, + RawNode iteration, + RawNode rc +); + +RawNode ShortRecursion( + RawNode rec, + RawNode declaration, + RawNode domain, + RawNode iteration, + RawNode rc +); + +RawNode Imperative( + RawNode imp, + RawNode value, + RawNode actions, + RawNode rc +); } // namespace ccl::rslang::detail - -#line 83 "../header/RSParserImpl.h" // lalr1.cc:401 +#line 141 "../header/RSParserImpl.h" # include # include // std::abort @@ -127,22 +185,20 @@ int yylex(RawNode* yylval, ParserState* state); -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +#ifndef YY_ATTRIBUTE_PURE +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else -# define YY_ATTRIBUTE(Spec) /* empty */ +# define YY_ATTRIBUTE_PURE # endif #endif -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +# else +# define YY_ATTRIBUTE_UNUSED +# endif #endif /* Suppress unused-variable warnings by "using" E. */ @@ -154,11 +210,11 @@ int yylex(RawNode* yylval, ParserState* state); #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -171,6 +227,27 @@ int yylex(RawNode* yylval, ParserState* state); # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif # ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus @@ -188,9 +265,10 @@ int yylex(RawNode* yylval, ParserState* state); # define YYDEBUG 0 #endif -#line 11 "RSParserImpl.y" // lalr1.cc:401 +#line 15 "RSParserImpl.y" namespace ccl { namespace rslang { namespace detail { -#line 194 "../header/RSParserImpl.h" // lalr1.cc:401 +#line 271 "../header/RSParserImpl.h" + @@ -219,88 +297,206 @@ namespace ccl { namespace rslang { namespace detail { ~syntax_error () YY_NOEXCEPT YY_NOTHROW; }; - /// Tokens. + /// Token kinds. struct token { - enum yytokentype + enum token_kind_type { - RST_LOCAL = 258, - RST_GLOBAL = 259, - RST_FUNCTION = 260, - RST_PREDICATE = 261, - RST_RADICAL = 262, - RST_INTEGER = 263, - RST_INFINITY = 264, - RST_EMPTYSET = 265, - RST_PLUS = 266, - RST_MINUS = 267, - RST_MULTIPLY = 268, - RST_GREATER = 269, - RST_LESSER = 270, - RST_GREATER_OR_EQ = 271, - RST_LESSER_OR_EQ = 272, - RST_EQUAL = 273, - RST_NOTEQUAL = 274, - RST_FORALL = 275, - RST_EXISTS = 276, - RST_NOT = 277, - RST_EQUIVALENT = 278, - RST_IMPLICATION = 279, - RST_OR = 280, - RST_AND = 281, - RST_IN = 282, - RST_NOTIN = 283, - RST_SUBSET = 284, - RST_SUBOR_EQ = 285, - RST_NOTSUBSET = 286, - RST_DECART = 287, - RST_UNION = 288, - RST_INTERSECTION = 289, - RST_SET_MINUS = 290, - RST_SYMMINUS = 291, - RST_BOOLEAN = 292, - RST_BIGPR = 293, - RST_SMALLPR = 294, - RST_FILTER = 295, - RST_CARD = 296, - RST_BOOL = 297, - RST_DEBOOL = 298, - RST_RED = 299, - RST_DECLARATIVE = 300, - RST_RECURSIVE = 301, - RST_IMPERATIVE = 302, - RST_DEFINE = 303, - RST_STRUCT = 304, - RST_ASSIGN = 305, - RST_ITERATE = 306, - RST_LP = 307, - RST_RP = 308, - RST_LC = 309, - RST_RC = 310, - RST_LS = 311, - RST_RS = 312, - RST_BAR = 313, - RST_COMMA = 314, - RST_SEMICOLON = 315 + RST_YYEMPTY = -2, + RST_YYEOF = 0, // "end of file" + RST_YYerror = 256, // error + RST_YYUNDEF = 257, // "invalid token" + RST_LOCAL = 258, // LOCAL + RST_GLOBAL = 259, // GLOBAL + RST_FUNCTION = 260, // FUNCTION + RST_PREDICATE = 261, // PREDICATE + RST_RADICAL = 262, // RADICAL + RST_INTEGER = 263, // INTEGER + RST_INTSET = 264, // INTSET + RST_EMPTYSET = 265, // EMPTYSET + RST_PLUS = 266, // PLUS + RST_MINUS = 267, // MINUS + RST_MULTIPLY = 268, // MULTIPLY + RST_GREATER = 269, // GREATER + RST_LESSER = 270, // LESSER + RST_GREATER_OR_EQ = 271, // GREATER_OR_EQ + RST_LESSER_OR_EQ = 272, // LESSER_OR_EQ + RST_EQUAL = 273, // EQUAL + RST_NOTEQUAL = 274, // NOTEQUAL + RST_FORALL = 275, // FORALL + RST_EXISTS = 276, // EXISTS + RST_NOT = 277, // NOT + RST_EQUIVALENT = 278, // EQUIVALENT + RST_IMPLICATION = 279, // IMPLICATION + RST_OR = 280, // OR + RST_AND = 281, // AND + RST_IN = 282, // IN + RST_NOTIN = 283, // NOTIN + RST_SUBSET = 284, // SUBSET + RST_SUBOR_EQ = 285, // SUBOR_EQ + RST_NOTSUBSET = 286, // NOTSUBSET + RST_DECART = 287, // DECART + RST_UNION = 288, // UNION + RST_INTERSECTION = 289, // INTERSECTION + RST_SET_MINUS = 290, // SET_MINUS + RST_SYMMINUS = 291, // SYMMINUS + RST_BOOLEAN = 292, // BOOLEAN + RST_BIGPR = 293, // BIGPR + RST_SMALLPR = 294, // SMALLPR + RST_FILTER = 295, // FILTER + RST_CARD = 296, // CARD + RST_BOOL = 297, // BOOL + RST_DEBOOL = 298, // DEBOOL + RST_RED = 299, // RED + RST_DECLARATIVE = 300, // DECLARATIVE + RST_RECURSIVE = 301, // RECURSIVE + RST_IMPERATIVE = 302, // IMPERATIVE + RST_DEFINE = 303, // DEFINE + RST_STRUCT = 304, // STRUCT + RST_ASSIGN = 305, // ASSIGN + RST_ITERATE = 306, // ITERATE + RST_LP = 307, // LP + RST_RP = 308, // RP + RST_LC = 309, // LC + RST_RC = 310, // RC + RST_LS = 311, // LS + RST_RS = 312, // RS + RST_BAR = 313, // BAR + RST_COMMA = 314, // COMMA + RST_SEMICOLON = 315 // SEMICOLON + }; + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type yytokentype; + }; + + /// Token kind, as returned by yylex. + typedef token::yytokentype token_kind_type; + + /// Backward compatibility alias (Bison 3.6). + typedef token_kind_type token_type; + + /// Symbol kinds. + struct symbol_kind + { + enum symbol_kind_type + { + YYNTOKENS = 61, ///< Number of tokens. + S_YYEMPTY = -2, + S_YYEOF = 0, // "end of file" + S_YYerror = 1, // error + S_YYUNDEF = 2, // "invalid token" + S_LOCAL = 3, // LOCAL + S_GLOBAL = 4, // GLOBAL + S_FUNCTION = 5, // FUNCTION + S_PREDICATE = 6, // PREDICATE + S_RADICAL = 7, // RADICAL + S_INTEGER = 8, // INTEGER + S_INTSET = 9, // INTSET + S_EMPTYSET = 10, // EMPTYSET + S_PLUS = 11, // PLUS + S_MINUS = 12, // MINUS + S_MULTIPLY = 13, // MULTIPLY + S_GREATER = 14, // GREATER + S_LESSER = 15, // LESSER + S_GREATER_OR_EQ = 16, // GREATER_OR_EQ + S_LESSER_OR_EQ = 17, // LESSER_OR_EQ + S_EQUAL = 18, // EQUAL + S_NOTEQUAL = 19, // NOTEQUAL + S_FORALL = 20, // FORALL + S_EXISTS = 21, // EXISTS + S_NOT = 22, // NOT + S_EQUIVALENT = 23, // EQUIVALENT + S_IMPLICATION = 24, // IMPLICATION + S_OR = 25, // OR + S_AND = 26, // AND + S_IN = 27, // IN + S_NOTIN = 28, // NOTIN + S_SUBSET = 29, // SUBSET + S_SUBOR_EQ = 30, // SUBOR_EQ + S_NOTSUBSET = 31, // NOTSUBSET + S_DECART = 32, // DECART + S_UNION = 33, // UNION + S_INTERSECTION = 34, // INTERSECTION + S_SET_MINUS = 35, // SET_MINUS + S_SYMMINUS = 36, // SYMMINUS + S_BOOLEAN = 37, // BOOLEAN + S_BIGPR = 38, // BIGPR + S_SMALLPR = 39, // SMALLPR + S_FILTER = 40, // FILTER + S_CARD = 41, // CARD + S_BOOL = 42, // BOOL + S_DEBOOL = 43, // DEBOOL + S_RED = 44, // RED + S_DECLARATIVE = 45, // DECLARATIVE + S_RECURSIVE = 46, // RECURSIVE + S_IMPERATIVE = 47, // IMPERATIVE + S_DEFINE = 48, // DEFINE + S_STRUCT = 49, // STRUCT + S_ASSIGN = 50, // ASSIGN + S_ITERATE = 51, // ITERATE + S_LP = 52, // LP + S_RP = 53, // RP + S_LC = 54, // LC + S_RC = 55, // RC + S_LS = 56, // LS + S_RS = 57, // RS + S_BAR = 58, // BAR + S_COMMA = 59, // COMMA + S_SEMICOLON = 60, // SEMICOLON + S_YYACCEPT = 61, // $accept + S_expression = 62, // expression + S_global_declaration = 63, // global_declaration + S_function_name = 64, // function_name + S_logic_or_setexpr = 65, // logic_or_setexpr + S_function_decl = 66, // function_decl + S_arguments = 67, // arguments + S_declaration = 68, // declaration + S_variable = 69, // variable + S_var_enum = 70, // var_enum + S_var_all = 71, // var_all + S_logic = 72, // logic + S_logic_all = 73, // logic_all + S_logic_par = 74, // logic_par + S_logic_predicates = 75, // logic_predicates + S_binary_predicate = 76, // binary_predicate + S_logic_unary = 77, // logic_unary + S_logic_no_binary = 78, // logic_no_binary + S_quantifier = 79, // quantifier + S_quant_var = 80, // quant_var + S_quant_var_enum = 81, // quant_var_enum + S_logic_binary = 82, // logic_binary + S_setexpr = 83, // setexpr + S_operation_name = 84, // operation_name + S_setexpr_enum = 85, // setexpr_enum + S_setexpr_enum_min2 = 86, // setexpr_enum_min2 + S_literal = 87, // literal + S_identifier = 88, // identifier + S_setexpr_binary = 89, // setexpr_binary + S_setexpr_generators = 90, // setexpr_generators + S_enumeration = 91, // enumeration + S_tuple = 92, // tuple + S_boolean = 93, // boolean + S_filter_expression = 94, // filter_expression + S_declarative = 95, // declarative + S_recursion = 96, // recursion + S_imperative = 97, // imperative + S_imp_blocks = 98, // imp_blocks + S_imp_block = 99, // imp_block + S_RPE = 100, // RPE + S_RCE = 101 // RCE }; }; - /// (External) token type, as returned by yylex. - typedef token::yytokentype token_type; + /// (Internal) symbol kind. + typedef symbol_kind::symbol_kind_type symbol_kind_type; - /// Symbol type: an internal symbol number. - typedef int symbol_number_type; - - /// The symbol type number to denote an empty symbol. - enum { empty_symbol = -2 }; - - /// Internal symbol number for tokens (subsumed by symbol_number_type). - typedef unsigned char token_number_type; + /// The number of tokens. + static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS; /// A complete symbol. /// - /// Expects its Base type to provide access to the symbol type - /// via type_get (). + /// Expects its Base type to provide access to the symbol kind + /// via kind (). /// /// Provide access to semantic value. template @@ -316,7 +512,10 @@ namespace ccl { namespace rslang { namespace detail { #if 201103L <= YY_CPLUSPLUS /// Move constructor. - basic_symbol (basic_symbol&& that); + basic_symbol (basic_symbol&& that) + : Base (std::move (that)) + , value (std::move (that.value)) + {} #endif /// Copy constructor. @@ -340,6 +539,15 @@ namespace ccl { namespace rslang { namespace detail { Base::clear (); } + /// The user-facing name of this symbol. + std::string name () const YY_NOEXCEPT + { + return RSParserImpl::symbol_name (this->kind ()); + } + + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT; + /// Whether empty. bool empty () const YY_NOEXCEPT; @@ -357,52 +565,61 @@ namespace ccl { namespace rslang { namespace detail { }; /// Type access provider for token (enum) based symbols. - struct by_type + struct by_kind { /// Default constructor. - by_type (); + by_kind (); #if 201103L <= YY_CPLUSPLUS /// Move constructor. - by_type (by_type&& that); + by_kind (by_kind&& that); #endif /// Copy constructor. - by_type (const by_type& that); + by_kind (const by_kind& that); - /// The symbol type as needed by the constructor. - typedef token_type kind_type; + /// The symbol kind as needed by the constructor. + typedef token_kind_type kind_type; /// Constructor from (external) token numbers. - by_type (kind_type t); + by_kind (kind_type t); /// Record that this symbol is empty. void clear (); - /// Steal the symbol type from \a that. - void move (by_type& that); + /// Steal the symbol kind from \a that. + void move (by_kind& that); /// The (internal) type number (corresponding to \a type). /// \a empty when empty. - symbol_number_type type_get () const YY_NOEXCEPT; + symbol_kind_type kind () const YY_NOEXCEPT; - /// The token. - token_type token () const YY_NOEXCEPT; + /// Backward compatibility (Bison 3.6). + symbol_kind_type type_get () const YY_NOEXCEPT; - /// The symbol type. - /// \a empty_symbol when empty. - /// An int, not token_number_type, to be able to store empty_symbol. - int type; + /// The symbol kind. + /// \a S_YYEMPTY when empty. + symbol_kind_type kind_; }; + /// Backward compatibility for a private implementation detail (Bison 3.6). + typedef by_kind by_type; + /// "External" symbols: returned by the scanner. - struct symbol_type : basic_symbol + struct symbol_type : basic_symbol {}; /// Build a parser object. RSParserImpl (ParserState* state_yyarg); virtual ~RSParserImpl (); +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + RSParserImpl (const RSParserImpl&) = delete; + /// Non copyable. + RSParserImpl& operator= (const RSParserImpl&) = delete; +#endif + /// Parse. An alias for parse (). /// \returns 0 iff parsing succeeded. int operator() (); @@ -432,26 +649,51 @@ namespace ccl { namespace rslang { namespace detail { /// Report a syntax error. void error (const syntax_error& err); + /// The user-facing name of the symbol whose (internal) number is + /// YYSYMBOL. No bounds checking. + static std::string symbol_name (symbol_kind_type yysymbol); + + class context + { + public: + context (const RSParserImpl& yyparser, const symbol_type& yyla); + const symbol_type& lookahead () const { return yyla_; } + symbol_kind_type token () const { return yyla_.kind (); } + /// Put in YYARG at most YYARGN of the expected tokens, and return the + /// number of tokens stored in YYARG. If YYARG is null, return the + /// number of expected tokens (guaranteed to be less than YYNTOKENS). + int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; + + private: + const RSParserImpl& yyparser_; + const symbol_type& yyla_; + }; + private: - /// This class is not copyable. +#if YY_CPLUSPLUS < 201103L + /// Non copyable. RSParserImpl (const RSParserImpl&); + /// Non copyable. RSParserImpl& operator= (const RSParserImpl&); +#endif - /// State numbers. - typedef int state_type; + + /// Stored state numbers (used for stacks). + typedef unsigned char state_type; + + /// The arguments of the error message. + int yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const; /// Generate an error message. - /// \param yystate the state where the error occurred. - /// \param yyla the lookahead token. - virtual std::string yysyntax_error_ (state_type yystate, - const symbol_type& yyla) const; - + /// \param yyctx the context in which the error occurred. + virtual std::string yysyntax_error_ (const context& yyctx) const; /// Compute post-reduction state. /// \param yystate the current state /// \param yysym the nonterminal to push on the stack - state_type yy_lr_goto_state_ (state_type yystate, int yysym); + static state_type yy_lr_goto_state_ (state_type yystate, int yysym); /// Whether the given \c yypact_ value indicates a defaulted state. /// \param yyvalue the value to check @@ -464,63 +706,66 @@ namespace ccl { namespace rslang { namespace detail { static const signed char yypact_ninf_; static const signed char yytable_ninf_; - /// Convert a scanner token number \a t to a symbol number. - static token_number_type yytranslate_ (int t); - - // Tables. - // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - // STATE-NUM. - static const short yypact_[]; - - // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - // Performed when YYTABLE does not specify something else to do. Zero - // means the default is an error. - static const unsigned char yydefact_[]; - - // YYPGOTO[NTERM-NUM]. - static const short yypgoto_[]; - - // YYDEFGOTO[NTERM-NUM]. - static const short yydefgoto_[]; - - // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - // positive, shift that token. If negative, reduce the rule whose - // number is the opposite. If YYTABLE_NINF, syntax error. - static const short yytable_[]; - - static const short yycheck_[]; - - // YYSTOS[STATE-NUM] -- The (internal number of the) accessing - // symbol of state STATE-NUM. - static const unsigned char yystos_[]; - - // YYR1[YYN] -- Symbol number of symbol that rule YYN derives. - static const unsigned char yyr1_[]; - - // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. - static const unsigned char yyr2_[]; - + /// Convert a scanner token kind \a t to a symbol kind. + /// In theory \a t should be a token_kind_type, but character literals + /// are valid, yet not members of the token_type enum. + static symbol_kind_type yytranslate_ (int t); /// Convert the symbol name \a n to a form suitable for a diagnostic. - static std::string yytnamerr_ (const char *n); - + static std::string yytnamerr_ (const char *yystr); /// For a symbol, its name in clear. static const char* const yytname_[]; + + + // Tables. + // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + // STATE-NUM. + static const short yypact_[]; + + // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + // Performed when YYTABLE does not specify something else to do. Zero + // means the default is an error. + static const signed char yydefact_[]; + + // YYPGOTO[NTERM-NUM]. + static const short yypgoto_[]; + + // YYDEFGOTO[NTERM-NUM]. + static const short yydefgoto_[]; + + // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + // positive, shift that token. If negative, reduce the rule whose + // number is the opposite. If YYTABLE_NINF, syntax error. + static const short yytable_[]; + + static const short yycheck_[]; + + // YYSTOS[STATE-NUM] -- The (internal number of the) accessing + // symbol of state STATE-NUM. + static const signed char yystos_[]; + + // YYR1[YYN] -- Symbol number of symbol that rule YYN derives. + static const signed char yyr1_[]; + + // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. + static const signed char yyr2_[]; + + #if YYDEBUG - // YYRLINE[YYN] -- Source line where rule number YYN was defined. - static const unsigned short yyrline_[]; + // YYRLINE[YYN] -- Source line where rule number YYN was defined. + static const short yyrline_[]; /// Report on the debug stream that the rule \a r is going to be reduced. - virtual void yy_reduce_print_ (int r); + virtual void yy_reduce_print_ (int r) const; /// Print the state stack on the debug stream. - virtual void yystack_print_ (); + virtual void yy_stack_print_ () const; /// Debugging level. int yydebug_; /// Debug stream. std::ostream* yycdebug_; - /// \brief Display a symbol type, value and location. + /// \brief Display a symbol kind, value and location. /// \param yyo The output stream. /// \param yysym The symbol. template @@ -541,7 +786,7 @@ namespace ccl { namespace rslang { namespace detail { /// Default constructor. by_state () YY_NOEXCEPT; - /// The symbol type as needed by the constructor. + /// The symbol kind as needed by the constructor. typedef state_type kind_type; /// Constructor. @@ -553,15 +798,16 @@ namespace ccl { namespace rslang { namespace detail { /// Record that this symbol is empty. void clear () YY_NOEXCEPT; - /// Steal the symbol type from \a that. + /// Steal the symbol kind from \a that. void move (by_state& that); - /// The (internal) type number (corresponding to \a state). - /// \a empty_symbol when empty. - symbol_number_type type_get () const YY_NOEXCEPT; + /// The symbol kind (corresponding to \a state). + /// \a symbol_kind::S_YYEMPTY when empty. + symbol_kind_type kind () const YY_NOEXCEPT; /// The state number used to denote an empty symbol. - enum { empty_state = -1 }; + /// We use the initial state, as it does not have a value. + enum { empty_state = 0 }; /// The state. /// \a empty when empty. @@ -583,6 +829,10 @@ namespace ccl { namespace rslang { namespace detail { /// Assignment, needed by push_back by some old implementations. /// Moves the contents of that. stack_symbol_type& operator= (stack_symbol_type& that); + + /// Assignment, needed by push_back by other implementations. + /// Needed by some other old implementations. + stack_symbol_type& operator= (const stack_symbol_type& that); #endif }; @@ -592,48 +842,38 @@ namespace ccl { namespace rslang { namespace detail { { public: // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; + typedef typename S::iterator iterator; + typedef typename S::const_iterator const_iterator; typedef typename S::size_type size_type; + typedef typename std::ptrdiff_t index_type; stack (size_type n = 200) : seq_ (n) {} +#if 201103L <= YY_CPLUSPLUS + /// Non copyable. + stack (const stack&) = delete; + /// Non copyable. + stack& operator= (const stack&) = delete; +#endif + /// Random access. /// /// Index 0 returns the topmost element. - T& - operator[] (size_type i) + const T& + operator[] (index_type i) const { - return seq_[size () - 1 - i]; + return seq_[size_type (size () - 1 - i)]; } /// Random access. /// /// Index 0 returns the topmost element. T& - operator[] (int i) + operator[] (index_type i) { - return operator[] (size_type (i)); - } - - /// Random access. - /// - /// Index 0 returns the topmost element. - const T& - operator[] (size_type i) const - { - return seq_[size () - 1 - i]; - } - - /// Random access. - /// - /// Index 0 returns the topmost element. - const T& - operator[] (int i) const - { - return operator[] (size_type (i)); + return seq_[size_type (size () - 1 - i)]; } /// Steal the contents of \a t. @@ -648,7 +888,7 @@ namespace ccl { namespace rslang { namespace detail { /// Pop elements from the stack. void - pop (int n = 1) YY_NOEXCEPT + pop (std::ptrdiff_t n = 1) YY_NOEXCEPT { for (; 0 < n; --n) seq_.pop_back (); @@ -662,49 +902,53 @@ namespace ccl { namespace rslang { namespace detail { } /// Number of elements on the stack. - size_type + index_type size () const YY_NOEXCEPT { - return seq_.size (); + return index_type (seq_.size ()); } /// Iterator on top of the stack (going downwards). const_iterator begin () const YY_NOEXCEPT { - return seq_.rbegin (); + return seq_.begin (); } /// Bottom of the stack. const_iterator end () const YY_NOEXCEPT { - return seq_.rend (); + return seq_.end (); } /// Present a slice of the top of a stack. class slice { public: - slice (const stack& stack, int range) + slice (const stack& stack, index_type range) : stack_ (stack) , range_ (range) {} const T& - operator[] (int i) const + operator[] (index_type i) const { return stack_[range_ - i]; } private: const stack& stack_; - int range_; + index_type range_; }; private: +#if YY_CPLUSPLUS < 201103L + /// Non copyable. stack (const stack&); + /// Non copyable. stack& operator= (const stack&); +#endif /// The wrapped container. S seq_; }; @@ -737,24 +981,21 @@ namespace ccl { namespace rslang { namespace detail { /// Constants. enum { - yyeof_ = 0, yylast_ = 589, ///< Last index in yytable_. yynnts_ = 41, ///< Number of nonterminal symbols. - yyfinal_ = 85, ///< Termination state number. - yyterror_ = 1, - yyerrcode_ = 256, - yyntokens_ = 61 ///< Number of tokens. + yyfinal_ = 85 ///< Termination state number. }; // User arguments. ParserState* state; + }; -#line 11 "RSParserImpl.y" // lalr1.cc:401 +#line 15 "RSParserImpl.y" } } } // ccl::rslang::detail -#line 758 "../header/RSParserImpl.h" // lalr1.cc:401 +#line 999 "../header/RSParserImpl.h" diff --git a/ccl/rslang/header/SDImplementation.h b/ccl/rslang/header/SDImplementation.h index 4e20eb2..bf52336 100644 --- a/ccl/rslang/header/SDImplementation.h +++ b/ccl/rslang/header/SDImplementation.h @@ -154,7 +154,7 @@ private: uint32_t counter{ 0 }; public: - explicit Iterator(const SDDecartian& decartaian, bool isCompleted = false); + explicit Iterator(const SDDecartian& base, bool isCompleted = false); public: using iterator_category = std::forward_iterator_tag; diff --git a/ccl/rslang/include/ccl/rslang/ParserState.hpp b/ccl/rslang/include/ccl/rslang/ParserState.hpp index 0f5969c..a67ecb9 100644 --- a/ccl/rslang/include/ccl/rslang/ParserState.hpp +++ b/ccl/rslang/include/ccl/rslang/ParserState.hpp @@ -5,6 +5,7 @@ #include "ccl/rslang/RSErrorCodes.hpp" #include +#include namespace ccl::rslang::detail { @@ -18,6 +19,8 @@ struct Node { public: explicit Node(Token token) noexcept : token{ std::move(token) } {} + explicit Node(TokenID id, StrRange pos, TokenData val = {}) noexcept + : Node(Token(id, pos, std::move(val))) {} }; struct ParserState { diff --git a/ccl/rslang/include/ccl/rslang/RSErrorCodes.hpp b/ccl/rslang/include/ccl/rslang/RSErrorCodes.hpp index b7a6b2a..c854cab 100644 --- a/ccl/rslang/include/ccl/rslang/RSErrorCodes.hpp +++ b/ccl/rslang/include/ccl/rslang/RSErrorCodes.hpp @@ -14,7 +14,7 @@ enum class LexerEID : uint32_t { //! Syntactic errors enumeration enum class ParseEID : uint32_t { syntax = 0x8400, // Неизвестная синтаксическая ошибка - missingParanthesis = 0x8406, // Пропущена скобка ')' + missingParenthesis = 0x8406, // Пропущена скобка ')' missingCurlyBrace = 0x8407, // Пропущена скобка '}' invalidQuantifier = 0x8408, // Некорректная кванторная декларация expectedDeclaration = 0x8414, // Ожидалось объявление аргументов diff --git a/ccl/rslang/src/Interpreter.cpp b/ccl/rslang/src/Interpreter.cpp index a2cb6ab..e08aae2 100644 --- a/ccl/rslang/src/Interpreter.cpp +++ b/ccl/rslang/src/Interpreter.cpp @@ -2,6 +2,8 @@ #include "ccl/rslang/Interpreter.h" +#include + namespace ccl::rslang { Interpreter::Interpreter(const TypeContext& types, SyntaxTreeContext ast, DataContext data) diff --git a/ccl/rslang/src/RSParser.cpp b/ccl/rslang/src/RSParser.cpp index c4630f5..9da87c0 100644 --- a/ccl/rslang/src/RSParser.cpp +++ b/ccl/rslang/src/RSParser.cpp @@ -17,6 +17,8 @@ #pragma warning( disable : 26418 26415 26440 ) #endif +#include + namespace ccl::rslang::detail { RSParser::RSParser(std::optional reporter) @@ -58,15 +60,13 @@ int yylex(RawNode* yylval, ParserState* state) { void RSParserImpl::error(const std::string& /*msg*/) {} RawNode AddNode(const TokenID token, RawNode son) { - auto result = std::make_shared(Token(token, son->token.pos)); - + auto result = std::make_shared(token, son->token.pos); result->children.emplace_back(son); return result; } RawNode AddNode(const TokenID token, RawNode son1, RawNode son2) { - auto result = std::make_shared( - Token{ token, StrRange{ son1->token.pos.start, son2->token.pos.finish } }); + auto result = std::make_shared(token, StrRange{ son1->token.pos.start, son2->token.pos.finish }); result->children.emplace_back(son1); result->children.emplace_back(son2); return result; @@ -87,19 +87,19 @@ RawNode UnaryOperation(RawNode operation, RawNode operand) { RawNode RemoveBrackets(RawNode br1, RawNode operand, RawNode br2) { operand->token.pos = StrRange{ br1->token.pos.start, br2->token.pos.finish }; - auto bracketNode = std::make_shared(Token(TokenID::PUNC_PL, operand->token.pos)); + auto bracketNode = std::make_shared(TokenID::PUNC_PL, operand->token.pos); bracketNode->children.emplace_back(operand); return bracketNode; } RawNode ReplaceBrackets(const TokenID token, RawNode br1, RawNode argList, RawNode br2) { - auto result = std::make_shared(Token(token, StrRange{ br1->token.pos.start, br2->token.pos.finish })); + auto result = std::make_shared(token, StrRange{ br1->token.pos.start, br2->token.pos.finish }); result->children = argList->children; return result; } RawNode Enumeration(const TokenID token, RawNode el1, RawNode el2) { - auto result = std::make_shared(Token(token, StrRange{ el1->token.pos.start, el2->token.pos.finish })); + auto result = std::make_shared(token, StrRange{ el1->token.pos.start, el2->token.pos.finish }); if (el1->token.id != token) { result->children.emplace_back(el1); } else { @@ -121,19 +121,27 @@ RawNode Quantifier(RawNode quant, RawNode declaration, RawNode domain, RawNode p return quant; } -RawNode FunctionDeclaration(RawNode start, RawNode argdecl, RawNode expr) { +RawNode FunctionDeclaration(RawNode start, RawNode argumentsDeclaration, RawNode expr) { auto result = std::make_shared( - Token{ TokenID::NT_FUNC_DEFINITION, StrRange{ start->token.pos.start, expr->token.pos.finish } }); - result->children.emplace_back(argdecl); + TokenID::NT_FUNC_DEFINITION, + StrRange{ start->token.pos.start, expr->token.pos.finish } + ); + result->children.emplace_back(argumentsDeclaration); result->children.emplace_back(expr); return result; } RawNode FunctionCall(RawNode function, RawNode args, RawNode rs) { auto result = std::make_shared( - Token{ TokenID::NT_FUNC_CALL, StrRange{ function->token.pos.start, rs->token.pos.finish } }); + TokenID::NT_FUNC_CALL, + StrRange{ function->token.pos.start, rs->token.pos.finish } + ); result->children.emplace_back(function); - result->children.insert(end(result->children), begin(args->children), end(args->children)); + result->children.insert( + end(result->children), + begin(args->children), + end(args->children) + ); return result; } @@ -144,48 +152,71 @@ RawNode FilterCall(RawNode filter, RawNode params, RawNode argument, RawNode rp) return filter; } -RawNode TextOperator(RawNode oper, RawNode args, RawNode rp) { - oper->token.pos.finish = rp->token.pos.finish; - oper->children.emplace_back(args); - return oper; +RawNode TextOperator(RawNode operatorName, RawNode args, RawNode rp) { + operatorName->token.pos.finish = rp->token.pos.finish; + operatorName->children.emplace_back(args); + return operatorName; } -RawNode Decartian(RawNode op1, RawNode decart, RawNode op2) { +RawNode Decartian(RawNode op1, RawNode decartian, RawNode op2) { if (op1->token.id == TokenID::DECART) { auto result = std::move(op1); result->token.pos.finish = op2->token.pos.finish; result->children.emplace_back(op2); return result; } else { - return BinaryOperation(std::move(op1), std::move(decart), std::move(op2)); + return BinaryOperation(std::move(op1), std::move(decartian), std::move(op2)); } } -RawNode TermDeclaration(RawNode lc, RawNode declaration, RawNode domain, RawNode predicate, RawNode rc) { +RawNode TermDeclaration( + RawNode lc, + RawNode declaration, + RawNode domain, + RawNode predicate, + RawNode rc +) { auto result = std::make_shared( - Token{ TokenID::NT_DECLARATIVE_EXPR, StrRange{ lc->token.pos.start, rc->token.pos.finish } }); + TokenID::NT_DECLARATIVE_EXPR, + StrRange{ lc->token.pos.start, rc->token.pos.finish } + ); result->children.emplace_back(declaration); result->children.emplace_back(domain); result->children.emplace_back(predicate); return result; } -RawNode FullRecursion(RawNode rec, RawNode localid, - RawNode domain, RawNode condition, RawNode iteration, RawNode rc) { +RawNode FullRecursion( + RawNode rec, + RawNode declaration, + RawNode domain, + RawNode condition, + RawNode iteration, + RawNode rc +) { auto result = std::make_shared( - Token{ TokenID::NT_RECURSIVE_FULL, StrRange{ rec->token.pos.start, rc->token.pos.finish } }); - result->children.emplace_back(localid); + TokenID::NT_RECURSIVE_FULL, + StrRange{ rec->token.pos.start, rc->token.pos.finish } + ); + result->children.emplace_back(declaration); result->children.emplace_back(domain); result->children.emplace_back(condition); result->children.emplace_back(iteration); return result; } -RawNode ShortRecursion(RawNode rec, RawNode localid, - RawNode domain, RawNode iteration, RawNode rc) { +RawNode ShortRecursion( + RawNode rec, + RawNode declaration, + RawNode domain, + RawNode iteration, + RawNode rc +) { auto result = std::make_shared( - Token{ TokenID::NT_RECURSIVE_SHORT, StrRange{ rec->token.pos.start, rc->token.pos.finish } }); - result->children.emplace_back(localid); + TokenID::NT_RECURSIVE_SHORT, + StrRange{ rec->token.pos.start, rc->token.pos.finish } + ); + result->children.emplace_back(declaration); result->children.emplace_back(domain); result->children.emplace_back(iteration); return result; @@ -193,7 +224,9 @@ RawNode ShortRecursion(RawNode rec, RawNode localid, RawNode Imperative(RawNode imp, RawNode value, RawNode actions, RawNode rc) { auto result = std::make_shared( - Token{ TokenID::NT_IMPERATIVE_EXPR, StrRange{ imp->token.pos.start, rc->token.pos.finish } }); + TokenID::NT_IMPERATIVE_EXPR, + StrRange{ imp->token.pos.start, rc->token.pos.finish } + ); result->children.emplace_back(value); result->children.insert(end(result->children), begin(actions->children), end(actions->children)); return result; diff --git a/ccl/rslang/src/RSParserImpl.cpp b/ccl/rslang/src/RSParserImpl.cpp index c54d0d4..ab15340 100644 --- a/ccl/rslang/src/RSParserImpl.cpp +++ b/ccl/rslang/src/RSParserImpl.cpp @@ -1,8 +1,8 @@ -// A Bison parser, made by GNU Bison 3.3.2. +// A Bison parser, made by GNU Bison 3.7.4. // Skeleton implementation for Bison LALR(1) parsers in C++ -// Copyright (C) 2002-2015, 2018-2019 Free Software Foundation, Inc. +// Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -30,15 +30,16 @@ // This special exception was added by the Free Software Foundation in // version 2.2 of Bison. -// Undocumented macros, especially those whose name start with YY_, -// are private implementation details. Do not rely on them. +// DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, +// especially those whose name start with YY_ or yy_. They are +// private implementation details that can be changed or removed. -// // "%code top" blocks. -#line 16 "RSParserImpl.y" // lalr1.cc:423 +// "%code top" blocks. +#line 24 "RSParserImpl.y" #ifdef _MSC_VER #pragma warning( push ) - #pragma warning( disable : 26434 26438 26440 26446 26447 26448 26456 ) + #pragma warning( disable : 4244 26434 26438 26440 26446 26447 26448 26456 ) #pragma warning( disable : 26460 26477 26481 26482 26493 26494 26495 26496 ) #endif @@ -54,7 +55,7 @@ #endif -#line 58 "RSParserImpl.cpp" // lalr1.cc:423 +#line 59 "RSParserImpl.cpp" @@ -76,6 +77,7 @@ # endif #endif + // Whether we are compiled with exception support. #ifndef YY_EXCEPTIONS # if defined __GNUC__ && !defined __EXCEPTIONS @@ -87,9 +89,6 @@ -// Suppress unused-variable warnings by "using" E. -#define YYUSE(E) ((void) (E)) - // Enable debugging if requested. #if YYDEBUG @@ -115,7 +114,7 @@ # define YY_STACK_PRINT() \ do { \ if (yydebug_) \ - yystack_print_ (); \ + yy_stack_print_ (); \ } while (false) #else // !YYDEBUG @@ -135,57 +134,17 @@ #define YYERROR goto yyerrorlab #define YYRECOVERING() (!!yyerrstatus_) -#line 11 "RSParserImpl.y" // lalr1.cc:510 +#line 15 "RSParserImpl.y" namespace ccl { namespace rslang { namespace detail { -#line 141 "RSParserImpl.cpp" // lalr1.cc:510 - - /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - RSParserImpl::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - else - goto append; - - append: - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } - +#line 140 "RSParserImpl.cpp" /// Build a parser object. RSParserImpl::RSParserImpl (ParserState* state_yyarg) - : #if YYDEBUG - yydebug_ (false), + : yydebug_ (false), yycdebug_ (&std::cerr), +#else + : #endif state (state_yyarg) {} @@ -197,18 +156,10 @@ namespace ccl { namespace rslang { namespace detail { {} /*---------------. - | Symbol types. | + | symbol kinds. | `---------------*/ // basic_symbol. -#if 201103L <= YY_CPLUSPLUS - template - RSParserImpl::basic_symbol::basic_symbol (basic_symbol&& that) - : Base (std::move (that)) - , value (std::move (that.value)) - {} -#endif - template RSParserImpl::basic_symbol::basic_symbol (const basic_symbol& that) : Base (that) @@ -229,11 +180,18 @@ namespace ccl { namespace rslang { namespace detail { , value (YY_MOVE (v)) {} + template + RSParserImpl::symbol_kind_type + RSParserImpl::basic_symbol::type_get () const YY_NOEXCEPT + { + return this->kind (); + } + template bool RSParserImpl::basic_symbol::empty () const YY_NOEXCEPT { - return Base::type_get () == empty_symbol; + return this->kind () == symbol_kind::S_YYEMPTY; } template @@ -244,44 +202,50 @@ namespace ccl { namespace rslang { namespace detail { value = YY_MOVE (s.value); } - // by_type. - RSParserImpl::by_type::by_type () - : type (empty_symbol) + // by_kind. + RSParserImpl::by_kind::by_kind () + : kind_ (symbol_kind::S_YYEMPTY) {} #if 201103L <= YY_CPLUSPLUS - RSParserImpl::by_type::by_type (by_type&& that) - : type (that.type) + RSParserImpl::by_kind::by_kind (by_kind&& that) + : kind_ (that.kind_) { that.clear (); } #endif - RSParserImpl::by_type::by_type (const by_type& that) - : type (that.type) + RSParserImpl::by_kind::by_kind (const by_kind& that) + : kind_ (that.kind_) {} - RSParserImpl::by_type::by_type (token_type t) - : type (yytranslate_ (t)) + RSParserImpl::by_kind::by_kind (token_kind_type t) + : kind_ (yytranslate_ (t)) {} void - RSParserImpl::by_type::clear () + RSParserImpl::by_kind::clear () { - type = empty_symbol; + kind_ = symbol_kind::S_YYEMPTY; } void - RSParserImpl::by_type::move (by_type& that) + RSParserImpl::by_kind::move (by_kind& that) { - type = that.type; + kind_ = that.kind_; that.clear (); } - int - RSParserImpl::by_type::type_get () const YY_NOEXCEPT + RSParserImpl::symbol_kind_type + RSParserImpl::by_kind::kind () const YY_NOEXCEPT { - return type; + return kind_; + } + + RSParserImpl::symbol_kind_type + RSParserImpl::by_kind::type_get () const YY_NOEXCEPT + { + return this->kind (); } @@ -311,13 +275,13 @@ namespace ccl { namespace rslang { namespace detail { : state (s) {} - RSParserImpl::symbol_number_type - RSParserImpl::by_state::type_get () const YY_NOEXCEPT + RSParserImpl::symbol_kind_type + RSParserImpl::by_state::kind () const YY_NOEXCEPT { if (state == empty_state) - return empty_symbol; + return symbol_kind::S_YYEMPTY; else - return yystos_[state]; + return YY_CAST (symbol_kind_type, yystos_[+state]); } RSParserImpl::stack_symbol_type::stack_symbol_type () @@ -336,10 +300,18 @@ namespace ccl { namespace rslang { namespace detail { : super_type (s, YY_MOVE (that.value)) { // that is emptied. - that.type = empty_symbol; + that.kind_ = symbol_kind::S_YYEMPTY; } #if YY_CPLUSPLUS < 201103L + RSParserImpl::stack_symbol_type& + RSParserImpl::stack_symbol_type::operator= (const stack_symbol_type& that) + { + state = that.state; + value = that.value; + return *this; + } + RSParserImpl::stack_symbol_type& RSParserImpl::stack_symbol_type::operator= (stack_symbol_type& that) { @@ -359,28 +331,26 @@ namespace ccl { namespace rslang { namespace detail { YY_SYMBOL_PRINT (yymsg, yysym); // User destructor. - YYUSE (yysym.type_get ()); + YYUSE (yysym.kind ()); } #if YYDEBUG template void - RSParserImpl::yy_print_ (std::ostream& yyo, - const basic_symbol& yysym) const + RSParserImpl::yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const { std::ostream& yyoutput = yyo; YYUSE (yyoutput); - symbol_number_type yytype = yysym.type_get (); -#if defined __GNUC__ && ! defined __clang__ && ! defined __ICC && __GNUC__ * 100 + __GNUC_MINOR__ <= 408 - // Avoid a (spurious) G++ 4.8 warning about "array subscript is - // below array bounds". if (yysym.empty ()) - std::abort (); -#endif - yyo << (yytype < yyntokens_ ? "token" : "nterm") - << ' ' << yytname_[yytype] << " ("; - YYUSE (yytype); - yyo << ')'; + yyo << "empty symbol"; + else + { + symbol_kind_type yykind = yysym.kind (); + yyo << (yykind < YYNTOKENS ? "token" : "nterm") + << ' ' << yysym.name () << " ("; + YYUSE (yykind); + yyo << ')'; + } } #endif @@ -439,11 +409,11 @@ namespace ccl { namespace rslang { namespace detail { RSParserImpl::state_type RSParserImpl::yy_lr_goto_state_ (state_type yystate, int yysym) { - int yyr = yypgoto_[yysym - yyntokens_] + yystate; + int yyr = yypgoto_[yysym - YYNTOKENS] + yystate; if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) return yytable_[yyr]; else - return yydefgoto_[yysym - yyntokens_]; + return yydefgoto_[yysym - YYNTOKENS]; } bool @@ -467,7 +437,6 @@ namespace ccl { namespace rslang { namespace detail { int RSParserImpl::parse () { - // State. int yyn; /// Length of the RHS of the rule being reduced. int yylen = 0; @@ -500,7 +469,8 @@ namespace ccl { namespace rslang { namespace detail { | yynewstate -- push a new symbol on the stack. | `-----------------------------------------------*/ yynewstate: - YYCDEBUG << "Entering state " << yystack_[0].state << '\n'; + YYCDEBUG << "Entering state " << int (yystack_[0].state) << '\n'; + YY_STACK_PRINT (); // Accept? if (yystack_[0].state == yyfinal_) @@ -514,19 +484,19 @@ namespace ccl { namespace rslang { namespace detail { `-----------*/ yybackup: // Try to take a decision without lookahead. - yyn = yypact_[yystack_[0].state]; + yyn = yypact_[+yystack_[0].state]; if (yy_pact_value_is_default_ (yyn)) goto yydefault; // Read a lookahead token. if (yyla.empty ()) { - YYCDEBUG << "Reading a token: "; + YYCDEBUG << "Reading a token\n"; #if YY_EXCEPTIONS try #endif // YY_EXCEPTIONS { - yyla.type = yytranslate_ (yylex (&yyla.value, state)); + yyla.kind_ = yytranslate_ (yylex (&yyla.value, state)); } #if YY_EXCEPTIONS catch (const syntax_error& yyexc) @@ -539,11 +509,23 @@ namespace ccl { namespace rslang { namespace detail { } YY_SYMBOL_PRINT ("Next token is", yyla); + if (yyla.kind () == symbol_kind::S_YYerror) + { + // The scanner already issued an error message, process directly + // to error recovery. But do not keep the error token as + // lookahead, it is too special and may lead us to an endless + // loop in error recovery. */ + yyla.kind_ = symbol_kind::S_YYUNDEF; + goto yyerrlab1; + } + /* If the proper action on seeing token YYLA.TYPE is to reduce or to detect an error, take that action. */ - yyn += yyla.type_get (); - if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ()) - goto yydefault; + yyn += yyla.kind (); + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ()) + { + goto yydefault; + } // Reduce or error. yyn = yytable_[yyn]; @@ -560,7 +542,7 @@ namespace ccl { namespace rslang { namespace detail { --yyerrstatus_; // Shift the lookahead token. - yypush_ ("Shifting", yyn, YY_MOVE (yyla)); + yypush_ ("Shifting", state_type (yyn), YY_MOVE (yyla)); goto yynewstate; @@ -568,7 +550,7 @@ namespace ccl { namespace rslang { namespace detail { | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: - yyn = yydefact_[yystack_[0].state]; + yyn = yydefact_[+yystack_[0].state]; if (yyn == 0) goto yyerrlab; goto yyreduce; @@ -602,368 +584,369 @@ namespace ccl { namespace rslang { namespace detail { { switch (yyn) { - case 3: -#line 151 "RSParserImpl.y" // lalr1.cc:919 - { state->FinalizeExpression(yystack_[0].value); } -#line 609 "RSParserImpl.cpp" // lalr1.cc:919 + case 3: // expression: logic_or_setexpr +#line 263 "RSParserImpl.y" + { state->FinalizeExpression(yystack_[0].value); } +#line 591 "RSParserImpl.cpp" break; - case 4: -#line 152 "RSParserImpl.y" // lalr1.cc:919 - { state->FinalizeExpression(yystack_[0].value); } -#line 615 "RSParserImpl.cpp" // lalr1.cc:919 + case 4: // expression: function_decl +#line 264 "RSParserImpl.y" + { state->FinalizeExpression(yystack_[0].value); } +#line 597 "RSParserImpl.cpp" break; - case 7: -#line 159 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = FunctionDeclaration(yystack_[3].value, yystack_[2].value, yystack_[0].value); } -#line 621 "RSParserImpl.cpp" // lalr1.cc:919 + case 5: // global_declaration: GLOBAL DEFINE +#line 268 "RSParserImpl.y" + { state->FinalizeCstEmpty(yystack_[1].value, yystack_[0].value); } +#line 603 "RSParserImpl.cpp" break; - case 8: -#line 160 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::expectedDeclaration); YYABORT; } -#line 627 "RSParserImpl.cpp" // lalr1.cc:919 + case 6: // global_declaration: GLOBAL STRUCT setexpr +#line 269 "RSParserImpl.y" + { state->FinalizeCstExpression(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 609 "RSParserImpl.cpp" break; - case 9: -#line 163 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::NT_ARGUMENTS, yystack_[0].value); } -#line 633 "RSParserImpl.cpp" // lalr1.cc:919 + case 7: // global_declaration: GLOBAL DEFINE logic_or_setexpr +#line 270 "RSParserImpl.y" + { state->FinalizeCstExpression(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 615 "RSParserImpl.cpp" break; - case 10: -#line 164 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Enumeration(TokenID::NT_ARGUMENTS, yystack_[2].value, yystack_[0].value); } -#line 639 "RSParserImpl.cpp" // lalr1.cc:919 + case 8: // global_declaration: function_name DEFINE function_decl +#line 271 "RSParserImpl.y" + { state->FinalizeCstExpression(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 621 "RSParserImpl.cpp" break; - case 11: -#line 165 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::expectedLocal); YYABORT; } -#line 645 "RSParserImpl.cpp" // lalr1.cc:919 + case 13: // function_decl: LS arguments RS logic_or_setexpr +#line 284 "RSParserImpl.y" + { yylhs.value = FunctionDeclaration(yystack_[3].value, yystack_[2].value, yystack_[0].value); } +#line 627 "RSParserImpl.cpp" break; - case 12: -#line 167 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::NT_ARG_DECL, yystack_[2].value, yystack_[0].value); } -#line 651 "RSParserImpl.cpp" // lalr1.cc:919 + case 14: // function_decl: LS error +#line 285 "RSParserImpl.y" + { state->OnError(ParseEID::expectedDeclaration); YYABORT; } +#line 633 "RSParserImpl.cpp" break; - case 13: -#line 168 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::expectedDeclaration); YYABORT; } -#line 657 "RSParserImpl.cpp" // lalr1.cc:919 + case 15: // arguments: declaration +#line 290 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::NT_ARGUMENTS, yystack_[0].value); } +#line 639 "RSParserImpl.cpp" break; - case 14: -#line 172 "RSParserImpl.y" // lalr1.cc:919 - { state->FinalizeCstEmpty(yystack_[1].value, yystack_[0].value); } -#line 663 "RSParserImpl.cpp" // lalr1.cc:919 + case 16: // arguments: arguments COMMA declaration +#line 291 "RSParserImpl.y" + { yylhs.value = Enumeration(TokenID::NT_ARGUMENTS, yystack_[2].value, yystack_[0].value); } +#line 645 "RSParserImpl.cpp" break; - case 15: -#line 173 "RSParserImpl.y" // lalr1.cc:919 - { state->FinalizeCstExpression(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 669 "RSParserImpl.cpp" // lalr1.cc:919 + case 17: // arguments: arguments COMMA error +#line 292 "RSParserImpl.y" + { state->OnError(ParseEID::expectedLocal); YYABORT; } +#line 651 "RSParserImpl.cpp" break; - case 16: -#line 174 "RSParserImpl.y" // lalr1.cc:919 - { state->FinalizeCstExpression(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 675 "RSParserImpl.cpp" // lalr1.cc:919 + case 18: // declaration: LOCAL IN setexpr +#line 295 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::NT_ARG_DECL, yystack_[2].value, yystack_[0].value); } +#line 657 "RSParserImpl.cpp" break; - case 17: -#line 175 "RSParserImpl.y" // lalr1.cc:919 - { state->FinalizeCstExpression(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 681 "RSParserImpl.cpp" // lalr1.cc:919 + case 19: // declaration: LOCAL error +#line 296 "RSParserImpl.y" + { state->OnError(ParseEID::expectedDeclaration); YYABORT; } +#line 663 "RSParserImpl.cpp" break; - case 26: -#line 190 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = RemoveBrackets(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 687 "RSParserImpl.cpp" // lalr1.cc:919 + case 21: // variable: LP var_enum RPE +#line 301 "RSParserImpl.y" + { yylhs.value = ReplaceBrackets(TokenID::NT_TUPLE_DECL, yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 669 "RSParserImpl.cpp" break; - case 27: -#line 191 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = RemoveBrackets(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 693 "RSParserImpl.cpp" // lalr1.cc:919 + case 22: // var_enum: var_all COMMA var_all +#line 304 "RSParserImpl.y" + { yylhs.value = Enumeration(TokenID::INTERRUPT, yystack_[2].value, yystack_[0].value); } +#line 675 "RSParserImpl.cpp" break; - case 28: -#line 193 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = UnaryOperation(yystack_[1].value, yystack_[0].value);} -#line 699 "RSParserImpl.cpp" // lalr1.cc:919 + case 23: // var_enum: var_all COMMA error +#line 305 "RSParserImpl.y" + { state->OnError(ParseEID::expectedLocal); YYABORT; } +#line 681 "RSParserImpl.cpp" break; - case 29: -#line 195 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Quantifier(yystack_[4].value, yystack_[3].value, yystack_[1].value, yystack_[0].value);} -#line 705 "RSParserImpl.cpp" // lalr1.cc:919 + case 31: // logic_par: LP logic_binary RPE +#line 323 "RSParserImpl.y" + { yylhs.value = RemoveBrackets(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 687 "RSParserImpl.cpp" break; - case 30: -#line 196 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::invalidQuantifier); YYABORT; } -#line 711 "RSParserImpl.cpp" // lalr1.cc:919 + case 32: // logic_par: LP logic_predicates RPE +#line 324 "RSParserImpl.y" + { yylhs.value = RemoveBrackets(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 693 "RSParserImpl.cpp" break; - case 31: -#line 197 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = FunctionCall(yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 717 "RSParserImpl.cpp" // lalr1.cc:919 + case 33: // logic_predicates: setexpr binary_predicate setexpr +#line 328 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 699 "RSParserImpl.cpp" break; - case 32: -#line 199 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 723 "RSParserImpl.cpp" // lalr1.cc:919 + case 45: // logic_unary: NOT logic_no_binary +#line 345 "RSParserImpl.y" + { yylhs.value = UnaryOperation(yystack_[1].value, yystack_[0].value);} +#line 705 "RSParserImpl.cpp" break; - case 33: -#line 201 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 729 "RSParserImpl.cpp" // lalr1.cc:919 + case 46: // logic_unary: quantifier quant_var IN setexpr logic_no_binary +#line 346 "RSParserImpl.y" + { yylhs.value = Quantifier(yystack_[4].value, yystack_[3].value, yystack_[1].value, yystack_[0].value);} +#line 711 "RSParserImpl.cpp" break; - case 34: -#line 202 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 735 "RSParserImpl.cpp" // lalr1.cc:919 + case 47: // logic_unary: quantifier error +#line 347 "RSParserImpl.y" + { state->OnError(ParseEID::invalidQuantifier); YYABORT; } +#line 717 "RSParserImpl.cpp" break; - case 35: -#line 203 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 741 "RSParserImpl.cpp" // lalr1.cc:919 + case 48: // logic_unary: PREDICATE LS setexpr_enum RS +#line 348 "RSParserImpl.y" + { yylhs.value = FunctionCall(yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 723 "RSParserImpl.cpp" break; - case 36: -#line 204 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 747 "RSParserImpl.cpp" // lalr1.cc:919 + case 56: // quant_var: LP error +#line 362 "RSParserImpl.y" + { state->OnError(ParseEID::invalidQuantifier); YYABORT; } +#line 729 "RSParserImpl.cpp" break; - case 39: -#line 209 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::invalidQuantifier); YYABORT; } -#line 753 "RSParserImpl.cpp" // lalr1.cc:919 + case 57: // quant_var_enum: quant_var COMMA quant_var +#line 365 "RSParserImpl.y" + { yylhs.value = Enumeration(TokenID::NT_ENUM_DECL, yystack_[2].value, yystack_[0].value); } +#line 735 "RSParserImpl.cpp" break; - case 40: -#line 211 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Enumeration(TokenID::NT_ENUM_DECL, yystack_[2].value, yystack_[0].value); } -#line 759 "RSParserImpl.cpp" // lalr1.cc:919 + case 58: // quant_var_enum: quant_var COMMA error +#line 366 "RSParserImpl.y" + { state->OnError(ParseEID::expectedLocal); YYABORT; } +#line 741 "RSParserImpl.cpp" break; - case 41: -#line 212 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::expectedLocal); YYABORT; } -#line 765 "RSParserImpl.cpp" // lalr1.cc:919 + case 59: // logic_binary: logic_all EQUIVALENT logic_all +#line 370 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 747 "RSParserImpl.cpp" break; - case 46: -#line 220 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = FunctionCall(yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 771 "RSParserImpl.cpp" // lalr1.cc:919 + case 60: // logic_binary: logic_all IMPLICATION logic_all +#line 371 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 753 "RSParserImpl.cpp" break; - case 47: -#line 221 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = TextOperator(yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 777 "RSParserImpl.cpp" // lalr1.cc:919 + case 61: // logic_binary: logic_all OR logic_all +#line 372 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 759 "RSParserImpl.cpp" break; - case 48: -#line 224 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 783 "RSParserImpl.cpp" // lalr1.cc:919 + case 62: // logic_binary: logic_all AND logic_all +#line 373 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 765 "RSParserImpl.cpp" break; - case 49: -#line 225 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 789 "RSParserImpl.cpp" // lalr1.cc:919 + case 67: // setexpr: FUNCTION LS setexpr_enum RS +#line 383 "RSParserImpl.y" + { yylhs.value = FunctionCall(yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 771 "RSParserImpl.cpp" break; - case 50: -#line 226 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 795 "RSParserImpl.cpp" // lalr1.cc:919 + case 68: // setexpr: operation_name LP setexpr RPE +#line 384 "RSParserImpl.y" + { yylhs.value = TextOperator(yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 777 "RSParserImpl.cpp" break; - case 51: -#line 227 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 801 "RSParserImpl.cpp" // lalr1.cc:919 + case 75: // setexpr_enum: setexpr +#line 395 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::INTERRUPT, yystack_[0].value); } +#line 783 "RSParserImpl.cpp" break; - case 52: -#line 228 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 807 "RSParserImpl.cpp" // lalr1.cc:919 + case 77: // setexpr_enum_min2: setexpr_enum COMMA setexpr +#line 399 "RSParserImpl.y" + { yylhs.value = Enumeration(TokenID::INTERRUPT, yystack_[2].value, yystack_[0].value); } +#line 789 "RSParserImpl.cpp" break; - case 53: -#line 229 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 813 "RSParserImpl.cpp" // lalr1.cc:919 + case 85: // setexpr_binary: setexpr PLUS setexpr +#line 416 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 795 "RSParserImpl.cpp" break; - case 54: -#line 230 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 819 "RSParserImpl.cpp" // lalr1.cc:919 + case 86: // setexpr_binary: setexpr MINUS setexpr +#line 417 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 801 "RSParserImpl.cpp" break; - case 55: -#line 231 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Decartian(yystack_[2].value, yystack_[1].value, yystack_[0].value);} -#line 825 "RSParserImpl.cpp" // lalr1.cc:919 + case 87: // setexpr_binary: setexpr MULTIPLY setexpr +#line 418 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 807 "RSParserImpl.cpp" break; - case 56: -#line 232 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = RemoveBrackets(yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 831 "RSParserImpl.cpp" // lalr1.cc:919 + case 88: // setexpr_binary: setexpr UNION setexpr +#line 419 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 813 "RSParserImpl.cpp" break; - case 60: -#line 238 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = FilterCall(yystack_[6].value, yystack_[4].value, yystack_[1].value, yystack_[0].value); } -#line 837 "RSParserImpl.cpp" // lalr1.cc:919 + case 89: // setexpr_binary: setexpr SET_MINUS setexpr +#line 420 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 819 "RSParserImpl.cpp" break; - case 64: -#line 243 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = ReplaceBrackets(TokenID::NT_ENUMERATION, yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 843 "RSParserImpl.cpp" // lalr1.cc:919 + case 90: // setexpr_binary: setexpr SYMMINUS setexpr +#line 421 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 825 "RSParserImpl.cpp" break; - case 65: -#line 245 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = ReplaceBrackets(TokenID::NT_TUPLE, yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 849 "RSParserImpl.cpp" // lalr1.cc:919 + case 91: // setexpr_binary: setexpr INTERSECTION setexpr +#line 422 "RSParserImpl.y" + { yylhs.value = BinaryOperation(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 831 "RSParserImpl.cpp" break; - case 66: -#line 247 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = TextOperator(yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 855 "RSParserImpl.cpp" // lalr1.cc:919 + case 92: // setexpr_binary: setexpr DECART setexpr +#line 423 "RSParserImpl.y" + { yylhs.value = Decartian(yystack_[2].value, yystack_[1].value, yystack_[0].value);} +#line 837 "RSParserImpl.cpp" break; - case 67: -#line 248 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = UnaryOperation(yystack_[1].value, yystack_[0].value); } -#line 861 "RSParserImpl.cpp" // lalr1.cc:919 + case 93: // setexpr_binary: LP setexpr_binary RPE +#line 424 "RSParserImpl.y" + { yylhs.value = RemoveBrackets(yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 843 "RSParserImpl.cpp" break; - case 68: -#line 250 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::INTERRUPT, yystack_[0].value); } -#line 867 "RSParserImpl.cpp" // lalr1.cc:919 + case 101: // enumeration: LC setexpr_enum RC +#line 437 "RSParserImpl.y" + { yylhs.value = ReplaceBrackets(TokenID::NT_ENUMERATION, yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 849 "RSParserImpl.cpp" break; - case 70: -#line 253 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Enumeration(TokenID::INTERRUPT, yystack_[2].value, yystack_[0].value); } -#line 873 "RSParserImpl.cpp" // lalr1.cc:919 + case 102: // tuple: LP setexpr_enum_min2 RPE +#line 440 "RSParserImpl.y" + { yylhs.value = ReplaceBrackets(TokenID::NT_TUPLE, yystack_[2].value, yystack_[1].value, yystack_[0].value); } +#line 855 "RSParserImpl.cpp" break; - case 71: -#line 255 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = TermDeclaration(yystack_[6].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 879 "RSParserImpl.cpp" // lalr1.cc:919 + case 103: // boolean: BOOLEAN LP setexpr RPE +#line 443 "RSParserImpl.y" + { yylhs.value = TextOperator(yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 861 "RSParserImpl.cpp" break; - case 72: -#line 257 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = TermDeclaration(yystack_[7].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 885 "RSParserImpl.cpp" // lalr1.cc:919 + case 104: // boolean: BOOLEAN boolean +#line 444 "RSParserImpl.y" + { yylhs.value = UnaryOperation(yystack_[1].value, yystack_[0].value); } +#line 867 "RSParserImpl.cpp" break; - case 73: -#line 260 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = FullRecursion(yystack_[9].value, yystack_[7].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 891 "RSParserImpl.cpp" // lalr1.cc:919 + case 105: // filter_expression: FILTER LS setexpr_enum RS LP setexpr RPE +#line 447 "RSParserImpl.y" + { yylhs.value = FilterCall(yystack_[6].value, yystack_[4].value, yystack_[1].value, yystack_[0].value); } +#line 873 "RSParserImpl.cpp" break; - case 74: -#line 262 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = ShortRecursion(yystack_[7].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 897 "RSParserImpl.cpp" // lalr1.cc:919 + case 106: // declarative: LC LOCAL IN setexpr BAR logic RCE +#line 451 "RSParserImpl.y" + { yylhs.value = TermDeclaration(yystack_[6].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 879 "RSParserImpl.cpp" break; - case 75: -#line 264 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Imperative(yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } -#line 903 "RSParserImpl.cpp" // lalr1.cc:919 + case 107: // declarative: DECLARATIVE LC variable IN setexpr BAR logic RCE +#line 452 "RSParserImpl.y" + { yylhs.value = TermDeclaration(yystack_[7].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 885 "RSParserImpl.cpp" break; - case 76: -#line 266 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::INTERRUPT, yystack_[0].value); } -#line 909 "RSParserImpl.cpp" // lalr1.cc:919 + case 108: // recursion: RECURSIVE LC variable ASSIGN setexpr BAR logic BAR setexpr RCE +#line 455 "RSParserImpl.y" + { yylhs.value = FullRecursion(yystack_[9].value, yystack_[7].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 891 "RSParserImpl.cpp" break; - case 77: -#line 267 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Enumeration(TokenID::INTERRUPT, yystack_[2].value, yystack_[0].value); } -#line 915 "RSParserImpl.cpp" // lalr1.cc:919 + case 109: // recursion: RECURSIVE LC variable ASSIGN setexpr BAR setexpr RCE +#line 456 "RSParserImpl.y" + { yylhs.value = ShortRecursion(yystack_[7].value, yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 897 "RSParserImpl.cpp" break; - case 78: -#line 269 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::NT_IMP_DECLARE, yystack_[2].value, yystack_[0].value); } -#line 921 "RSParserImpl.cpp" // lalr1.cc:919 + case 110: // imperative: IMPERATIVE LC setexpr BAR imp_blocks RCE +#line 459 "RSParserImpl.y" + { yylhs.value = Imperative(yystack_[5].value, yystack_[3].value, yystack_[1].value, yystack_[0].value); } +#line 903 "RSParserImpl.cpp" break; - case 79: -#line 270 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::NT_IMP_ASSIGN, yystack_[2].value, yystack_[0].value); } -#line 927 "RSParserImpl.cpp" // lalr1.cc:919 + case 111: // imp_blocks: imp_block +#line 462 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::INTERRUPT, yystack_[0].value); } +#line 909 "RSParserImpl.cpp" break; - case 80: -#line 271 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = AddNode(TokenID::NT_IMP_LOGIC, yystack_[0].value); } -#line 933 "RSParserImpl.cpp" // lalr1.cc:919 + case 112: // imp_blocks: imp_blocks SEMICOLON imp_blocks +#line 463 "RSParserImpl.y" + { yylhs.value = Enumeration(TokenID::INTERRUPT, yystack_[2].value, yystack_[0].value); } +#line 915 "RSParserImpl.cpp" break; - case 82: -#line 274 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = ReplaceBrackets(TokenID::NT_TUPLE_DECL, yystack_[2].value, yystack_[1].value, yystack_[0].value); } -#line 939 "RSParserImpl.cpp" // lalr1.cc:919 + case 113: // imp_block: LOCAL ITERATE setexpr +#line 466 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::NT_IMP_DECLARE, yystack_[2].value, yystack_[0].value); } +#line 921 "RSParserImpl.cpp" break; - case 83: -#line 276 "RSParserImpl.y" // lalr1.cc:919 - { yylhs.value = Enumeration(TokenID::INTERRUPT, yystack_[2].value, yystack_[0].value); } -#line 945 "RSParserImpl.cpp" // lalr1.cc:919 + case 114: // imp_block: LOCAL ASSIGN setexpr +#line 467 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::NT_IMP_ASSIGN, yystack_[2].value, yystack_[0].value); } +#line 927 "RSParserImpl.cpp" break; - case 84: -#line 277 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::expectedLocal); YYABORT; } -#line 951 "RSParserImpl.cpp" // lalr1.cc:919 + case 115: // imp_block: logic +#line 468 "RSParserImpl.y" + { yylhs.value = AddNode(TokenID::NT_IMP_LOGIC, yystack_[0].value); } +#line 933 "RSParserImpl.cpp" break; - case 117: -#line 325 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::missingParanthesis); YYABORT; } -#line 957 "RSParserImpl.cpp" // lalr1.cc:919 + case 117: // RPE: error +#line 475 "RSParserImpl.y" + { state->OnError(ParseEID::missingParenthesis); YYABORT; } +#line 939 "RSParserImpl.cpp" break; - case 119: -#line 328 "RSParserImpl.y" // lalr1.cc:919 - { state->OnError(ParseEID::missingCurlyBrace); YYABORT; } -#line 963 "RSParserImpl.cpp" // lalr1.cc:919 + case 119: // RCE: error +#line 479 "RSParserImpl.y" + { state->OnError(ParseEID::missingCurlyBrace); YYABORT; } +#line 945 "RSParserImpl.cpp" break; -#line 967 "RSParserImpl.cpp" // lalr1.cc:919 +#line 949 "RSParserImpl.cpp" + default: break; } @@ -979,7 +962,6 @@ namespace ccl { namespace rslang { namespace detail { YY_SYMBOL_PRINT ("-> $$ =", yylhs); yypop_ (yylen); yylen = 0; - YY_STACK_PRINT (); // Shift the result of the reduction. yypush_ (YY_NULLPTR, YY_MOVE (yylhs)); @@ -995,7 +977,9 @@ namespace ccl { namespace rslang { namespace detail { if (!yyerrstatus_) { ++yynerrs_; - error (yysyntax_error_ (yystack_[0].state, yyla)); + context yyctx (*this, yyla); + std::string msg = yysyntax_error_ (yyctx); + error (YY_MOVE (msg)); } @@ -1005,7 +989,7 @@ namespace ccl { namespace rslang { namespace detail { error, discard it. */ // Return failure if at end of input. - if (yyla.type_get () == yyeof_) + if (yyla.kind () == symbol_kind::S_YYEOF) YYABORT; else if (!yyla.empty ()) { @@ -1031,6 +1015,7 @@ namespace ccl { namespace rslang { namespace detail { this YYERROR. */ yypop_ (yylen); yylen = 0; + YY_STACK_PRINT (); goto yyerrlab1; @@ -1039,34 +1024,36 @@ namespace ccl { namespace rslang { namespace detail { `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus_ = 3; // Each real token shifted decrements this. + // Pop stack until we find a state that shifts the error token. + for (;;) + { + yyn = yypact_[+yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + yyn += symbol_kind::S_YYerror; + if (0 <= yyn && yyn <= yylast_ + && yycheck_[yyn] == symbol_kind::S_YYerror) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + // Pop the current state because it cannot handle the error token. + if (yystack_.size () == 1) + YYABORT; + + yy_destroy_ ("Error: popping", yystack_[0]); + yypop_ (); + YY_STACK_PRINT (); + } { stack_symbol_type error_token; - for (;;) - { - yyn = yypact_[yystack_[0].state]; - if (!yy_pact_value_is_default_ (yyn)) - { - yyn += yyterror_; - if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) - { - yyn = yytable_[yyn]; - if (0 < yyn) - break; - } - } - - // Pop the current state because it cannot handle the error token. - if (yystack_.size () == 1) - YYABORT; - - yy_destroy_ ("Error: popping", yystack_[0]); - yypop_ (); - YY_STACK_PRINT (); - } // Shift the error token. - error_token.state = yyn; + error_token.state = state_type (yyn); yypush_ ("Shifting", YY_MOVE (error_token)); } goto yynewstate; @@ -1098,6 +1085,7 @@ namespace ccl { namespace rslang { namespace detail { /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ yypop_ (yylen); + YY_STACK_PRINT (); while (1 < yystack_.size ()) { yy_destroy_ ("Cleanup: popping", yystack_[0]); @@ -1131,18 +1119,100 @@ namespace ccl { namespace rslang { namespace detail { error (yyexc.what ()); } - // Generate an error message. + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ std::string - RSParserImpl::yysyntax_error_ (state_type yystate, const symbol_type& yyla) const + RSParserImpl::yytnamerr_ (const char *yystr) { - // Number of reported tokens (one for the "unexpected", one per - // "expected"). - size_t yycount = 0; - // Its maximum. - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - // Arguments of yyformat. - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + if (*yystr == '"') + { + std::string yyr; + char const *yyp = yystr; + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + else + goto append; + + append: + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + std::string + RSParserImpl::symbol_name (symbol_kind_type yysymbol) + { + return yytnamerr_ (yytname_[yysymbol]); + } + + + + // RSParserImpl::context. + RSParserImpl::context::context (const RSParserImpl& yyparser, const symbol_type& yyla) + : yyparser_ (yyparser) + , yyla_ (yyla) + {} + + int + RSParserImpl::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const + { + // Actual number of expected tokens + int yycount = 0; + + int yyn = yypact_[+yyparser_.yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + // Stay within bounds of both yycheck and yytname. + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != symbol_kind::S_YYerror + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (!yyarg) + ++yycount; + else if (yycount == yyargn) + return 0; + else + yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx); + } + } + + if (yyarg && yycount == 0 && 0 < yyargn) + yyarg[0] = symbol_kind::S_YYEMPTY; + return yycount; + } + + + + int + RSParserImpl::yy_syntax_error_arguments_ (const context& yyctx, + symbol_kind_type yyarg[], int yyargn) const + { /* There are many possibilities here to consider: - If this state is a consistent state with a default action, then the only way this function was invoked is if the default action @@ -1161,41 +1231,32 @@ namespace ccl { namespace rslang { namespace detail { - Of course, the expected token list depends on states to have correct lookahead information, and it depends on the parser not to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state - merging (from LALR or IELR) and default reductions corrupt the - expected token list. However, the list is correct for - canonical LR with one exception: it will still contain any - token that will not be accepted due to an error action in a - later state. + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. */ - if (!yyla.empty ()) + + if (!yyctx.lookahead ().empty ()) { - int yytoken = yyla.type_get (); - yyarg[yycount++] = yytname_[yytoken]; - int yyn = yypact_[yystate]; - if (!yy_pact_value_is_default_ (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - // Stay within bounds of both yycheck and yytname. - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - for (int yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ - && !yy_table_value_is_error_ (yytable_[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - break; - } - else - yyarg[yycount++] = yytname_[yyx]; - } - } + if (yyarg) + yyarg[0] = yyctx.token (); + int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1); + return yyn + 1; } + return 0; + } + + // Generate an error message. + std::string + RSParserImpl::yysyntax_error_ (const context& yyctx) const + { + // Its maximum. + enum { YYARGS_MAX = 5 }; + // Arguments of yyformat. + symbol_kind_type yyarg[YYARGS_MAX]; + int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); char const* yyformat = YY_NULLPTR; switch (yycount) @@ -1216,11 +1277,11 @@ namespace ccl { namespace rslang { namespace detail { std::string yyres; // Argument number. - size_t yyi = 0; + std::ptrdiff_t yyi = 0; for (char const* yyp = yyformat; *yyp; ++yyp) if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) { - yyres += yytnamerr_ (yyarg[yyi++]); + yyres += symbol_name (yyarg[yyi++]); ++yyp; } else @@ -1229,120 +1290,120 @@ namespace ccl { namespace rslang { namespace detail { } - const signed char RSParserImpl::yypact_ninf_ = -65; + const signed char RSParserImpl::yypact_ninf_ = -58; - const signed char RSParserImpl::yytable_ninf_ = -87; + const signed char RSParserImpl::yytable_ninf_ = -116; const short RSParserImpl::yypact_[] = { - 236, -65, 92, -43, -40, -65, -65, -65, -65, -65, - -65, 342, 37, -65, -65, -37, -65, -65, -65, -65, - -16, 21, 26, 342, 414, 143, 56, -65, -65, -65, - 110, 90, -65, -65, -65, -65, 553, -65, -65, -65, - -65, -65, -65, -65, -65, 83, -65, -65, -65, 84, - 85, 342, 466, 466, 466, -65, -65, -65, -65, -65, - 553, -65, 466, -65, 466, 93, 93, 466, -65, 58, - 101, 553, 202, 102, 19, 146, -65, 466, 215, 2, - -65, -65, 59, 103, -65, -65, 342, 342, 342, 342, - 466, 466, 466, -65, -65, -65, -65, -65, -65, -65, - -65, -65, -65, -65, 466, 466, 466, 466, 466, 466, - 114, -65, -65, 100, 12, -65, -65, 466, -65, 215, - 123, 195, 152, 203, 93, 163, 144, 489, -65, -65, - -65, -65, -65, 466, -65, 466, -65, -65, 466, 342, - 199, 125, 238, 185, -65, 142, 142, 174, -65, -65, - -65, -65, -65, 215, -65, -65, -65, 20, 194, 466, - 127, 152, -65, -65, -65, 207, 466, 466, 394, 215, - 503, 215, -65, -65, -65, -65, 131, 290, -65, -65, - -65, 466, 516, 521, 106, 8, 10, -65, 342, -65, - -65, -65, -65, 152, 342, 342, 466, 466, -65, -65, - 394, -65, 11, -65, 11, 208, 14, 215, 215, -65, - -65, -65, 466, -65, 87, -65 + 236, -58, 111, -34, -17, -58, -58, -58, -58, -58, + -58, 342, 82, -58, -58, 25, -58, -58, -58, -58, + 46, 56, 75, 342, 414, 9, 60, -58, 85, -58, + -58, 137, 224, -58, -58, -58, 79, -58, 553, 118, + -58, -58, -58, -58, -58, -58, -58, -58, -58, -58, + -58, 342, 466, 466, 466, -58, -58, -58, -58, -58, + -58, 553, 466, -58, 466, 35, 35, 466, -58, 70, + 101, 553, 121, 17, 202, 157, -58, 466, 175, 24, + -58, -58, 10, 63, -58, -58, 97, 342, 342, 342, + 342, -58, -58, 100, -58, -19, -58, 466, 466, 466, + -58, -58, -58, -58, -58, -58, -58, -58, -58, -58, + -58, 466, 466, 466, 466, 466, 466, 466, -58, 175, + 126, 203, 129, 206, 35, 163, 144, 489, -58, -58, + -58, -58, 466, -58, -58, 466, -58, -58, 466, 342, + 89, -58, 120, 241, 176, -58, -58, -58, 19, 146, + 466, 148, 143, 143, 190, -58, -58, -58, -58, -58, + 175, 129, -58, -58, -58, 207, 466, 466, 394, 175, + 503, 175, -58, -58, -58, -58, 154, 290, -58, -58, + -58, 466, 516, 521, 123, 6, 8, -58, 342, -58, + -58, -58, -58, 129, 342, 342, 466, 466, -58, -58, + 394, -58, 33, -58, 33, 169, 14, 175, 175, -58, + -58, -58, 466, -58, 73, -58 }; - const unsigned char + const signed char RSParserImpl::yydefact_[] = { - 0, 93, 89, 87, 88, 91, 94, 96, 95, 97, - 98, 0, 0, 102, 103, 0, 104, 99, 100, 101, - 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, - 21, 0, 22, 19, 18, 20, 6, 44, 45, 57, - 58, 59, 61, 63, 62, 90, 92, 43, 42, 0, - 0, 14, 0, 0, 0, 89, 28, 25, 24, 23, - 0, 90, 0, 67, 0, 0, 0, 0, 21, 0, - 0, 68, 0, 0, 0, 93, 88, 0, 68, 0, - 69, 8, 0, 0, 9, 1, 0, 0, 0, 0, - 0, 0, 0, 112, 113, 114, 115, 111, 110, 105, - 106, 107, 108, 109, 0, 0, 0, 0, 0, 0, - 0, 30, 81, 0, 0, 38, 37, 0, 16, 15, + 0, 84, 81, 9, 10, 83, 78, 80, 79, 52, + 53, 0, 0, 72, 73, 0, 74, 69, 70, 71, + 0, 0, 0, 0, 0, 0, 0, 2, 82, 3, + 4, 29, 0, 30, 26, 27, 0, 28, 12, 0, + 63, 64, 65, 66, 94, 95, 96, 97, 98, 100, + 99, 5, 0, 0, 0, 81, 82, 51, 49, 50, + 45, 0, 0, 104, 0, 0, 0, 0, 29, 0, + 0, 75, 0, 0, 0, 84, 10, 0, 75, 0, + 76, 14, 0, 0, 15, 1, 0, 0, 0, 0, + 0, 47, 20, 0, 54, 0, 55, 0, 0, 0, + 41, 42, 43, 44, 40, 39, 34, 35, 36, 37, + 38, 0, 0, 0, 0, 0, 0, 0, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 117, 116, - 27, 26, 56, 0, 65, 0, 64, 13, 0, 0, - 0, 33, 34, 35, 36, 48, 49, 50, 55, 51, - 54, 52, 53, 32, 17, 39, 85, 0, 0, 0, - 0, 0, 46, 31, 66, 0, 0, 0, 0, 70, - 0, 12, 7, 11, 10, 82, 0, 0, 41, 40, - 47, 0, 0, 0, 93, 21, 0, 76, 0, 84, - 86, 83, 29, 0, 0, 0, 0, 0, 119, 118, - 0, 75, 0, 60, 0, 21, 0, 79, 78, 77, - 71, 72, 0, 74, 0, 73 + 32, 31, 0, 102, 93, 0, 101, 19, 0, 0, + 0, 8, 59, 60, 61, 62, 56, 24, 0, 0, + 0, 0, 85, 86, 87, 92, 88, 91, 89, 90, + 33, 0, 67, 48, 103, 0, 0, 0, 0, 77, + 0, 18, 13, 17, 16, 21, 0, 0, 58, 57, + 68, 0, 0, 0, 84, 29, 0, 111, 0, 23, + 25, 22, 46, 0, 0, 0, 0, 0, 119, 118, + 0, 110, 0, 105, 0, 29, 0, 114, 113, 112, + 106, 107, 0, 109, 0, 108 }; const short RSParserImpl::yypgoto_[] = { - -65, -65, -44, 155, -65, 128, -65, 4, 136, 95, - -8, -6, -9, 244, 109, -65, 0, -1, -65, -65, - -65, 258, 94, 17, -65, -65, -65, 71, -65, -48, - 108, 111, 285, -65, -65, -65, -65, -65, -65, -64, + -58, -58, -58, 228, -50, 178, -58, 128, -30, 93, + 95, 4, 164, -8, -9, -58, -6, 107, -58, 119, + -58, 249, 0, -58, 94, -4, -58, -58, -2, -58, + -58, -58, 273, -58, -58, -58, -58, 86, -58, -57, -13 }; const short RSParserImpl::yydefgoto_[] = { - -1, 26, 27, 28, 83, 84, 29, 68, 31, 56, - 32, 33, 34, 35, 114, 115, 60, 37, 38, 39, - 40, 41, 73, 80, 42, 43, 44, 186, 187, 156, - 157, 158, 61, 46, 47, 48, 49, 50, 109, 130, + -1, 26, 27, 56, 29, 30, 83, 84, 147, 148, + 149, 68, 32, 33, 34, 116, 35, 60, 36, 95, + 96, 37, 61, 39, 72, 80, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 186, 187, 130, 201 }; const short RSParserImpl::yytable_[] = { - 36, 116, 59, 57, 30, 58, 131, 118, 132, -80, - 134, 198, 198, 53, 69, 198, 54, 125, 126, 64, - 128, 128, 72, 71, 78, 90, 91, 92, 93, 94, - 95, 96, 97, 98, -21, -21, -21, -21, 65, 159, - 74, 99, 100, 101, 102, 103, 104, 105, 106, 107, - 108, 36, 119, 78, 78, 30, 85, 136, 164, 128, - 137, 133, 122, -80, 78, 199, 199, 127, -80, 199, - 200, 160, 129, 129, 12, 66, 72, 78, -69, -86, - 67, -18, -18, -18, -18, 111, 138, 112, 198, 62, - 145, 146, 147, 175, 74, 172, 112, 180, 90, 91, - 92, 155, 128, 112, 148, 149, 150, 151, 152, 153, - -5, 129, 116, 86, 87, 88, 89, 161, 79, 104, - 105, 106, 107, 108, -20, -20, -20, -20, 178, 203, - 112, 110, 189, 169, 112, 170, 113, 117, 171, 36, - 51, 52, 199, 30, 81, 124, 82, 120, 121, 87, - 88, 89, 124, 128, 129, 92, 196, 197, 123, 177, - 139, 133, 140, 90, 91, 92, 182, 183, 59, 57, - 25, 58, 185, 135, 104, 105, 106, 107, 108, 113, - 162, 193, 133, 124, 104, 105, 106, 107, 108, 210, + 38, 118, 58, 57, 31, 59, 94, -115, 150, 198, + 81, 137, 82, 131, 69, 198, 133, 134, 128, 73, + 128, 74, 53, 71, 78, 97, 98, 99, 100, 101, + 102, 103, 104, 105, 198, 125, 126, 138, 92, 54, + 151, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 38, 119, 78, 78, 31, -29, -29, -29, -29, + 85, -115, 122, 199, 78, 164, -115, 127, 200, 199, + 129, 128, 129, 73, 198, 74, -76, 78, -25, 136, + 91, 64, 92, 132, 97, 98, 99, 124, 199, 172, + 173, 175, 82, -26, -26, -26, -26, 152, 153, 154, + 65, 146, 128, 92, 180, 111, 112, 113, 114, 115, + 66, 155, 156, 157, 158, 159, 160, 161, 79, 12, + 139, 94, 140, 129, -28, -28, -28, -28, 199, 67, + 128, 93, 169, 86, 62, 170, 203, -11, 171, 38, + 97, 98, 99, 31, 88, 89, 90, 120, 121, 178, + 177, 92, 124, 25, 129, 189, 99, 92, 123, 51, + 52, 111, 112, 113, 114, 115, 182, 183, 58, 57, + 117, 59, 185, 196, 197, 111, 112, 113, 114, 115, + 132, 193, 129, 162, 135, 132, 97, 98, 99, 210, 166, 211, 202, 213, 167, 206, 207, 208, 204, 205, - 173, 215, 82, 128, 185, 129, 104, 105, 106, 107, - 108, 89, 214, -44, -44, -44, -44, -44, -44, -44, - -44, -44, 141, 142, 143, 144, 90, 91, 92, -44, - -44, -44, -44, -44, -44, -44, -44, -44, -44, 1, - 2, 3, 4, 5, 6, 7, 8, 104, 105, 106, - 107, 108, 163, 176, 133, 129, 9, 10, 11, 181, - 165, -44, 133, 88, 89, 154, 212, 70, 174, 179, - 63, 209, 192, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 190, 45, 0, 191, 23, 0, + 93, 215, 90, 128, 185, 176, 124, 111, 112, 113, + 114, 115, 214, -65, -65, -65, -65, -65, -65, -65, + -65, -65, 111, 112, 113, 114, 115, 212, 28, -65, + -65, -65, -65, -65, -65, -65, -65, -65, -65, 1, + 2, 3, 4, 5, 6, 7, 8, 87, 88, 89, + 90, 142, 143, 144, 145, 129, 9, 10, 11, 181, + 163, -65, 132, 165, 141, 132, 89, 90, 174, 190, + 179, 191, 70, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 192, 63, 209, 0, 23, 0, 24, 0, 25, 1, 55, 3, 4, 5, 6, 7, - 8, 90, 91, 92, 0, 0, 0, 0, 0, 0, + 8, 97, 98, 99, 0, 0, 0, 0, 0, 0, 9, 10, 11, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 104, 105, 106, 107, 108, 12, 13, 14, + 0, 0, 111, 112, 113, 114, 115, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 0, 0, 0, 23, 0, 24, 1, 55, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, @@ -1360,49 +1421,49 @@ namespace ccl { namespace rslang { namespace detail { 55, 3, 76, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 90, 91, 92, 12, 13, 14, 15, 16, 17, 18, - 19, 20, 21, 22, 90, 91, 92, 0, 77, 0, - 24, 104, 105, 106, 107, 108, 0, 90, 91, 92, - 0, 0, 90, 91, 92, 104, 105, 106, 107, 108, - 0, 0, 0, 0, 0, 0, 0, 168, 104, 105, - 106, 107, 108, 104, 105, 106, 107, 108, 0, 0, - 0, 188, 0, 0, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 0, 194, 0, 0, 0, 0, 195, - 99, 100, 101, 102, 103, 104, 105, 106, 107, 108 + 97, 98, 99, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 97, 98, 99, 0, 77, 0, + 24, 111, 112, 113, 114, 115, 0, 97, 98, 99, + 0, 0, 97, 98, 99, 111, 112, 113, 114, 115, + 0, 0, 0, 0, 0, 0, 0, 168, 111, 112, + 113, 114, 115, 111, 112, 113, 114, 115, 0, 0, + 0, 188, 0, 0, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 0, 194, 0, 0, 0, 0, 195, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115 }; const short RSParserImpl::yycheck_[] = { - 0, 49, 11, 11, 0, 11, 70, 51, 72, 1, - 74, 1, 1, 56, 23, 1, 56, 65, 66, 56, - 1, 1, 23, 23, 24, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 23, 24, 25, 26, 54, 27, - 23, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 51, 52, 53, 54, 51, 0, 55, 122, 1, - 1, 59, 62, 55, 64, 55, 55, 67, 60, 55, - 60, 59, 53, 53, 37, 54, 77, 77, 59, 59, - 54, 23, 24, 25, 26, 1, 27, 3, 1, 52, - 90, 91, 92, 157, 77, 139, 3, 161, 11, 12, - 13, 1, 1, 3, 104, 105, 106, 107, 108, 109, - 0, 53, 160, 23, 24, 25, 26, 117, 24, 32, - 33, 34, 35, 36, 23, 24, 25, 26, 1, 193, - 3, 48, 1, 133, 3, 135, 52, 52, 138, 139, - 48, 49, 55, 139, 1, 52, 3, 53, 54, 24, - 25, 26, 52, 1, 53, 13, 50, 51, 64, 159, - 57, 59, 59, 11, 12, 13, 166, 167, 177, 177, - 56, 177, 168, 27, 32, 33, 34, 35, 36, 52, - 57, 181, 59, 52, 32, 33, 34, 35, 36, 202, + 0, 51, 11, 11, 0, 11, 36, 1, 27, 1, + 1, 1, 3, 70, 23, 1, 73, 74, 1, 23, + 1, 23, 56, 23, 24, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 1, 65, 66, 27, 3, 56, + 59, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 51, 52, 53, 54, 51, 23, 24, 25, 26, + 0, 55, 62, 55, 64, 122, 60, 67, 60, 55, + 53, 1, 53, 77, 1, 77, 59, 77, 59, 55, + 1, 56, 3, 59, 11, 12, 13, 52, 55, 139, + 1, 148, 3, 23, 24, 25, 26, 97, 98, 99, + 54, 1, 1, 3, 161, 32, 33, 34, 35, 36, + 54, 111, 112, 113, 114, 115, 116, 117, 24, 37, + 57, 151, 59, 53, 23, 24, 25, 26, 55, 54, + 1, 52, 132, 48, 52, 135, 193, 0, 138, 139, + 11, 12, 13, 139, 24, 25, 26, 53, 54, 1, + 150, 3, 52, 56, 53, 1, 13, 3, 64, 48, + 49, 32, 33, 34, 35, 36, 166, 167, 177, 177, + 52, 177, 168, 50, 51, 32, 33, 34, 35, 36, + 59, 181, 53, 57, 27, 59, 11, 12, 13, 202, 27, 204, 188, 206, 50, 195, 196, 197, 194, 195, - 1, 214, 3, 1, 200, 53, 32, 33, 34, 35, - 36, 26, 212, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 86, 87, 88, 89, 11, 12, 13, 27, + 52, 214, 26, 1, 200, 59, 52, 32, 33, 34, + 35, 36, 212, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 32, 33, 34, 35, 36, 58, 0, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 3, - 4, 5, 6, 7, 8, 9, 10, 32, 33, 34, - 35, 36, 57, 59, 59, 53, 20, 21, 22, 52, - 57, 59, 59, 25, 26, 110, 58, 23, 140, 160, - 12, 200, 177, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 176, 0, -1, 176, 52, -1, + 4, 5, 6, 7, 8, 9, 10, 23, 24, 25, + 26, 87, 88, 89, 90, 53, 20, 21, 22, 52, + 57, 59, 59, 57, 86, 59, 25, 26, 140, 176, + 151, 176, 23, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 177, 12, 200, -1, 52, -1, 54, -1, 56, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, 20, 21, 22, -1, -1, -1, -1, -1, -1, -1, @@ -1435,130 +1496,131 @@ namespace ccl { namespace rslang { namespace detail { 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 }; - const unsigned char + const signed char RSParserImpl::yystos_[] = { 0, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 22, 37, 38, 39, 40, 41, 42, 43, 44, - 45, 46, 47, 52, 54, 56, 62, 63, 64, 67, - 68, 69, 71, 72, 73, 74, 77, 78, 79, 80, - 81, 82, 85, 86, 87, 93, 94, 95, 96, 97, - 98, 48, 49, 56, 56, 4, 70, 71, 72, 73, - 77, 93, 52, 82, 56, 54, 54, 54, 68, 73, - 74, 77, 78, 83, 84, 3, 6, 52, 77, 83, - 84, 1, 3, 65, 66, 0, 23, 24, 25, 26, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 27, - 28, 29, 30, 31, 32, 33, 34, 35, 36, 99, - 48, 1, 3, 52, 75, 76, 90, 52, 63, 77, - 83, 83, 77, 83, 52, 90, 90, 77, 1, 53, - 100, 100, 100, 59, 100, 27, 55, 1, 27, 57, - 59, 69, 69, 69, 69, 77, 77, 77, 77, 77, - 77, 77, 77, 77, 64, 1, 90, 91, 92, 27, - 59, 77, 57, 57, 100, 57, 27, 50, 58, 77, - 77, 77, 63, 1, 66, 100, 59, 77, 1, 75, - 100, 52, 77, 77, 3, 68, 88, 89, 58, 1, - 91, 92, 70, 77, 58, 58, 50, 51, 1, 55, - 60, 101, 68, 100, 68, 68, 77, 77, 77, 88, - 101, 101, 58, 101, 77, 101 + 45, 46, 47, 52, 54, 56, 62, 63, 64, 65, + 66, 72, 73, 74, 75, 77, 79, 82, 83, 84, + 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + 97, 48, 49, 56, 56, 4, 64, 74, 75, 77, + 78, 83, 52, 93, 56, 54, 54, 54, 72, 75, + 82, 83, 85, 86, 89, 3, 6, 52, 83, 85, + 86, 1, 3, 67, 68, 0, 48, 23, 24, 25, + 26, 1, 3, 52, 69, 80, 81, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 76, 52, 65, 83, + 85, 85, 83, 85, 52, 69, 69, 83, 1, 53, + 100, 100, 59, 100, 100, 27, 55, 1, 27, 57, + 59, 66, 73, 73, 73, 73, 1, 69, 70, 71, + 27, 59, 83, 83, 83, 83, 83, 83, 83, 83, + 83, 83, 57, 57, 100, 57, 27, 50, 58, 83, + 83, 83, 65, 1, 68, 100, 59, 83, 1, 80, + 100, 52, 83, 83, 3, 72, 98, 99, 58, 1, + 70, 71, 78, 83, 58, 58, 50, 51, 1, 55, + 60, 101, 72, 100, 72, 72, 83, 83, 83, 98, + 101, 101, 58, 101, 83, 101 }; - const unsigned char + const signed char RSParserImpl::yyr1_[] = { - 0, 61, 62, 62, 62, 63, 63, 64, 64, 65, - 65, 65, 66, 66, 67, 67, 67, 67, 68, 68, - 68, 69, 69, 70, 70, 70, 71, 71, 72, 72, - 72, 72, 73, 74, 74, 74, 74, 75, 75, 75, - 76, 76, 77, 77, 77, 77, 77, 77, 78, 78, - 78, 78, 78, 78, 78, 78, 78, 79, 79, 79, - 79, 79, 79, 79, 80, 81, 82, 82, 83, 83, - 84, 85, 85, 86, 86, 87, 88, 88, 89, 89, - 89, 90, 90, 91, 91, 92, 92, 93, 93, 94, - 94, 94, 95, 95, 96, 96, 96, 97, 97, 98, - 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 100, 100, 101, 101 + 0, 61, 62, 62, 62, 63, 63, 63, 63, 64, + 64, 65, 65, 66, 66, 67, 67, 67, 68, 68, + 69, 69, 70, 70, 71, 71, 72, 72, 72, 73, + 73, 74, 74, 75, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 77, 77, 77, 77, 78, + 78, 78, 79, 79, 80, 80, 80, 81, 81, 82, + 82, 82, 82, 83, 83, 83, 83, 83, 83, 84, + 84, 84, 84, 84, 84, 85, 85, 86, 87, 87, + 87, 88, 88, 88, 88, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 90, 90, 90, 90, 90, 90, + 90, 91, 92, 93, 93, 94, 95, 95, 96, 96, + 97, 98, 98, 99, 99, 99, 100, 100, 101, 101 }; - const unsigned char + const signed char RSParserImpl::yyr2_[] = { - 0, 2, 1, 1, 1, 1, 1, 4, 2, 1, - 3, 3, 3, 2, 2, 3, 3, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 3, 3, 2, 5, - 2, 4, 3, 3, 3, 3, 3, 1, 1, 2, - 3, 3, 1, 1, 1, 1, 4, 4, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, - 7, 1, 1, 1, 3, 3, 4, 2, 1, 1, - 3, 7, 8, 10, 8, 6, 1, 3, 3, 3, - 1, 1, 3, 3, 3, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 0, 2, 1, 1, 1, 2, 3, 3, 3, 1, + 1, 1, 1, 4, 2, 1, 3, 3, 3, 2, + 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, + 1, 3, 3, 3, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 5, 2, 4, 1, + 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, + 3, 3, 3, 1, 1, 1, 1, 4, 4, 1, + 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, + 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, + 1, 3, 3, 4, 2, 7, 7, 8, 10, 8, + 6, 1, 3, 3, 3, 1, 1, 1, 1, 1 }; - +#if YYDEBUG || 1 // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - // First, the terminals, then, starting at \a yyntokens_, nonterminals. + // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. const char* const RSParserImpl::yytname_[] = { - "$end", "error", "$undefined", "LOCAL", "GLOBAL", "FUNCTION", - "PREDICATE", "RADICAL", "INTEGER", "INFINITY", "EMPTYSET", "PLUS", - "MINUS", "MULTIPLY", "GREATER", "LESSER", "GREATER_OR_EQ", + "\"end of file\"", "error", "\"invalid token\"", "LOCAL", "GLOBAL", + "FUNCTION", "PREDICATE", "RADICAL", "INTEGER", "INTSET", "EMPTYSET", + "PLUS", "MINUS", "MULTIPLY", "GREATER", "LESSER", "GREATER_OR_EQ", "LESSER_OR_EQ", "EQUAL", "NOTEQUAL", "FORALL", "EXISTS", "NOT", "EQUIVALENT", "IMPLICATION", "OR", "AND", "IN", "NOTIN", "SUBSET", "SUBOR_EQ", "NOTSUBSET", "DECART", "UNION", "INTERSECTION", "SET_MINUS", "SYMMINUS", "BOOLEAN", "BIGPR", "SMALLPR", "FILTER", "CARD", "BOOL", "DEBOOL", "RED", "DECLARATIVE", "RECURSIVE", "IMPERATIVE", "DEFINE", "STRUCT", "ASSIGN", "ITERATE", "LP", "RP", "LC", "RC", "LS", "RS", "BAR", - "COMMA", "SEMICOLON", "$accept", "expression", "term_or_logic", - "function_decl", "arg_declaration", "declaration", "global_declaration", - "logic", "logic_all", "logic_no_binary", "logic_par", "logic_unary", - "logic_predicates", "logic_binary", "quant_var", "quant_var_enum", - "term", "binary_operation", "typed_constructors", "enumeration", "tuple", - "boolean", "term_enum", "term_enum_min2", "declarative", "recursion", - "imperative", "imp_blocks", "imp_block", "variable", "var_enum", - "var_all", "function_name", "global_id", "identifier", "literal", - "quantifier", "operation_name", "binary_predicate", "RPE", "RCE", YY_NULLPTR + "COMMA", "SEMICOLON", "$accept", "expression", "global_declaration", + "function_name", "logic_or_setexpr", "function_decl", "arguments", + "declaration", "variable", "var_enum", "var_all", "logic", "logic_all", + "logic_par", "logic_predicates", "binary_predicate", "logic_unary", + "logic_no_binary", "quantifier", "quant_var", "quant_var_enum", + "logic_binary", "setexpr", "operation_name", "setexpr_enum", + "setexpr_enum_min2", "literal", "identifier", "setexpr_binary", + "setexpr_generators", "enumeration", "tuple", "boolean", + "filter_expression", "declarative", "recursion", "imperative", + "imp_blocks", "imp_block", "RPE", "RCE", YY_NULLPTR }; +#endif + #if YYDEBUG - const unsigned short + const short RSParserImpl::yyrline_[] = { - 0, 150, 150, 151, 152, 155, 156, 159, 160, 163, - 164, 165, 167, 168, 172, 173, 174, 175, 179, 180, - 181, 183, 184, 186, 187, 188, 190, 191, 193, 194, - 196, 197, 199, 201, 202, 203, 204, 207, 208, 209, - 211, 212, 216, 217, 218, 219, 220, 221, 224, 225, - 226, 227, 228, 229, 230, 231, 232, 235, 236, 237, - 238, 239, 240, 241, 243, 245, 247, 248, 250, 251, - 253, 255, 256, 259, 261, 264, 266, 267, 269, 270, - 271, 273, 274, 276, 277, 279, 280, 284, 285, 287, - 288, 289, 291, 292, 294, 295, 296, 299, 300, 303, - 304, 305, 306, 307, 308, 311, 312, 313, 314, 315, - 316, 317, 318, 319, 320, 321, 324, 325, 327, 328 + 0, 262, 262, 263, 264, 268, 269, 270, 271, 274, + 275, 279, 280, 284, 285, 290, 291, 292, 295, 296, + 300, 301, 304, 305, 308, 309, 314, 315, 316, 319, + 320, 323, 324, 328, 331, 332, 333, 334, 335, 336, + 337, 338, 339, 340, 341, 345, 346, 347, 348, 351, + 352, 353, 356, 357, 360, 361, 362, 365, 366, 370, + 371, 372, 373, 379, 380, 381, 382, 383, 384, 387, + 388, 389, 390, 391, 392, 395, 396, 399, 403, 404, + 405, 409, 410, 411, 412, 416, 417, 418, 419, 420, + 421, 422, 423, 424, 428, 429, 430, 431, 432, 433, + 434, 437, 440, 443, 444, 447, 451, 452, 455, 456, + 459, 462, 463, 466, 467, 468, 474, 475, 478, 479 }; - // Print the state stack on the debug stream. void - RSParserImpl::yystack_print_ () + RSParserImpl::yy_stack_print_ () const { *yycdebug_ << "Stack now"; for (stack_type::const_iterator i = yystack_.begin (), i_end = yystack_.end (); i != i_end; ++i) - *yycdebug_ << ' ' << i->state; + *yycdebug_ << ' ' << int (i->state); *yycdebug_ << '\n'; } - // Report on the debug stream that the rule \a yyrule is going to be reduced. void - RSParserImpl::yy_reduce_print_ (int yyrule) + RSParserImpl::yy_reduce_print_ (int yyrule) const { - unsigned yylno = yyrline_[yyrule]; + int yylno = yyrline_[yyrule]; int yynrhs = yyr2_[yyrule]; // Print the symbols being reduced, and their result. *yycdebug_ << "Reducing stack by rule " << yyrule - 1 @@ -1570,13 +1632,13 @@ namespace ccl { namespace rslang { namespace detail { } #endif // YYDEBUG - RSParserImpl::token_number_type + RSParserImpl::symbol_kind_type RSParserImpl::yytranslate_ (int t) { // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to // TOKEN-NUM as returned by yylex. static - const token_number_type + const signed char translate_table[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -1612,21 +1674,22 @@ namespace ccl { namespace rslang { namespace detail { 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 }; - const unsigned user_token_number_max_ = 315; - const token_number_type undef_token_ = 2; + // Last valid token kind. + const int code_max = 315; - if (static_cast (t) <= yyeof_) - return yyeof_; - else if (static_cast (t) <= user_token_number_max_) - return translate_table[t]; + if (t <= 0) + return symbol_kind::S_YYEOF; + else if (t <= code_max) + return YY_CAST (symbol_kind_type, translate_table[t]); else - return undef_token_; + return symbol_kind::S_YYUNDEF; } -#line 11 "RSParserImpl.y" // lalr1.cc:1242 +#line 15 "RSParserImpl.y" } } } // ccl::rslang::detail -#line 1629 "RSParserImpl.cpp" // lalr1.cc:1242 -#line 331 "RSParserImpl.y" // lalr1.cc:1243 +#line 1691 "RSParserImpl.cpp" + +#line 486 "RSParserImpl.y" #ifdef _MSC_VER diff --git a/ccl/rslang/src/RSParserImpl.y b/ccl/rslang/src/RSParserImpl.y index 9cc8b93..3e61659 100644 --- a/ccl/rslang/src/RSParserImpl.y +++ b/ccl/rslang/src/RSParserImpl.y @@ -1,4 +1,8 @@ -%require "3.2" +%require "3.7" + +/////////////////////////////////////////////////////////// +// ------------- Generator Definitions -------------------- +/////////////////////////////////////////////////////////// %output "RSParserImpl.cpp" %defines "../header/RSParserImpl.h" @@ -13,10 +17,14 @@ %define api.parser.class {RSParserImpl} %param {ParserState* state} + +/////////////////////////////////////////////////////////// +// ------------- Code Wrapper at FileStart ---------------- +/////////////////////////////////////////////////////////// %code top { #ifdef _MSC_VER #pragma warning( push ) - #pragma warning( disable : 26434 26438 26440 26446 26447 26448 26456 ) + #pragma warning( disable : 4244 26434 26438 26440 26446 26447 26448 26456 ) #pragma warning( disable : 26460 26477 26481 26482 26493 26494 26495 26496 ) #endif @@ -33,6 +41,10 @@ } + +/////////////////////////////////////////////////////////// +// ------------- Semantic Actions ------------------------- +/////////////////////////////////////////////////////////// %code requires{ #include "ccl/rslang/SyntaxTree.h" #include "ccl/rslang/ParserState.hpp" @@ -42,292 +54,435 @@ namespace ccl::rslang::detail { #define YYSTYPE RawNode struct ParserState; +int yylex(RawNode* yylval, ParserState* state); + RawNode AddNode(TokenID token, RawNode son); RawNode AddNode(TokenID token, RawNode son1, RawNode son2); -RawNode BinaryOperation(RawNode op1, RawNode operation, RawNode op2); -RawNode UnaryOperation(RawNode operation, RawNode operand); RawNode RemoveBrackets(RawNode br1, RawNode operand, RawNode br2); RawNode ReplaceBrackets(TokenID token, RawNode br1, RawNode argList, RawNode br2); +RawNode BinaryOperation(RawNode op1, RawNode operation, RawNode op2); +RawNode UnaryOperation(RawNode operation, RawNode operand); RawNode Enumeration(TokenID token, RawNode el1, RawNode el2); -RawNode Decartian(RawNode op1, RawNode decart, RawNode op2); -RawNode Quantifier(RawNode quant, RawNode declaration, RawNode domain, RawNode predicate); -RawNode FunctionDeclaration(RawNode start, RawNode argdecl, RawNode expr); -RawNode FunctionCall(RawNode function, RawNode args, RawNode rs); -RawNode FilterCall(RawNode filter, RawNode params, RawNode argument, RawNode rp); -RawNode TextOperator(RawNode oper, RawNode args, RawNode rp); -RawNode TermDeclaration(RawNode lc, RawNode declaration, RawNode domain, RawNode predicate, RawNode rc); -RawNode FullRecursion(RawNode rec, RawNode localid, RawNode domain, RawNode condition, RawNode iteration, RawNode rc); -RawNode ShortRecursion(RawNode rec, RawNode localid, RawNode domain, RawNode iteration, RawNode rc); -RawNode Imperative(RawNode imp, RawNode value, RawNode actions, RawNode rc); +RawNode Decartian( + RawNode op1, + RawNode decartian, + RawNode op2 +); -int yylex(RawNode* yylval, ParserState* state); +RawNode Quantifier( + RawNode quant, + RawNode declaration, + RawNode domain, + RawNode predicate +); + +RawNode FunctionDeclaration( + RawNode start, + RawNode argumentsDeclaration, + RawNode expr +); + +RawNode FunctionCall( + RawNode function, + RawNode args, RawNode + rs +); + +RawNode FilterCall( + RawNode filter, + RawNode params, + RawNode argument, + RawNode rp +); + +RawNode TextOperator( + RawNode operatorName, + RawNode args, + RawNode rp +); + +RawNode TermDeclaration( + RawNode lc, + RawNode declaration, + RawNode domain, + RawNode predicate, + RawNode rc); + +RawNode FullRecursion( + RawNode rec, + RawNode declaration, + RawNode domain, + RawNode condition, + RawNode iteration, + RawNode rc +); + +RawNode ShortRecursion( + RawNode rec, + RawNode declaration, + RawNode domain, + RawNode iteration, + RawNode rc +); + +RawNode Imperative( + RawNode imp, + RawNode value, + RawNode actions, + RawNode rc +); } // namespace ccl::rslang::detail - } -//-------------- Идентификаторы ----------------------------------- -%token LOCAL // Имя локальной переменной - GLOBAL // Имя глобальной переменной - FUNCTION // Терм-функция - PREDICATE // Пердикат-функция - RADICAL // Радикал для шаблонов функций и предикатов - INTEGER - INFINITY - EMPTYSET -//------------------ Арифметика ------------------------------ -%left PLUS MINUS -%left MULTIPLY +/////////////////////////////////////////////////////////// +// ------------- Terminal Tokens -------------------------- +/////////////////////////////////////////////////////////// -// ----------- Целочисленные предикаты ----------------------- -%token GREATER - LESSER - GREATER_OR_EQ - LESSER_OR_EQ - -// --------------- Сравнение --------------------------------- -%token EQUAL - NOTEQUAL - -//------------- Логические предикаты ------------------------ -%token FORALL // Квантор всеобщности - EXISTS // Квантор существования -%right NOT -%left EQUIVALENT -%left IMPLICATION -%left OR -%left AND - -//-------------- Предикаты теории множеств ------------------- -%token IN - NOTIN - SUBSET - SUBOR_EQ - NOTSUBSET - -//-------------- Операции теории множеств ------------------- -%left DECART UNION INTERSECTION SET_MINUS SYMMINUS -%right BOOLEAN // Булеан - -//------------------ Родоструктурные операции ------------------- -%token BIGPR // Большая проекция - SMALLPR // Малая проекция - FILTER // Фильтр - CARD // Кардинальность (мощность множества) - BOOL // синглетон - DEBOOL // десинглетон - RED // reduce (множество-сумма) - -//------------------ Родоструктурные конструкции ------------------- -%token DECLARATIVE // выражение терма - RECURSIVE // рекурсивное определение - IMPERATIVE // императивное определение - -//-------------- Пунктуация --------------------------------- -%token DEFINE // Определение глобального идентификатора - STRUCT // Определение глобальной структуры - ASSIGN // Знак присвоения - ITERATE // Знак перебора - LP // Открывающая круглая скобка - RP // Закрывающая круглая скобка - LC // Открывающая фигурная скобка - RC // Закрывающая фигурная скобка - LS // Открывающая квадратная скобка - RS // Закрывающая квадратная скобка - BAR // Вертикальная черта -%left COMMA // Запятая -%left SEMICOLON // Точка с запятой +// ------------- Identifiers ------------------------------ +%token + LOCAL // Local identifier + GLOBAL // Global identifier + FUNCTION // Term-function + PREDICATE // Predicate-function + RADICAL // Templated argument identifier + INTEGER // Integer literal + INTSET // Set of all integers + EMPTYSET // Empty set + + +// ------------- Arithmetic operations -------------------- +%left PLUS MINUS // Add and Subtract +%left MULTIPLY // Multiply + + +// ------------- Integer predicates ----------------------- +%token + GREATER // IsGreater + LESSER // IsLesser + GREATER_OR_EQ // IsGreater or IsEqual + LESSER_OR_EQ // IsLesser or IsEqual + + +// ------------- Equality predicate ----------------------- +%token + EQUAL // IsEqual + NOTEQUAL // NotEqual + + +// ------------- First order logic ------------------------ +%token + FORALL // UniversalQuantifier + EXISTS // ExistentialQuantifier + +%right + NOT // Negation + +%left + EQUIVALENT // IsEquivalent + +%left + IMPLICATION // Implies + +%left + OR // LogicDisjunction + +%left + AND // LogicConjunction + + +// ------------- Set theory predicates -------------------- +%token + IN // IsElement + NOTIN // NotElement + SUBSET // IsSubset and NotEqual + SUBOR_EQ // IsSubset + NOTSUBSET // NotSubset + + +// ------------- Set species operations ------------------- +%left + DECART // CartesianProduct + UNION // SetDisjunction + INTERSECTION // SetConjunction + SET_MINUS // SetSubtraction + SYMMINUS // SetSymmetricDifference + +%right + BOOLEAN // PowerSet + + +// ------------- Structural operations -------------------- +%token + BIGPR // SetProjection + SMALLPR // CortegeProjection + FILTER // Filter + CARD // SetCardinality + BOOL // Singleton + DEBOOL // ExtractSingleElement + RED // SetReduction + + +// ------------- Definition constructions ----------------- +%token + DECLARATIVE // DeclarativeDefinition + RECURSIVE // RecursiveDefinition + IMPERATIVE // ImperativeDefinition + + +// ------------- Punctuation and Syntactic sugar ---------- +%token + DEFINE // Global definition separator + STRUCT // Global structure domain separator + ASSIGN // Assignment (IsEqual) + ITERATE // SetIteration (IsElement) + LP // ( + RP // ) + LC // { + RC // } + LS // [ + RS // ] + BAR // | +%left + COMMA // , +%left + SEMICOLON // ; -///////////////////////////////////////////////////////////////////////////// -//---------------- Правила грамматики --------------------------------------- %% +/////////////////////////////////////////////////////////////////////////////// +// ------------------------- Grammar Rules ------------------------------------ +/////////////////////////////////////////////////////////////////////////////// -//--------------- Выражение ------------------------------ -expression : global_declaration - | term_or_logic { state->FinalizeExpression($1); } - | function_decl { state->FinalizeExpression($1); } - ; +// ------------------------- Language Expression ------------------------------ +expression + : global_declaration + | logic_or_setexpr { state->FinalizeExpression($1); } + | function_decl { state->FinalizeExpression($1); } + ; -term_or_logic : logic - | term - ; +global_declaration + : GLOBAL DEFINE { state->FinalizeCstEmpty($1, $2); } + | GLOBAL STRUCT setexpr { state->FinalizeCstExpression($1, $2, $3); } + | GLOBAL DEFINE logic_or_setexpr { state->FinalizeCstExpression($1, $2, $3); } + | function_name DEFINE function_decl { state->FinalizeCstExpression($1, $2, $3); } + ; +function_name + : FUNCTION + | PREDICATE + ; -function_decl : LS arg_declaration RS term_or_logic { $$ = FunctionDeclaration($1, $2, $4); } - | LS error { state->OnError(ParseEID::expectedDeclaration); YYABORT; } - ; +logic_or_setexpr + : logic + | setexpr + ; -arg_declaration : declaration { $$ = AddNode(TokenID::NT_ARGUMENTS, $1); } - | arg_declaration COMMA declaration { $$ = Enumeration(TokenID::NT_ARGUMENTS, $1, $3); } - | arg_declaration COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; } - ; -declaration : LOCAL IN term { $$ = AddNode(TokenID::NT_ARG_DECL, $1, $3); } - | LOCAL error { state->OnError(ParseEID::expectedDeclaration); YYABORT; } - ; +function_decl + : LS arguments RS logic_or_setexpr { $$ = FunctionDeclaration($1, $2, $4); } + | LS error { state->OnError(ParseEID::expectedDeclaration); YYABORT; } + ; -//--------------- Выражение конституэнты ------------------------------ -global_declaration : GLOBAL DEFINE { state->FinalizeCstEmpty($1, $2); } - | GLOBAL STRUCT term { state->FinalizeCstExpression($1, $2, $3); } - | GLOBAL DEFINE term_or_logic { state->FinalizeCstExpression($1, $2, $3); } - | function_name DEFINE function_decl { state->FinalizeCstExpression($1, $2, $3); } - ; +// ------------------------- Variables and arguments ------------------------- +arguments + : declaration { $$ = AddNode(TokenID::NT_ARGUMENTS, $1); } + | arguments COMMA declaration { $$ = Enumeration(TokenID::NT_ARGUMENTS, $1, $3); } + | arguments COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; } + ; +declaration + : LOCAL IN setexpr { $$ = AddNode(TokenID::NT_ARG_DECL, $1, $3); } + | LOCAL error { state->OnError(ParseEID::expectedDeclaration); YYABORT; } + ; -//--------------- Логическое выражение ----------------------------------------- -logic : logic_predicates - | logic_unary - | logic_binary - ; -logic_all : logic - | logic_par - ; -logic_no_binary: logic_predicates - | logic_unary - | logic_par - ; -logic_par : LP logic_binary RPE { $$ = RemoveBrackets($1, $2, $3); } - | LP logic_predicates RPE { $$ = RemoveBrackets($1, $2, $3); } - ; -logic_unary : NOT logic_no_binary { $$ = UnaryOperation($1, $2);} - | quantifier quant_var IN term logic_no_binary - { $$ = Quantifier($1, $2, $4, $5);} - | quantifier error { state->OnError(ParseEID::invalidQuantifier); YYABORT; } - | PREDICATE LS term_enum RS { $$ = FunctionCall($1, $3, $4); } - ; -logic_predicates: term binary_predicate term { $$ = BinaryOperation($1, $2, $3); } - ; -logic_binary : logic_all EQUIVALENT logic_all { $$ = BinaryOperation($1, $2, $3); } - | logic_all IMPLICATION logic_all { $$ = BinaryOperation($1, $2, $3); } - | logic_all OR logic_all { $$ = BinaryOperation($1, $2, $3); } - | logic_all AND logic_all { $$ = BinaryOperation($1, $2, $3); } - ; -//--------------- Декларация локальной переменной ----------------------------- -quant_var : variable - | quant_var_enum - | LP error { state->OnError(ParseEID::invalidQuantifier); YYABORT; } - ; -quant_var_enum : quant_var COMMA quant_var { $$ = Enumeration(TokenID::NT_ENUM_DECL, $1, $3); } - | quant_var COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; } - ; +variable + : LOCAL + | LP var_enum RPE { $$ = ReplaceBrackets(TokenID::NT_TUPLE_DECL, $1, $2, $3); } + ; +var_enum + : var_all COMMA var_all { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); } + | var_all COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; } + ; +var_all + : variable + | var_enum + ; -//-------------------- Термы РС ------------------------------------- -term : literal - | identifier - | binary_operation - | typed_constructors - | FUNCTION LS term_enum RS { $$ = FunctionCall($1, $3, $4); } - | operation_name LP term RPE { $$ = TextOperator($1, $3, $4); } - ; -//--------------- Двухместная операция ------------------------------ -binary_operation: term PLUS term { $$ = BinaryOperation($1, $2, $3); } - | term MINUS term { $$ = BinaryOperation($1, $2, $3); } - | term MULTIPLY term { $$ = BinaryOperation($1, $2, $3); } - | term UNION term { $$ = BinaryOperation($1, $2, $3); } - | term SET_MINUS term { $$ = BinaryOperation($1, $2, $3); } - | term SYMMINUS term { $$ = BinaryOperation($1, $2, $3); } - | term INTERSECTION term { $$ = BinaryOperation($1, $2, $3); } - | term DECART term { $$ = Decartian($1, $2, $3);} - | LP binary_operation RPE { $$ = RemoveBrackets($1, $2, $3); } - ; -//--------------- Структурные конструкции ------------------------------ -typed_constructors : enumeration - | tuple - | boolean - | FILTER LS term_enum RS LP term RPE { $$ = FilterCall($1, $3, $6, $7); } - | declarative - | imperative - | recursion - ; -enumeration : LC term_enum RC { $$ = ReplaceBrackets(TokenID::NT_ENUMERATION, $1, $2, $3); } - ; -tuple : LP term_enum_min2 RPE { $$ = ReplaceBrackets(TokenID::NT_TUPLE, $1, $2, $3); } - ; -boolean : BOOLEAN LP term RPE { $$ = TextOperator($1, $3, $4); } - | BOOLEAN boolean { $$ = UnaryOperation($1, $2); } - ; -term_enum : term { $$ = AddNode(TokenID::INTERRUPT, $1); } - | term_enum_min2 - ; -term_enum_min2 : term_enum COMMA term { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); } - ; -declarative : LC LOCAL IN term BAR logic RCE { $$ = TermDeclaration($1, $2, $4, $6, $7); } - | DECLARATIVE LC variable IN term BAR logic RCE - { $$ = TermDeclaration($1, $3, $5, $7, $8); } - ; -recursion : RECURSIVE LC variable ASSIGN term BAR logic BAR term RCE - { $$ = FullRecursion($1, $3, $5, $7, $9, $10); } - | RECURSIVE LC variable ASSIGN term BAR term RCE - { $$ = ShortRecursion($1, $3, $5, $7, $8); } - ; -imperative : IMPERATIVE LC term BAR imp_blocks RCE { $$ = Imperative($1, $3, $5, $6); } - ; -imp_blocks : imp_block { $$ = AddNode(TokenID::INTERRUPT, $1); } - | imp_blocks SEMICOLON imp_blocks { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); } - ; -imp_block : LOCAL ITERATE term { $$ = AddNode(TokenID::NT_IMP_DECLARE, $1, $3); } - | LOCAL ASSIGN term { $$ = AddNode(TokenID::NT_IMP_ASSIGN, $1, $3); } - | logic { $$ = AddNode(TokenID::NT_IMP_LOGIC, $1); } - ; -variable : LOCAL - | LP var_enum RPE { $$ = ReplaceBrackets(TokenID::NT_TUPLE_DECL, $1, $2, $3); } - ; -var_enum : var_all COMMA var_all { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); } - | var_all COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; } - ; -var_all : variable - | var_enum - ; +// ------------------------- Logic Expressions -------------------------------- +logic + : logic_predicates + | logic_unary + | logic_binary + ; +logic_all + : logic + | logic_par + ; +logic_par + : LP logic_binary RPE { $$ = RemoveBrackets($1, $2, $3); } + | LP logic_predicates RPE { $$ = RemoveBrackets($1, $2, $3); } + ; -//------------ Идентификаторы ------------------- -function_name : FUNCTION - | PREDICATE - ; -global_id : GLOBAL - | function_name - | RADICAL - ; -identifier : global_id - | LOCAL - ; -literal : INTEGER - | EMPTYSET - | INFINITY - ; -//------------- Кванторы -------------------------- -quantifier : FORALL - | EXISTS - ; -//------------ Встроенные функции ---------------- -operation_name : BOOL - | DEBOOL - | RED - | BIGPR - | SMALLPR - | CARD - ; -//--------------- Двухместный предикат -------- -binary_predicate : IN - | NOTIN - | SUBSET - | SUBOR_EQ - | NOTSUBSET - | NOTEQUAL - | EQUAL - | GREATER - | LESSER - | GREATER_OR_EQ - | LESSER_OR_EQ - ; -//--------------- Скобки ---------------- -RPE : RP - | error { state->OnError(ParseEID::missingParanthesis); YYABORT; } - ; -RCE : RC - | error { state->OnError(ParseEID::missingCurlyBrace); YYABORT; } - ; +logic_predicates + : setexpr binary_predicate setexpr { $$ = BinaryOperation($1, $2, $3); } + ; +binary_predicate + : IN + | NOTIN + | SUBSET + | SUBOR_EQ + | NOTSUBSET + | NOTEQUAL + | EQUAL + | GREATER + | LESSER + | GREATER_OR_EQ + | LESSER_OR_EQ + ; +logic_unary + : NOT logic_no_binary { $$ = UnaryOperation($1, $2);} + | quantifier quant_var IN setexpr logic_no_binary { $$ = Quantifier($1, $2, $4, $5);} + | quantifier error { state->OnError(ParseEID::invalidQuantifier); YYABORT; } + | PREDICATE LS setexpr_enum RS { $$ = FunctionCall($1, $3, $4); } + ; +logic_no_binary + : logic_predicates + | logic_unary + | logic_par + ; +quantifier + : FORALL + | EXISTS + ; +quant_var + : variable + | quant_var_enum + | LP error { state->OnError(ParseEID::invalidQuantifier); YYABORT; } + ; +quant_var_enum + : quant_var COMMA quant_var { $$ = Enumeration(TokenID::NT_ENUM_DECL, $1, $3); } + | quant_var COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; } + ; + +logic_binary + : logic_all EQUIVALENT logic_all { $$ = BinaryOperation($1, $2, $3); } + | logic_all IMPLICATION logic_all { $$ = BinaryOperation($1, $2, $3); } + | logic_all OR logic_all { $$ = BinaryOperation($1, $2, $3); } + | logic_all AND logic_all { $$ = BinaryOperation($1, $2, $3); } + ; + + +// ------------------------- Set Expressions ---------------------------------- +setexpr + : literal + | identifier + | setexpr_binary + | setexpr_generators + | FUNCTION LS setexpr_enum RS { $$ = FunctionCall($1, $3, $4); } + | operation_name LP setexpr RPE { $$ = TextOperator($1, $3, $4); } + ; +operation_name + : BOOL + | DEBOOL + | RED + | BIGPR + | SMALLPR + | CARD + ; +setexpr_enum + : setexpr { $$ = AddNode(TokenID::INTERRUPT, $1); } + | setexpr_enum_min2 + ; +setexpr_enum_min2 + : setexpr_enum COMMA setexpr { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); } + ; + +literal + : INTEGER + | EMPTYSET + | INTSET + ; + +identifier + : GLOBAL + | function_name + | RADICAL + | LOCAL + ; + +setexpr_binary + : setexpr PLUS setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr MINUS setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr MULTIPLY setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr UNION setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr SET_MINUS setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr SYMMINUS setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr INTERSECTION setexpr { $$ = BinaryOperation($1, $2, $3); } + | setexpr DECART setexpr { $$ = Decartian($1, $2, $3);} + | LP setexpr_binary RPE { $$ = RemoveBrackets($1, $2, $3); } + ; + +setexpr_generators + : enumeration + | tuple + | boolean + | filter_expression + | declarative + | imperative + | recursion + ; +enumeration + : LC setexpr_enum RC { $$ = ReplaceBrackets(TokenID::NT_ENUMERATION, $1, $2, $3); } + ; +tuple + : LP setexpr_enum_min2 RPE { $$ = ReplaceBrackets(TokenID::NT_TUPLE, $1, $2, $3); } + ; +boolean + : BOOLEAN LP setexpr RPE { $$ = TextOperator($1, $3, $4); } + | BOOLEAN boolean { $$ = UnaryOperation($1, $2); } + ; +filter_expression + : FILTER LS setexpr_enum RS LP setexpr RPE { $$ = FilterCall($1, $3, $6, $7); } + ; + +declarative + : LC LOCAL IN setexpr BAR logic RCE { $$ = TermDeclaration($1, $2, $4, $6, $7); } + | DECLARATIVE LC variable IN setexpr BAR logic RCE { $$ = TermDeclaration($1, $3, $5, $7, $8); } + ; +recursion + : RECURSIVE LC variable ASSIGN setexpr BAR logic BAR setexpr RCE { $$ = FullRecursion($1, $3, $5, $7, $9, $10); } + | RECURSIVE LC variable ASSIGN setexpr BAR setexpr RCE { $$ = ShortRecursion($1, $3, $5, $7, $8); } + ; +imperative + : IMPERATIVE LC setexpr BAR imp_blocks RCE { $$ = Imperative($1, $3, $5, $6); } + ; +imp_blocks + : imp_block { $$ = AddNode(TokenID::INTERRUPT, $1); } + | imp_blocks SEMICOLON imp_blocks { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); } + ; +imp_block + : LOCAL ITERATE setexpr { $$ = AddNode(TokenID::NT_IMP_DECLARE, $1, $3); } + | LOCAL ASSIGN setexpr { $$ = AddNode(TokenID::NT_IMP_ASSIGN, $1, $3); } + | logic { $$ = AddNode(TokenID::NT_IMP_LOGIC, $1); } + ; + + +// ------------------------- Error helpers ------------------------------------ +RPE + : RP + | error { state->OnError(ParseEID::missingParenthesis); YYABORT; } + ; +RCE + : RC + | error { state->OnError(ParseEID::missingCurlyBrace); YYABORT; } + ; + + +/////////////////////////////////////////////////////////// +// ------------- Code Wrapper at FileEnd ---------------- +/////////////////////////////////////////////////////////// %% #ifdef _MSC_VER diff --git a/ccl/rslang/src/SDImplementation.cpp b/ccl/rslang/src/SDImplementation.cpp index b6c80ea..3f3a513 100644 --- a/ccl/rslang/src/SDImplementation.cpp +++ b/ccl/rslang/src/SDImplementation.cpp @@ -147,8 +147,8 @@ bool SDPowerSet::Contains(StructuredData element) const { return element.B().IsSubsetOrEq(base.B()); } -SDDecartian::Iterator::Iterator(const SDDecartian& decart, const bool completed) - : decartian{ &decart }, isCompleted{ completed || decartian->Cardinality() == 0 } { +SDDecartian::Iterator::Iterator(const SDDecartian& base, const bool completed) + : decartian{ &base }, isCompleted{ completed || base.Cardinality() == 0 } { if (!isCompleted) { componentIters.reserve(size(decartian->factors)); for (const auto& factor : decartian->factors) { diff --git a/ccl/rslang/src/SDataCompact.cpp b/ccl/rslang/src/SDataCompact.cpp index 914c97c..2e951da 100644 --- a/ccl/rslang/src/SDataCompact.cpp +++ b/ccl/rslang/src/SDataCompact.cpp @@ -1,6 +1,10 @@ #include "ccl/rslang/SDataCompact.h" #include "ccl/rslang/RSToken.h" +#include "ccl/rslang/Typification.h" +#include "ccl/rslang/StructuredData.h" + +#include namespace ccl::object { diff --git a/ccl/rslang/test/src/testStructuredData.cpp b/ccl/rslang/test/src/testStructuredData.cpp index ac655ff..240559b 100644 --- a/ccl/rslang/test/src/testStructuredData.cpp +++ b/ccl/rslang/test/src/testStructuredData.cpp @@ -309,20 +309,20 @@ TEST_F(UTStructuredData, SetProjection) { TEST_F(UTStructuredData, DecartianCreate) { const auto bSet1 = Factory::Set({ el1, el2 }); const auto bSet2 = Factory::Set({ el1, el2, el3 }); - const auto decart = Factory::Decartian({ bSet1, bSet2 }); - EXPECT_TRUE(decart.IsCollection()); - EXPECT_TRUE(std::begin(decart.B())->IsTuple()); - EXPECT_EQ(bSet1.B().Cardinality() * bSet2.B().Cardinality(), decart.B().Cardinality()); + const auto decartian = Factory::Decartian({ bSet1, bSet2 }); + EXPECT_TRUE(decartian.IsCollection()); + EXPECT_TRUE(std::begin(decartian.B())->IsTuple()); + EXPECT_EQ(bSet1.B().Cardinality() * bSet2.B().Cardinality(), decartian.B().Cardinality()); } TEST_F(UTStructuredData, DecartianAddElement) { const auto bSet1 = Factory::Set({ el1 }); const auto bSet2 = Factory::Set({ el1 }); - auto decart = Factory::Decartian({ bSet1, bSet2 }); - EXPECT_FALSE(decart.ModifyB().AddElement(Factory::Set({ el1 }))); - EXPECT_FALSE(decart.ModifyB().AddElement(Factory::Tuple({ el1, el1 }))); - EXPECT_FALSE(decart.ModifyB().AddElement(Factory::Tuple({ el1, el2 }))); - EXPECT_FALSE(decart.ModifyB().AddElement(Factory::EmptySet())); + auto decartian = Factory::Decartian({ bSet1, bSet2 }); + EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::Set({ el1 }))); + EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::Tuple({ el1, el1 }))); + EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::Tuple({ el1, el2 }))); + EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::EmptySet())); } TEST_F(UTStructuredData, DecartianEmpty) { @@ -334,29 +334,29 @@ TEST_F(UTStructuredData, DecartianEmpty) { TEST_F(UTStructuredData, DecartianAsymmetry) { const auto bSet1 = Factory::Singleton(el1); const auto bSet2 = Factory::Singleton(el3); - const auto decart12 = Factory::Decartian({ bSet1, bSet2 }); - const auto decart21 = Factory::Decartian({ bSet2, bSet1 }); - EXPECT_NE(decart12, decart21); + const auto decartian12 = Factory::Decartian({ bSet1, bSet2 }); + const auto decartian21 = Factory::Decartian({ bSet2, bSet1 }); + EXPECT_NE(decartian12, decartian21); } TEST_F(UTStructuredData, DecartianContains) { const auto bSet1 = Factory::Set({ el1, el2 }); const auto bSet2 = Factory::Set({ el1, el2, el3 }); - const auto decart = Factory::Decartian({ bSet1, bSet2 }); - EXPECT_TRUE(decart.B().Contains(Factory::Tuple({ el1, el3 }))); - EXPECT_FALSE(decart.B().Contains(Factory::Tuple({ el3, el3 }))); - EXPECT_FALSE(decart.B().Contains(Factory::Tuple({ el1, el3, el3 }))); + const auto decartian = Factory::Decartian({ bSet1, bSet2 }); + EXPECT_TRUE(decartian.B().Contains(Factory::Tuple({ el1, el3 }))); + EXPECT_FALSE(decartian.B().Contains(Factory::Tuple({ el3, el3 }))); + EXPECT_FALSE(decartian.B().Contains(Factory::Tuple({ el1, el3, el3 }))); } TEST_F(UTStructuredData, DecartianIteration) { const auto bSet1 = Factory::Set({ el1, el2 }); const auto bSet2 = Factory::Set({ el1, el2, el3 }); - const auto decart = Factory::Decartian({ bSet1, bSet2 }); + const auto decartian = Factory::Decartian({ bSet1, bSet2 }); auto elements = std::set{}; - for (const auto& el : decart.B()) { + for (const auto& el : decartian.B()) { elements.insert(el); } - EXPECT_EQ(decart.B().Cardinality(), ssize(elements)); + EXPECT_EQ(decartian.B().Cardinality(), ssize(elements)); } TEST_F(UTStructuredData, BooleanCreate) { diff --git a/scripts/BuildParser.ps1 b/scripts/BuildParser.ps1 index e1d3456..01643ea 100644 --- a/scripts/BuildParser.ps1 +++ b/scripts/BuildParser.ps1 @@ -1,6 +1,6 @@ # Generate lexers for RSlang -$bison = 'C:\GnuWin32\win_flex_bison3\win_bison.exe' +$bison = 'C:\ProgramData\chocolatey\bin\win_bison.exe' $workDir = Resolve-Path -Path "${PSScriptRoot}\..\ccl\rslang\src" $grammar = 'RSParserImpl.y'