mirror of
https://github.com/IRBorisov/ConceptCore.git
synced 2025-08-14 08:00:36 +03:00
Refactoring: cleanup grammar and upgrade Bison
This commit is contained in:
parent
173e38f052
commit
c4db405fbe
|
@ -20,6 +20,7 @@ Checks: "*,\
|
||||||
-google-readability-todo,\
|
-google-readability-todo,\
|
||||||
-google-global-names-in-headers,\
|
-google-global-names-in-headers,\
|
||||||
-readability-redundant-access-specifiers,\
|
-readability-redundant-access-specifiers,\
|
||||||
|
-readability-redundant-member-init,\
|
||||||
-readability-else-after-return,\
|
-readability-else-after-return,\
|
||||||
-readability-implicit-bool-conversion,\
|
-readability-implicit-bool-conversion,\
|
||||||
-readability-use-anyofallof,\
|
-readability-use-anyofallof,\
|
||||||
|
|
97
.vscode/settings.json
vendored
97
.vscode/settings.json
vendored
|
@ -20,9 +20,12 @@
|
||||||
"coredll",
|
"coredll",
|
||||||
"DCMAKE",
|
"DCMAKE",
|
||||||
"debool",
|
"debool",
|
||||||
|
"DECART",
|
||||||
"Decartian",
|
"Decartian",
|
||||||
"defexpr",
|
"defexpr",
|
||||||
|
"GNUC",
|
||||||
"gtest",
|
"gtest",
|
||||||
|
"ifdef",
|
||||||
"MSVC",
|
"MSVC",
|
||||||
"nlohmann",
|
"nlohmann",
|
||||||
"noteq",
|
"noteq",
|
||||||
|
@ -30,6 +33,96 @@
|
||||||
"pybind",
|
"pybind",
|
||||||
"pyconcept",
|
"pyconcept",
|
||||||
"rslang",
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
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)
|
- lexer requires [Re-flex](https://github.com/Genivia/RE-flex)
|
||||||
|
|
||||||
To run terminal after building docker container use command
|
To run terminal after building docker container use command
|
||||||
|
|
|
@ -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++
|
// 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
|
// 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
|
// 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.
|
// C++ LALR(1) parser skeleton written by Akim Demaille.
|
||||||
|
|
||||||
// Undocumented macros, especially those whose name start with YY_,
|
// DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
|
||||||
// are private implementation details. Do not rely on them.
|
// 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
|
#ifndef YY_YY_HEADER_RSPARSERIMPL_H_INCLUDED
|
||||||
# define YY_YY_HEADER_RSPARSERIMPL_H_INCLUDED
|
# define YY_YY_HEADER_RSPARSERIMPL_H_INCLUDED
|
||||||
// // "%code requires" blocks.
|
// "%code requires" blocks.
|
||||||
#line 36 "RSParserImpl.y" // lalr1.cc:401
|
#line 48 "RSParserImpl.y"
|
||||||
|
|
||||||
#include "ccl/rslang/SyntaxTree.h"
|
#include "ccl/rslang/SyntaxTree.h"
|
||||||
#include "ccl/rslang/ParserState.hpp"
|
#include "ccl/rslang/ParserState.hpp"
|
||||||
|
@ -54,32 +55,89 @@ namespace ccl::rslang::detail {
|
||||||
#define YYSTYPE RawNode
|
#define YYSTYPE RawNode
|
||||||
struct ParserState;
|
struct ParserState;
|
||||||
|
|
||||||
|
int yylex(RawNode* yylval, ParserState* state);
|
||||||
|
|
||||||
RawNode AddNode(TokenID token, RawNode son);
|
RawNode AddNode(TokenID token, RawNode son);
|
||||||
RawNode AddNode(TokenID token, RawNode son1, RawNode son2);
|
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 RemoveBrackets(RawNode br1, RawNode operand, RawNode br2);
|
||||||
RawNode ReplaceBrackets(TokenID token, RawNode br1, RawNode argList, 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 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 Decartian(
|
||||||
RawNode FunctionDeclaration(RawNode start, RawNode argdecl, RawNode expr);
|
RawNode op1,
|
||||||
RawNode FunctionCall(RawNode function, RawNode args, RawNode rs);
|
RawNode decartian,
|
||||||
RawNode FilterCall(RawNode filter, RawNode params, RawNode argument, RawNode rp);
|
RawNode op2
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
} // namespace ccl::rslang::detail
|
||||||
|
|
||||||
|
#line 141 "../header/RSParserImpl.h"
|
||||||
#line 83 "../header/RSParserImpl.h" // lalr1.cc:401
|
|
||||||
|
|
||||||
# include <cassert>
|
# include <cassert>
|
||||||
# include <cstdlib> // std::abort
|
# include <cstdlib> // std::abort
|
||||||
|
@ -127,22 +185,20 @@ int yylex(RawNode* yylval, ParserState* state);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef YY_ATTRIBUTE
|
#ifndef YY_ATTRIBUTE_PURE
|
||||||
# if (defined __GNUC__ \
|
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
|
||||||
&& (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
|
# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
|
||||||
|| defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
|
|
||||||
# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
|
|
||||||
# else
|
# else
|
||||||
# define YY_ATTRIBUTE(Spec) /* empty */
|
# define YY_ATTRIBUTE_PURE
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef YY_ATTRIBUTE_PURE
|
|
||||||
# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef YY_ATTRIBUTE_UNUSED
|
#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
|
#endif
|
||||||
|
|
||||||
/* Suppress unused-variable warnings by "using" E. */
|
/* 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__
|
#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
|
||||||
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
|
/* Suppress an incorrect diagnostic about yylval being uninitialized. */
|
||||||
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
|
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
|
||||||
_Pragma ("GCC diagnostic push") \
|
_Pragma ("GCC diagnostic push") \
|
||||||
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
|
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
|
||||||
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
|
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
|
||||||
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
|
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
|
||||||
_Pragma ("GCC diagnostic pop")
|
_Pragma ("GCC diagnostic pop")
|
||||||
#else
|
#else
|
||||||
# define YY_INITIAL_VALUE(Value) Value
|
# define YY_INITIAL_VALUE(Value) Value
|
||||||
|
@ -171,6 +227,27 @@ int yylex(RawNode* yylval, ParserState* state);
|
||||||
# define YY_INITIAL_VALUE(Value) /* Nothing. */
|
# define YY_INITIAL_VALUE(Value) /* Nothing. */
|
||||||
#endif
|
#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<Type> (Val)
|
||||||
|
# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
|
||||||
|
# else
|
||||||
|
# define YY_CAST(Type, Val) ((Type) (Val))
|
||||||
|
# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
# ifndef YY_NULLPTR
|
# ifndef YY_NULLPTR
|
||||||
# if defined __cplusplus
|
# if defined __cplusplus
|
||||||
# if 201103L <= __cplusplus
|
# if 201103L <= __cplusplus
|
||||||
|
@ -188,9 +265,10 @@ int yylex(RawNode* yylval, ParserState* state);
|
||||||
# define YYDEBUG 0
|
# define YYDEBUG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#line 11 "RSParserImpl.y" // lalr1.cc:401
|
#line 15 "RSParserImpl.y"
|
||||||
namespace ccl { namespace rslang { namespace detail {
|
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;
|
~syntax_error () YY_NOEXCEPT YY_NOTHROW;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Tokens.
|
/// Token kinds.
|
||||||
struct token
|
struct token
|
||||||
{
|
{
|
||||||
enum yytokentype
|
enum token_kind_type
|
||||||
{
|
{
|
||||||
RST_LOCAL = 258,
|
RST_YYEMPTY = -2,
|
||||||
RST_GLOBAL = 259,
|
RST_YYEOF = 0, // "end of file"
|
||||||
RST_FUNCTION = 260,
|
RST_YYerror = 256, // error
|
||||||
RST_PREDICATE = 261,
|
RST_YYUNDEF = 257, // "invalid token"
|
||||||
RST_RADICAL = 262,
|
RST_LOCAL = 258, // LOCAL
|
||||||
RST_INTEGER = 263,
|
RST_GLOBAL = 259, // GLOBAL
|
||||||
RST_INFINITY = 264,
|
RST_FUNCTION = 260, // FUNCTION
|
||||||
RST_EMPTYSET = 265,
|
RST_PREDICATE = 261, // PREDICATE
|
||||||
RST_PLUS = 266,
|
RST_RADICAL = 262, // RADICAL
|
||||||
RST_MINUS = 267,
|
RST_INTEGER = 263, // INTEGER
|
||||||
RST_MULTIPLY = 268,
|
RST_INTSET = 264, // INTSET
|
||||||
RST_GREATER = 269,
|
RST_EMPTYSET = 265, // EMPTYSET
|
||||||
RST_LESSER = 270,
|
RST_PLUS = 266, // PLUS
|
||||||
RST_GREATER_OR_EQ = 271,
|
RST_MINUS = 267, // MINUS
|
||||||
RST_LESSER_OR_EQ = 272,
|
RST_MULTIPLY = 268, // MULTIPLY
|
||||||
RST_EQUAL = 273,
|
RST_GREATER = 269, // GREATER
|
||||||
RST_NOTEQUAL = 274,
|
RST_LESSER = 270, // LESSER
|
||||||
RST_FORALL = 275,
|
RST_GREATER_OR_EQ = 271, // GREATER_OR_EQ
|
||||||
RST_EXISTS = 276,
|
RST_LESSER_OR_EQ = 272, // LESSER_OR_EQ
|
||||||
RST_NOT = 277,
|
RST_EQUAL = 273, // EQUAL
|
||||||
RST_EQUIVALENT = 278,
|
RST_NOTEQUAL = 274, // NOTEQUAL
|
||||||
RST_IMPLICATION = 279,
|
RST_FORALL = 275, // FORALL
|
||||||
RST_OR = 280,
|
RST_EXISTS = 276, // EXISTS
|
||||||
RST_AND = 281,
|
RST_NOT = 277, // NOT
|
||||||
RST_IN = 282,
|
RST_EQUIVALENT = 278, // EQUIVALENT
|
||||||
RST_NOTIN = 283,
|
RST_IMPLICATION = 279, // IMPLICATION
|
||||||
RST_SUBSET = 284,
|
RST_OR = 280, // OR
|
||||||
RST_SUBOR_EQ = 285,
|
RST_AND = 281, // AND
|
||||||
RST_NOTSUBSET = 286,
|
RST_IN = 282, // IN
|
||||||
RST_DECART = 287,
|
RST_NOTIN = 283, // NOTIN
|
||||||
RST_UNION = 288,
|
RST_SUBSET = 284, // SUBSET
|
||||||
RST_INTERSECTION = 289,
|
RST_SUBOR_EQ = 285, // SUBOR_EQ
|
||||||
RST_SET_MINUS = 290,
|
RST_NOTSUBSET = 286, // NOTSUBSET
|
||||||
RST_SYMMINUS = 291,
|
RST_DECART = 287, // DECART
|
||||||
RST_BOOLEAN = 292,
|
RST_UNION = 288, // UNION
|
||||||
RST_BIGPR = 293,
|
RST_INTERSECTION = 289, // INTERSECTION
|
||||||
RST_SMALLPR = 294,
|
RST_SET_MINUS = 290, // SET_MINUS
|
||||||
RST_FILTER = 295,
|
RST_SYMMINUS = 291, // SYMMINUS
|
||||||
RST_CARD = 296,
|
RST_BOOLEAN = 292, // BOOLEAN
|
||||||
RST_BOOL = 297,
|
RST_BIGPR = 293, // BIGPR
|
||||||
RST_DEBOOL = 298,
|
RST_SMALLPR = 294, // SMALLPR
|
||||||
RST_RED = 299,
|
RST_FILTER = 295, // FILTER
|
||||||
RST_DECLARATIVE = 300,
|
RST_CARD = 296, // CARD
|
||||||
RST_RECURSIVE = 301,
|
RST_BOOL = 297, // BOOL
|
||||||
RST_IMPERATIVE = 302,
|
RST_DEBOOL = 298, // DEBOOL
|
||||||
RST_DEFINE = 303,
|
RST_RED = 299, // RED
|
||||||
RST_STRUCT = 304,
|
RST_DECLARATIVE = 300, // DECLARATIVE
|
||||||
RST_ASSIGN = 305,
|
RST_RECURSIVE = 301, // RECURSIVE
|
||||||
RST_ITERATE = 306,
|
RST_IMPERATIVE = 302, // IMPERATIVE
|
||||||
RST_LP = 307,
|
RST_DEFINE = 303, // DEFINE
|
||||||
RST_RP = 308,
|
RST_STRUCT = 304, // STRUCT
|
||||||
RST_LC = 309,
|
RST_ASSIGN = 305, // ASSIGN
|
||||||
RST_RC = 310,
|
RST_ITERATE = 306, // ITERATE
|
||||||
RST_LS = 311,
|
RST_LP = 307, // LP
|
||||||
RST_RS = 312,
|
RST_RP = 308, // RP
|
||||||
RST_BAR = 313,
|
RST_LC = 309, // LC
|
||||||
RST_COMMA = 314,
|
RST_RC = 310, // RC
|
||||||
RST_SEMICOLON = 315
|
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.
|
/// (Internal) symbol kind.
|
||||||
typedef token::yytokentype token_type;
|
typedef symbol_kind::symbol_kind_type symbol_kind_type;
|
||||||
|
|
||||||
/// Symbol type: an internal symbol number.
|
/// The number of tokens.
|
||||||
typedef int symbol_number_type;
|
static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS;
|
||||||
|
|
||||||
/// 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;
|
|
||||||
|
|
||||||
/// A complete symbol.
|
/// A complete symbol.
|
||||||
///
|
///
|
||||||
/// Expects its Base type to provide access to the symbol type
|
/// Expects its Base type to provide access to the symbol kind
|
||||||
/// via type_get ().
|
/// via kind ().
|
||||||
///
|
///
|
||||||
/// Provide access to semantic value.
|
/// Provide access to semantic value.
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
|
@ -316,7 +512,10 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
|
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
/// Move constructor.
|
/// Move constructor.
|
||||||
basic_symbol (basic_symbol&& that);
|
basic_symbol (basic_symbol&& that)
|
||||||
|
: Base (std::move (that))
|
||||||
|
, value (std::move (that.value))
|
||||||
|
{}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
|
@ -340,6 +539,15 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
Base::clear ();
|
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.
|
/// Whether empty.
|
||||||
bool empty () const YY_NOEXCEPT;
|
bool empty () const YY_NOEXCEPT;
|
||||||
|
|
||||||
|
@ -357,52 +565,61 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Type access provider for token (enum) based symbols.
|
/// Type access provider for token (enum) based symbols.
|
||||||
struct by_type
|
struct by_kind
|
||||||
{
|
{
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
by_type ();
|
by_kind ();
|
||||||
|
|
||||||
#if 201103L <= YY_CPLUSPLUS
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
/// Move constructor.
|
/// Move constructor.
|
||||||
by_type (by_type&& that);
|
by_kind (by_kind&& that);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
by_type (const by_type& that);
|
by_kind (const by_kind& that);
|
||||||
|
|
||||||
/// The symbol type as needed by the constructor.
|
/// The symbol kind as needed by the constructor.
|
||||||
typedef token_type kind_type;
|
typedef token_kind_type kind_type;
|
||||||
|
|
||||||
/// Constructor from (external) token numbers.
|
/// Constructor from (external) token numbers.
|
||||||
by_type (kind_type t);
|
by_kind (kind_type t);
|
||||||
|
|
||||||
/// Record that this symbol is empty.
|
/// Record that this symbol is empty.
|
||||||
void clear ();
|
void clear ();
|
||||||
|
|
||||||
/// Steal the symbol type from \a that.
|
/// Steal the symbol kind from \a that.
|
||||||
void move (by_type& that);
|
void move (by_kind& that);
|
||||||
|
|
||||||
/// The (internal) type number (corresponding to \a type).
|
/// The (internal) type number (corresponding to \a type).
|
||||||
/// \a empty when empty.
|
/// \a empty when empty.
|
||||||
symbol_number_type type_get () const YY_NOEXCEPT;
|
symbol_kind_type kind () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The token.
|
/// Backward compatibility (Bison 3.6).
|
||||||
token_type token () const YY_NOEXCEPT;
|
symbol_kind_type type_get () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The symbol type.
|
/// The symbol kind.
|
||||||
/// \a empty_symbol when empty.
|
/// \a S_YYEMPTY when empty.
|
||||||
/// An int, not token_number_type, to be able to store empty_symbol.
|
symbol_kind_type kind_;
|
||||||
int type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Backward compatibility for a private implementation detail (Bison 3.6).
|
||||||
|
typedef by_kind by_type;
|
||||||
|
|
||||||
/// "External" symbols: returned by the scanner.
|
/// "External" symbols: returned by the scanner.
|
||||||
struct symbol_type : basic_symbol<by_type>
|
struct symbol_type : basic_symbol<by_kind>
|
||||||
{};
|
{};
|
||||||
|
|
||||||
/// Build a parser object.
|
/// Build a parser object.
|
||||||
RSParserImpl (ParserState* state_yyarg);
|
RSParserImpl (ParserState* state_yyarg);
|
||||||
virtual ~RSParserImpl ();
|
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 ().
|
/// Parse. An alias for parse ().
|
||||||
/// \returns 0 iff parsing succeeded.
|
/// \returns 0 iff parsing succeeded.
|
||||||
int operator() ();
|
int operator() ();
|
||||||
|
@ -432,26 +649,51 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
/// Report a syntax error.
|
/// Report a syntax error.
|
||||||
void error (const syntax_error& err);
|
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:
|
private:
|
||||||
/// This class is not copyable.
|
#if YY_CPLUSPLUS < 201103L
|
||||||
|
/// Non copyable.
|
||||||
RSParserImpl (const RSParserImpl&);
|
RSParserImpl (const RSParserImpl&);
|
||||||
|
/// Non copyable.
|
||||||
RSParserImpl& operator= (const RSParserImpl&);
|
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.
|
/// Generate an error message.
|
||||||
/// \param yystate the state where the error occurred.
|
/// \param yyctx the context in which the error occurred.
|
||||||
/// \param yyla the lookahead token.
|
virtual std::string yysyntax_error_ (const context& yyctx) const;
|
||||||
virtual std::string yysyntax_error_ (state_type yystate,
|
|
||||||
const symbol_type& yyla) const;
|
|
||||||
|
|
||||||
/// Compute post-reduction state.
|
/// Compute post-reduction state.
|
||||||
/// \param yystate the current state
|
/// \param yystate the current state
|
||||||
/// \param yysym the nonterminal to push on the stack
|
/// \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.
|
/// Whether the given \c yypact_ value indicates a defaulted state.
|
||||||
/// \param yyvalue the value to check
|
/// \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 yypact_ninf_;
|
||||||
static const signed char yytable_ninf_;
|
static const signed char yytable_ninf_;
|
||||||
|
|
||||||
/// Convert a scanner token number \a t to a symbol number.
|
/// Convert a scanner token kind \a t to a symbol kind.
|
||||||
static token_number_type yytranslate_ (int t);
|
/// In theory \a t should be a token_kind_type, but character literals
|
||||||
|
/// are valid, yet not members of the token_type enum.
|
||||||
// Tables.
|
static symbol_kind_type yytranslate_ (int t);
|
||||||
// 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 the symbol name \a n to a form suitable for a diagnostic.
|
/// 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.
|
/// For a symbol, its name in clear.
|
||||||
static const char* const yytname_[];
|
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
|
#if YYDEBUG
|
||||||
// YYRLINE[YYN] -- Source line where rule number YYN was defined.
|
// YYRLINE[YYN] -- Source line where rule number YYN was defined.
|
||||||
static const unsigned short yyrline_[];
|
static const short yyrline_[];
|
||||||
/// Report on the debug stream that the rule \a r is going to be reduced.
|
/// 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.
|
/// Print the state stack on the debug stream.
|
||||||
virtual void yystack_print_ ();
|
virtual void yy_stack_print_ () const;
|
||||||
|
|
||||||
/// Debugging level.
|
/// Debugging level.
|
||||||
int yydebug_;
|
int yydebug_;
|
||||||
/// Debug stream.
|
/// Debug stream.
|
||||||
std::ostream* yycdebug_;
|
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 yyo The output stream.
|
||||||
/// \param yysym The symbol.
|
/// \param yysym The symbol.
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
|
@ -541,7 +786,7 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
by_state () YY_NOEXCEPT;
|
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;
|
typedef state_type kind_type;
|
||||||
|
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
|
@ -553,15 +798,16 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
/// Record that this symbol is empty.
|
/// Record that this symbol is empty.
|
||||||
void clear () YY_NOEXCEPT;
|
void clear () YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Steal the symbol type from \a that.
|
/// Steal the symbol kind from \a that.
|
||||||
void move (by_state& that);
|
void move (by_state& that);
|
||||||
|
|
||||||
/// The (internal) type number (corresponding to \a state).
|
/// The symbol kind (corresponding to \a state).
|
||||||
/// \a empty_symbol when empty.
|
/// \a symbol_kind::S_YYEMPTY when empty.
|
||||||
symbol_number_type type_get () const YY_NOEXCEPT;
|
symbol_kind_type kind () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The state number used to denote an empty symbol.
|
/// 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.
|
/// The state.
|
||||||
/// \a empty when empty.
|
/// \a empty when empty.
|
||||||
|
@ -583,6 +829,10 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
/// Assignment, needed by push_back by some old implementations.
|
/// Assignment, needed by push_back by some old implementations.
|
||||||
/// Moves the contents of that.
|
/// Moves the contents of that.
|
||||||
stack_symbol_type& operator= (stack_symbol_type& 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
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -592,48 +842,38 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Hide our reversed order.
|
// Hide our reversed order.
|
||||||
typedef typename S::reverse_iterator iterator;
|
typedef typename S::iterator iterator;
|
||||||
typedef typename S::const_reverse_iterator const_iterator;
|
typedef typename S::const_iterator const_iterator;
|
||||||
typedef typename S::size_type size_type;
|
typedef typename S::size_type size_type;
|
||||||
|
typedef typename std::ptrdiff_t index_type;
|
||||||
|
|
||||||
stack (size_type n = 200)
|
stack (size_type n = 200)
|
||||||
: seq_ (n)
|
: seq_ (n)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
|
/// Non copyable.
|
||||||
|
stack (const stack&) = delete;
|
||||||
|
/// Non copyable.
|
||||||
|
stack& operator= (const stack&) = delete;
|
||||||
|
#endif
|
||||||
|
|
||||||
/// Random access.
|
/// Random access.
|
||||||
///
|
///
|
||||||
/// Index 0 returns the topmost element.
|
/// Index 0 returns the topmost element.
|
||||||
T&
|
const T&
|
||||||
operator[] (size_type i)
|
operator[] (index_type i) const
|
||||||
{
|
{
|
||||||
return seq_[size () - 1 - i];
|
return seq_[size_type (size () - 1 - i)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Random access.
|
/// Random access.
|
||||||
///
|
///
|
||||||
/// Index 0 returns the topmost element.
|
/// Index 0 returns the topmost element.
|
||||||
T&
|
T&
|
||||||
operator[] (int i)
|
operator[] (index_type i)
|
||||||
{
|
{
|
||||||
return operator[] (size_type (i));
|
return seq_[size_type (size () - 1 - 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Steal the contents of \a t.
|
/// Steal the contents of \a t.
|
||||||
|
@ -648,7 +888,7 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
|
|
||||||
/// Pop elements from the stack.
|
/// Pop elements from the stack.
|
||||||
void
|
void
|
||||||
pop (int n = 1) YY_NOEXCEPT
|
pop (std::ptrdiff_t n = 1) YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
for (; 0 < n; --n)
|
for (; 0 < n; --n)
|
||||||
seq_.pop_back ();
|
seq_.pop_back ();
|
||||||
|
@ -662,49 +902,53 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Number of elements on the stack.
|
/// Number of elements on the stack.
|
||||||
size_type
|
index_type
|
||||||
size () const YY_NOEXCEPT
|
size () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.size ();
|
return index_type (seq_.size ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterator on top of the stack (going downwards).
|
/// Iterator on top of the stack (going downwards).
|
||||||
const_iterator
|
const_iterator
|
||||||
begin () const YY_NOEXCEPT
|
begin () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.rbegin ();
|
return seq_.begin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bottom of the stack.
|
/// Bottom of the stack.
|
||||||
const_iterator
|
const_iterator
|
||||||
end () const YY_NOEXCEPT
|
end () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.rend ();
|
return seq_.end ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Present a slice of the top of a stack.
|
/// Present a slice of the top of a stack.
|
||||||
class slice
|
class slice
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
slice (const stack& stack, int range)
|
slice (const stack& stack, index_type range)
|
||||||
: stack_ (stack)
|
: stack_ (stack)
|
||||||
, range_ (range)
|
, range_ (range)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const T&
|
const T&
|
||||||
operator[] (int i) const
|
operator[] (index_type i) const
|
||||||
{
|
{
|
||||||
return stack_[range_ - i];
|
return stack_[range_ - i];
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const stack& stack_;
|
const stack& stack_;
|
||||||
int range_;
|
index_type range_;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if YY_CPLUSPLUS < 201103L
|
||||||
|
/// Non copyable.
|
||||||
stack (const stack&);
|
stack (const stack&);
|
||||||
|
/// Non copyable.
|
||||||
stack& operator= (const stack&);
|
stack& operator= (const stack&);
|
||||||
|
#endif
|
||||||
/// The wrapped container.
|
/// The wrapped container.
|
||||||
S seq_;
|
S seq_;
|
||||||
};
|
};
|
||||||
|
@ -737,24 +981,21 @@ namespace ccl { namespace rslang { namespace detail {
|
||||||
/// Constants.
|
/// Constants.
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
yyeof_ = 0,
|
|
||||||
yylast_ = 589, ///< Last index in yytable_.
|
yylast_ = 589, ///< Last index in yytable_.
|
||||||
yynnts_ = 41, ///< Number of nonterminal symbols.
|
yynnts_ = 41, ///< Number of nonterminal symbols.
|
||||||
yyfinal_ = 85, ///< Termination state number.
|
yyfinal_ = 85 ///< Termination state number.
|
||||||
yyterror_ = 1,
|
|
||||||
yyerrcode_ = 256,
|
|
||||||
yyntokens_ = 61 ///< Number of tokens.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// User arguments.
|
// User arguments.
|
||||||
ParserState* state;
|
ParserState* state;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#line 11 "RSParserImpl.y" // lalr1.cc:401
|
#line 15 "RSParserImpl.y"
|
||||||
} } } // ccl::rslang::detail
|
} } } // ccl::rslang::detail
|
||||||
#line 758 "../header/RSParserImpl.h" // lalr1.cc:401
|
#line 999 "../header/RSParserImpl.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ private:
|
||||||
uint32_t counter{ 0 };
|
uint32_t counter{ 0 };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Iterator(const SDDecartian& decartaian, bool isCompleted = false);
|
explicit Iterator(const SDDecartian& base, bool isCompleted = false);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using iterator_category = std::forward_iterator_tag;
|
using iterator_category = std::forward_iterator_tag;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "ccl/rslang/RSErrorCodes.hpp"
|
#include "ccl/rslang/RSErrorCodes.hpp"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace ccl::rslang::detail {
|
namespace ccl::rslang::detail {
|
||||||
|
|
||||||
|
@ -18,6 +19,8 @@ struct Node {
|
||||||
public:
|
public:
|
||||||
explicit Node(Token token) noexcept
|
explicit Node(Token token) noexcept
|
||||||
: token{ std::move(token) } {}
|
: token{ std::move(token) } {}
|
||||||
|
explicit Node(TokenID id, StrRange pos, TokenData val = {}) noexcept
|
||||||
|
: Node(Token(id, pos, std::move(val))) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParserState {
|
struct ParserState {
|
||||||
|
|
|
@ -14,7 +14,7 @@ enum class LexerEID : uint32_t {
|
||||||
//! Syntactic errors enumeration
|
//! Syntactic errors enumeration
|
||||||
enum class ParseEID : uint32_t {
|
enum class ParseEID : uint32_t {
|
||||||
syntax = 0x8400, // Неизвестная синтаксическая ошибка
|
syntax = 0x8400, // Неизвестная синтаксическая ошибка
|
||||||
missingParanthesis = 0x8406, // Пропущена скобка ')'
|
missingParenthesis = 0x8406, // Пропущена скобка ')'
|
||||||
missingCurlyBrace = 0x8407, // Пропущена скобка '}'
|
missingCurlyBrace = 0x8407, // Пропущена скобка '}'
|
||||||
invalidQuantifier = 0x8408, // Некорректная кванторная декларация
|
invalidQuantifier = 0x8408, // Некорректная кванторная декларация
|
||||||
expectedDeclaration = 0x8414, // Ожидалось объявление аргументов
|
expectedDeclaration = 0x8414, // Ожидалось объявление аргументов
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "ccl/rslang/Interpreter.h"
|
#include "ccl/rslang/Interpreter.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace ccl::rslang {
|
namespace ccl::rslang {
|
||||||
|
|
||||||
Interpreter::Interpreter(const TypeContext& types, SyntaxTreeContext ast, DataContext data)
|
Interpreter::Interpreter(const TypeContext& types, SyntaxTreeContext ast, DataContext data)
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#pragma warning( disable : 26418 26415 26440 )
|
#pragma warning( disable : 26418 26415 26440 )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace ccl::rslang::detail {
|
namespace ccl::rslang::detail {
|
||||||
|
|
||||||
RSParser::RSParser(std::optional<ErrorReporter> reporter)
|
RSParser::RSParser(std::optional<ErrorReporter> reporter)
|
||||||
|
@ -58,15 +60,13 @@ int yylex(RawNode* yylval, ParserState* state) {
|
||||||
void RSParserImpl::error(const std::string& /*msg*/) {}
|
void RSParserImpl::error(const std::string& /*msg*/) {}
|
||||||
|
|
||||||
RawNode AddNode(const TokenID token, RawNode son) {
|
RawNode AddNode(const TokenID token, RawNode son) {
|
||||||
auto result = std::make_shared<Node>(Token(token, son->token.pos));
|
auto result = std::make_shared<Node>(token, son->token.pos);
|
||||||
|
|
||||||
result->children.emplace_back(son);
|
result->children.emplace_back(son);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode AddNode(const TokenID token, RawNode son1, RawNode son2) {
|
RawNode AddNode(const TokenID token, RawNode son1, RawNode son2) {
|
||||||
auto result = std::make_shared<Node>(
|
auto result = std::make_shared<Node>(token, StrRange{ son1->token.pos.start, son2->token.pos.finish });
|
||||||
Token{ token, StrRange{ son1->token.pos.start, son2->token.pos.finish } });
|
|
||||||
result->children.emplace_back(son1);
|
result->children.emplace_back(son1);
|
||||||
result->children.emplace_back(son2);
|
result->children.emplace_back(son2);
|
||||||
return result;
|
return result;
|
||||||
|
@ -87,19 +87,19 @@ RawNode UnaryOperation(RawNode operation, RawNode operand) {
|
||||||
|
|
||||||
RawNode RemoveBrackets(RawNode br1, RawNode operand, RawNode br2) {
|
RawNode RemoveBrackets(RawNode br1, RawNode operand, RawNode br2) {
|
||||||
operand->token.pos = StrRange{ br1->token.pos.start, br2->token.pos.finish };
|
operand->token.pos = StrRange{ br1->token.pos.start, br2->token.pos.finish };
|
||||||
auto bracketNode = std::make_shared<Node>(Token(TokenID::PUNC_PL, operand->token.pos));
|
auto bracketNode = std::make_shared<Node>(TokenID::PUNC_PL, operand->token.pos);
|
||||||
bracketNode->children.emplace_back(operand);
|
bracketNode->children.emplace_back(operand);
|
||||||
return bracketNode;
|
return bracketNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode ReplaceBrackets(const TokenID token, RawNode br1, RawNode argList, RawNode br2) {
|
RawNode ReplaceBrackets(const TokenID token, RawNode br1, RawNode argList, RawNode br2) {
|
||||||
auto result = std::make_shared<Node>(Token(token, StrRange{ br1->token.pos.start, br2->token.pos.finish }));
|
auto result = std::make_shared<Node>(token, StrRange{ br1->token.pos.start, br2->token.pos.finish });
|
||||||
result->children = argList->children;
|
result->children = argList->children;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode Enumeration(const TokenID token, RawNode el1, RawNode el2) {
|
RawNode Enumeration(const TokenID token, RawNode el1, RawNode el2) {
|
||||||
auto result = std::make_shared<Node>(Token(token, StrRange{ el1->token.pos.start, el2->token.pos.finish }));
|
auto result = std::make_shared<Node>(token, StrRange{ el1->token.pos.start, el2->token.pos.finish });
|
||||||
if (el1->token.id != token) {
|
if (el1->token.id != token) {
|
||||||
result->children.emplace_back(el1);
|
result->children.emplace_back(el1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -121,19 +121,27 @@ RawNode Quantifier(RawNode quant, RawNode declaration, RawNode domain, RawNode p
|
||||||
return quant;
|
return quant;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode FunctionDeclaration(RawNode start, RawNode argdecl, RawNode expr) {
|
RawNode FunctionDeclaration(RawNode start, RawNode argumentsDeclaration, RawNode expr) {
|
||||||
auto result = std::make_shared<Node>(
|
auto result = std::make_shared<Node>(
|
||||||
Token{ TokenID::NT_FUNC_DEFINITION, StrRange{ start->token.pos.start, expr->token.pos.finish } });
|
TokenID::NT_FUNC_DEFINITION,
|
||||||
result->children.emplace_back(argdecl);
|
StrRange{ start->token.pos.start, expr->token.pos.finish }
|
||||||
|
);
|
||||||
|
result->children.emplace_back(argumentsDeclaration);
|
||||||
result->children.emplace_back(expr);
|
result->children.emplace_back(expr);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode FunctionCall(RawNode function, RawNode args, RawNode rs) {
|
RawNode FunctionCall(RawNode function, RawNode args, RawNode rs) {
|
||||||
auto result = std::make_shared<Node>(
|
auto result = std::make_shared<Node>(
|
||||||
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.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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,48 +152,71 @@ RawNode FilterCall(RawNode filter, RawNode params, RawNode argument, RawNode rp)
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode TextOperator(RawNode oper, RawNode args, RawNode rp) {
|
RawNode TextOperator(RawNode operatorName, RawNode args, RawNode rp) {
|
||||||
oper->token.pos.finish = rp->token.pos.finish;
|
operatorName->token.pos.finish = rp->token.pos.finish;
|
||||||
oper->children.emplace_back(args);
|
operatorName->children.emplace_back(args);
|
||||||
return oper;
|
return operatorName;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode Decartian(RawNode op1, RawNode decart, RawNode op2) {
|
RawNode Decartian(RawNode op1, RawNode decartian, RawNode op2) {
|
||||||
if (op1->token.id == TokenID::DECART) {
|
if (op1->token.id == TokenID::DECART) {
|
||||||
auto result = std::move(op1);
|
auto result = std::move(op1);
|
||||||
result->token.pos.finish = op2->token.pos.finish;
|
result->token.pos.finish = op2->token.pos.finish;
|
||||||
result->children.emplace_back(op2);
|
result->children.emplace_back(op2);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} 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<Node>(
|
auto result = std::make_shared<Node>(
|
||||||
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(declaration);
|
||||||
result->children.emplace_back(domain);
|
result->children.emplace_back(domain);
|
||||||
result->children.emplace_back(predicate);
|
result->children.emplace_back(predicate);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode FullRecursion(RawNode rec, RawNode localid,
|
RawNode FullRecursion(
|
||||||
RawNode domain, RawNode condition, RawNode iteration, RawNode rc) {
|
RawNode rec,
|
||||||
|
RawNode declaration,
|
||||||
|
RawNode domain,
|
||||||
|
RawNode condition,
|
||||||
|
RawNode iteration,
|
||||||
|
RawNode rc
|
||||||
|
) {
|
||||||
auto result = std::make_shared<Node>(
|
auto result = std::make_shared<Node>(
|
||||||
Token{ TokenID::NT_RECURSIVE_FULL, StrRange{ rec->token.pos.start, rc->token.pos.finish } });
|
TokenID::NT_RECURSIVE_FULL,
|
||||||
result->children.emplace_back(localid);
|
StrRange{ rec->token.pos.start, rc->token.pos.finish }
|
||||||
|
);
|
||||||
|
result->children.emplace_back(declaration);
|
||||||
result->children.emplace_back(domain);
|
result->children.emplace_back(domain);
|
||||||
result->children.emplace_back(condition);
|
result->children.emplace_back(condition);
|
||||||
result->children.emplace_back(iteration);
|
result->children.emplace_back(iteration);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawNode ShortRecursion(RawNode rec, RawNode localid,
|
RawNode ShortRecursion(
|
||||||
RawNode domain, RawNode iteration, RawNode rc) {
|
RawNode rec,
|
||||||
|
RawNode declaration,
|
||||||
|
RawNode domain,
|
||||||
|
RawNode iteration,
|
||||||
|
RawNode rc
|
||||||
|
) {
|
||||||
auto result = std::make_shared<Node>(
|
auto result = std::make_shared<Node>(
|
||||||
Token{ TokenID::NT_RECURSIVE_SHORT, StrRange{ rec->token.pos.start, rc->token.pos.finish } });
|
TokenID::NT_RECURSIVE_SHORT,
|
||||||
result->children.emplace_back(localid);
|
StrRange{ rec->token.pos.start, rc->token.pos.finish }
|
||||||
|
);
|
||||||
|
result->children.emplace_back(declaration);
|
||||||
result->children.emplace_back(domain);
|
result->children.emplace_back(domain);
|
||||||
result->children.emplace_back(iteration);
|
result->children.emplace_back(iteration);
|
||||||
return result;
|
return result;
|
||||||
|
@ -193,7 +224,9 @@ RawNode ShortRecursion(RawNode rec, RawNode localid,
|
||||||
|
|
||||||
RawNode Imperative(RawNode imp, RawNode value, RawNode actions, RawNode rc) {
|
RawNode Imperative(RawNode imp, RawNode value, RawNode actions, RawNode rc) {
|
||||||
auto result = std::make_shared<Node>(
|
auto result = std::make_shared<Node>(
|
||||||
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.emplace_back(value);
|
||||||
result->children.insert(end(result->children), begin(actions->children), end(actions->children));
|
result->children.insert(end(result->children), begin(actions->children), end(actions->children));
|
||||||
return result;
|
return result;
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,8 @@
|
||||||
%require "3.2"
|
%require "3.7"
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// ------------- Generator Definitions --------------------
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
%output "RSParserImpl.cpp"
|
%output "RSParserImpl.cpp"
|
||||||
%defines "../header/RSParserImpl.h"
|
%defines "../header/RSParserImpl.h"
|
||||||
|
@ -13,10 +17,14 @@
|
||||||
%define api.parser.class {RSParserImpl}
|
%define api.parser.class {RSParserImpl}
|
||||||
%param {ParserState* state}
|
%param {ParserState* state}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// ------------- Code Wrapper at FileStart ----------------
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
%code top {
|
%code top {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#pragma warning( push )
|
#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 )
|
#pragma warning( disable : 26460 26477 26481 26482 26493 26494 26495 26496 )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -33,6 +41,10 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
// ------------- Semantic Actions -------------------------
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
%code requires{
|
%code requires{
|
||||||
#include "ccl/rslang/SyntaxTree.h"
|
#include "ccl/rslang/SyntaxTree.h"
|
||||||
#include "ccl/rslang/ParserState.hpp"
|
#include "ccl/rslang/ParserState.hpp"
|
||||||
|
@ -42,292 +54,435 @@ namespace ccl::rslang::detail {
|
||||||
#define YYSTYPE RawNode
|
#define YYSTYPE RawNode
|
||||||
struct ParserState;
|
struct ParserState;
|
||||||
|
|
||||||
|
int yylex(RawNode* yylval, ParserState* state);
|
||||||
|
|
||||||
RawNode AddNode(TokenID token, RawNode son);
|
RawNode AddNode(TokenID token, RawNode son);
|
||||||
RawNode AddNode(TokenID token, RawNode son1, RawNode son2);
|
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 RemoveBrackets(RawNode br1, RawNode operand, RawNode br2);
|
||||||
RawNode ReplaceBrackets(TokenID token, RawNode br1, RawNode argList, 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 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 Decartian(
|
||||||
RawNode FunctionDeclaration(RawNode start, RawNode argdecl, RawNode expr);
|
RawNode op1,
|
||||||
RawNode FunctionCall(RawNode function, RawNode args, RawNode rs);
|
RawNode decartian,
|
||||||
RawNode FilterCall(RawNode filter, RawNode params, RawNode argument, RawNode rp);
|
RawNode op2
|
||||||
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);
|
|
||||||
|
|
||||||
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
|
} // namespace ccl::rslang::detail
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------- Идентификаторы -----------------------------------
|
|
||||||
%token LOCAL // Имя локальной переменной
|
|
||||||
GLOBAL // Имя глобальной переменной
|
|
||||||
FUNCTION // Терм-функция
|
|
||||||
PREDICATE // Пердикат-функция
|
|
||||||
RADICAL // Радикал для шаблонов функций и предикатов
|
|
||||||
INTEGER
|
|
||||||
INFINITY
|
|
||||||
EMPTYSET
|
|
||||||
|
|
||||||
//------------------ Арифметика ------------------------------
|
///////////////////////////////////////////////////////////
|
||||||
%left PLUS MINUS
|
// ------------- Terminal Tokens --------------------------
|
||||||
%left MULTIPLY
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// ----------- Целочисленные предикаты -----------------------
|
// ------------- Identifiers ------------------------------
|
||||||
%token GREATER
|
%token
|
||||||
LESSER
|
LOCAL // Local identifier
|
||||||
GREATER_OR_EQ
|
GLOBAL // Global identifier
|
||||||
LESSER_OR_EQ
|
FUNCTION // Term-function
|
||||||
|
PREDICATE // Predicate-function
|
||||||
// --------------- Сравнение ---------------------------------
|
RADICAL // Templated argument identifier
|
||||||
%token EQUAL
|
INTEGER // Integer literal
|
||||||
NOTEQUAL
|
INTSET // Set of all integers
|
||||||
|
EMPTYSET // Empty set
|
||||||
//------------- Логические предикаты ------------------------
|
|
||||||
%token FORALL // Квантор всеобщности
|
|
||||||
EXISTS // Квантор существования
|
// ------------- Arithmetic operations --------------------
|
||||||
%right NOT
|
%left PLUS MINUS // Add and Subtract
|
||||||
%left EQUIVALENT
|
%left MULTIPLY // Multiply
|
||||||
%left IMPLICATION
|
|
||||||
%left OR
|
|
||||||
%left AND
|
// ------------- Integer predicates -----------------------
|
||||||
|
%token
|
||||||
//-------------- Предикаты теории множеств -------------------
|
GREATER // IsGreater
|
||||||
%token IN
|
LESSER // IsLesser
|
||||||
NOTIN
|
GREATER_OR_EQ // IsGreater or IsEqual
|
||||||
SUBSET
|
LESSER_OR_EQ // IsLesser or IsEqual
|
||||||
SUBOR_EQ
|
|
||||||
NOTSUBSET
|
|
||||||
|
// ------------- Equality predicate -----------------------
|
||||||
//-------------- Операции теории множеств -------------------
|
%token
|
||||||
%left DECART UNION INTERSECTION SET_MINUS SYMMINUS
|
EQUAL // IsEqual
|
||||||
%right BOOLEAN // Булеан
|
NOTEQUAL // NotEqual
|
||||||
|
|
||||||
//------------------ Родоструктурные операции -------------------
|
|
||||||
%token BIGPR // Большая проекция
|
// ------------- First order logic ------------------------
|
||||||
SMALLPR // Малая проекция
|
%token
|
||||||
FILTER // Фильтр
|
FORALL // UniversalQuantifier
|
||||||
CARD // Кардинальность (мощность множества)
|
EXISTS // ExistentialQuantifier
|
||||||
BOOL // синглетон
|
|
||||||
DEBOOL // десинглетон
|
%right
|
||||||
RED // reduce (множество-сумма)
|
NOT // Negation
|
||||||
|
|
||||||
//------------------ Родоструктурные конструкции -------------------
|
%left
|
||||||
%token DECLARATIVE // выражение терма
|
EQUIVALENT // IsEquivalent
|
||||||
RECURSIVE // рекурсивное определение
|
|
||||||
IMPERATIVE // императивное определение
|
%left
|
||||||
|
IMPLICATION // Implies
|
||||||
//-------------- Пунктуация ---------------------------------
|
|
||||||
%token DEFINE // Определение глобального идентификатора
|
%left
|
||||||
STRUCT // Определение глобальной структуры
|
OR // LogicDisjunction
|
||||||
ASSIGN // Знак присвоения
|
|
||||||
ITERATE // Знак перебора
|
%left
|
||||||
LP // Открывающая круглая скобка
|
AND // LogicConjunction
|
||||||
RP // Закрывающая круглая скобка
|
|
||||||
LC // Открывающая фигурная скобка
|
|
||||||
RC // Закрывающая фигурная скобка
|
// ------------- Set theory predicates --------------------
|
||||||
LS // Открывающая квадратная скобка
|
%token
|
||||||
RS // Закрывающая квадратная скобка
|
IN // IsElement
|
||||||
BAR // Вертикальная черта
|
NOTIN // NotElement
|
||||||
%left COMMA // Запятая
|
SUBSET // IsSubset and NotEqual
|
||||||
%left SEMICOLON // Точка с запятой
|
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 ------------------------------------
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//--------------- Выражение ------------------------------
|
// ------------------------- Language Expression ------------------------------
|
||||||
expression : global_declaration
|
expression
|
||||||
| term_or_logic { state->FinalizeExpression($1); }
|
: global_declaration
|
||||||
| function_decl { state->FinalizeExpression($1); }
|
| logic_or_setexpr { state->FinalizeExpression($1); }
|
||||||
;
|
| function_decl { state->FinalizeExpression($1); }
|
||||||
|
;
|
||||||
|
|
||||||
term_or_logic : logic
|
global_declaration
|
||||||
| term
|
: 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); }
|
logic_or_setexpr
|
||||||
| LS error { state->OnError(ParseEID::expectedDeclaration); YYABORT; }
|
: logic
|
||||||
;
|
| setexpr
|
||||||
|
;
|
||||||
|
|
||||||
arg_declaration : declaration { $$ = AddNode(TokenID::NT_ARGUMENTS, $1); }
|
function_decl
|
||||||
| arg_declaration COMMA declaration { $$ = Enumeration(TokenID::NT_ARGUMENTS, $1, $3); }
|
: LS arguments RS logic_or_setexpr { $$ = FunctionDeclaration($1, $2, $4); }
|
||||||
| arg_declaration COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; }
|
| LS error { state->OnError(ParseEID::expectedDeclaration); YYABORT; }
|
||||||
;
|
;
|
||||||
declaration : LOCAL IN term { $$ = AddNode(TokenID::NT_ARG_DECL, $1, $3); }
|
|
||||||
| LOCAL error { state->OnError(ParseEID::expectedDeclaration); YYABORT; }
|
|
||||||
;
|
|
||||||
|
|
||||||
//--------------- Выражение конституэнты ------------------------------
|
// ------------------------- Variables and arguments -------------------------
|
||||||
global_declaration : GLOBAL DEFINE { state->FinalizeCstEmpty($1, $2); }
|
arguments
|
||||||
| GLOBAL STRUCT term { state->FinalizeCstExpression($1, $2, $3); }
|
: declaration { $$ = AddNode(TokenID::NT_ARGUMENTS, $1); }
|
||||||
| GLOBAL DEFINE term_or_logic { state->FinalizeCstExpression($1, $2, $3); }
|
| arguments COMMA declaration { $$ = Enumeration(TokenID::NT_ARGUMENTS, $1, $3); }
|
||||||
| function_name DEFINE function_decl { state->FinalizeCstExpression($1, $2, $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; }
|
||||||
|
;
|
||||||
|
|
||||||
//--------------- Логическое выражение -----------------------------------------
|
variable
|
||||||
logic : logic_predicates
|
: LOCAL
|
||||||
| logic_unary
|
| LP var_enum RPE { $$ = ReplaceBrackets(TokenID::NT_TUPLE_DECL, $1, $2, $3); }
|
||||||
| logic_binary
|
;
|
||||||
;
|
var_enum
|
||||||
logic_all : logic
|
: var_all COMMA var_all { $$ = Enumeration(TokenID::INTERRUPT, $1, $3); }
|
||||||
| logic_par
|
| var_all COMMA error { state->OnError(ParseEID::expectedLocal); YYABORT; }
|
||||||
;
|
;
|
||||||
logic_no_binary: logic_predicates
|
var_all
|
||||||
| logic_unary
|
: variable
|
||||||
| logic_par
|
| var_enum
|
||||||
;
|
;
|
||||||
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; }
|
|
||||||
;
|
|
||||||
|
|
||||||
//-------------------- Термы РС -------------------------------------
|
// ------------------------- Logic Expressions --------------------------------
|
||||||
term : literal
|
logic
|
||||||
| identifier
|
: logic_predicates
|
||||||
| binary_operation
|
| logic_unary
|
||||||
| typed_constructors
|
| logic_binary
|
||||||
| FUNCTION LS term_enum RS { $$ = FunctionCall($1, $3, $4); }
|
;
|
||||||
| operation_name LP term RPE { $$ = TextOperator($1, $3, $4); }
|
logic_all
|
||||||
;
|
: logic
|
||||||
//--------------- Двухместная операция ------------------------------
|
| logic_par
|
||||||
binary_operation: term PLUS term { $$ = BinaryOperation($1, $2, $3); }
|
;
|
||||||
| term MINUS term { $$ = BinaryOperation($1, $2, $3); }
|
logic_par
|
||||||
| term MULTIPLY term { $$ = BinaryOperation($1, $2, $3); }
|
: LP logic_binary RPE { $$ = RemoveBrackets($1, $2, $3); }
|
||||||
| term UNION term { $$ = BinaryOperation($1, $2, $3); }
|
| LP logic_predicates RPE { $$ = RemoveBrackets($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_predicates
|
||||||
function_name : FUNCTION
|
: setexpr binary_predicate setexpr { $$ = BinaryOperation($1, $2, $3); }
|
||||||
| PREDICATE
|
;
|
||||||
;
|
binary_predicate
|
||||||
global_id : GLOBAL
|
: IN
|
||||||
| function_name
|
| NOTIN
|
||||||
| RADICAL
|
| SUBSET
|
||||||
;
|
| SUBOR_EQ
|
||||||
identifier : global_id
|
| NOTSUBSET
|
||||||
| LOCAL
|
| NOTEQUAL
|
||||||
;
|
| EQUAL
|
||||||
literal : INTEGER
|
| GREATER
|
||||||
| EMPTYSET
|
| LESSER
|
||||||
| INFINITY
|
| GREATER_OR_EQ
|
||||||
;
|
| LESSER_OR_EQ
|
||||||
//------------- Кванторы --------------------------
|
;
|
||||||
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_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
|
#ifdef _MSC_VER
|
||||||
|
|
|
@ -147,8 +147,8 @@ bool SDPowerSet::Contains(StructuredData element) const {
|
||||||
return element.B().IsSubsetOrEq(base.B());
|
return element.B().IsSubsetOrEq(base.B());
|
||||||
}
|
}
|
||||||
|
|
||||||
SDDecartian::Iterator::Iterator(const SDDecartian& decart, const bool completed)
|
SDDecartian::Iterator::Iterator(const SDDecartian& base, const bool completed)
|
||||||
: decartian{ &decart }, isCompleted{ completed || decartian->Cardinality() == 0 } {
|
: decartian{ &base }, isCompleted{ completed || base.Cardinality() == 0 } {
|
||||||
if (!isCompleted) {
|
if (!isCompleted) {
|
||||||
componentIters.reserve(size(decartian->factors));
|
componentIters.reserve(size(decartian->factors));
|
||||||
for (const auto& factor : decartian->factors) {
|
for (const auto& factor : decartian->factors) {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#include "ccl/rslang/SDataCompact.h"
|
#include "ccl/rslang/SDataCompact.h"
|
||||||
|
|
||||||
#include "ccl/rslang/RSToken.h"
|
#include "ccl/rslang/RSToken.h"
|
||||||
|
#include "ccl/rslang/Typification.h"
|
||||||
|
#include "ccl/rslang/StructuredData.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace ccl::object {
|
namespace ccl::object {
|
||||||
|
|
||||||
|
|
|
@ -309,20 +309,20 @@ TEST_F(UTStructuredData, SetProjection) {
|
||||||
TEST_F(UTStructuredData, DecartianCreate) {
|
TEST_F(UTStructuredData, DecartianCreate) {
|
||||||
const auto bSet1 = Factory::Set({ el1, el2 });
|
const auto bSet1 = Factory::Set({ el1, el2 });
|
||||||
const auto bSet2 = Factory::Set({ el1, el2, el3 });
|
const auto bSet2 = Factory::Set({ el1, el2, el3 });
|
||||||
const auto decart = Factory::Decartian({ bSet1, bSet2 });
|
const auto decartian = Factory::Decartian({ bSet1, bSet2 });
|
||||||
EXPECT_TRUE(decart.IsCollection());
|
EXPECT_TRUE(decartian.IsCollection());
|
||||||
EXPECT_TRUE(std::begin(decart.B())->IsTuple());
|
EXPECT_TRUE(std::begin(decartian.B())->IsTuple());
|
||||||
EXPECT_EQ(bSet1.B().Cardinality() * bSet2.B().Cardinality(), decart.B().Cardinality());
|
EXPECT_EQ(bSet1.B().Cardinality() * bSet2.B().Cardinality(), decartian.B().Cardinality());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UTStructuredData, DecartianAddElement) {
|
TEST_F(UTStructuredData, DecartianAddElement) {
|
||||||
const auto bSet1 = Factory::Set({ el1 });
|
const auto bSet1 = Factory::Set({ el1 });
|
||||||
const auto bSet2 = Factory::Set({ el1 });
|
const auto bSet2 = Factory::Set({ el1 });
|
||||||
auto decart = Factory::Decartian({ bSet1, bSet2 });
|
auto decartian = Factory::Decartian({ bSet1, bSet2 });
|
||||||
EXPECT_FALSE(decart.ModifyB().AddElement(Factory::Set({ el1 })));
|
EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::Set({ el1 })));
|
||||||
EXPECT_FALSE(decart.ModifyB().AddElement(Factory::Tuple({ el1, el1 })));
|
EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::Tuple({ el1, el1 })));
|
||||||
EXPECT_FALSE(decart.ModifyB().AddElement(Factory::Tuple({ el1, el2 })));
|
EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::Tuple({ el1, el2 })));
|
||||||
EXPECT_FALSE(decart.ModifyB().AddElement(Factory::EmptySet()));
|
EXPECT_FALSE(decartian.ModifyB().AddElement(Factory::EmptySet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UTStructuredData, DecartianEmpty) {
|
TEST_F(UTStructuredData, DecartianEmpty) {
|
||||||
|
@ -334,29 +334,29 @@ TEST_F(UTStructuredData, DecartianEmpty) {
|
||||||
TEST_F(UTStructuredData, DecartianAsymmetry) {
|
TEST_F(UTStructuredData, DecartianAsymmetry) {
|
||||||
const auto bSet1 = Factory::Singleton(el1);
|
const auto bSet1 = Factory::Singleton(el1);
|
||||||
const auto bSet2 = Factory::Singleton(el3);
|
const auto bSet2 = Factory::Singleton(el3);
|
||||||
const auto decart12 = Factory::Decartian({ bSet1, bSet2 });
|
const auto decartian12 = Factory::Decartian({ bSet1, bSet2 });
|
||||||
const auto decart21 = Factory::Decartian({ bSet2, bSet1 });
|
const auto decartian21 = Factory::Decartian({ bSet2, bSet1 });
|
||||||
EXPECT_NE(decart12, decart21);
|
EXPECT_NE(decartian12, decartian21);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UTStructuredData, DecartianContains) {
|
TEST_F(UTStructuredData, DecartianContains) {
|
||||||
const auto bSet1 = Factory::Set({ el1, el2 });
|
const auto bSet1 = Factory::Set({ el1, el2 });
|
||||||
const auto bSet2 = Factory::Set({ el1, el2, el3 });
|
const auto bSet2 = Factory::Set({ el1, el2, el3 });
|
||||||
const auto decart = Factory::Decartian({ bSet1, bSet2 });
|
const auto decartian = Factory::Decartian({ bSet1, bSet2 });
|
||||||
EXPECT_TRUE(decart.B().Contains(Factory::Tuple({ el1, el3 })));
|
EXPECT_TRUE(decartian.B().Contains(Factory::Tuple({ el1, el3 })));
|
||||||
EXPECT_FALSE(decart.B().Contains(Factory::Tuple({ el3, el3 })));
|
EXPECT_FALSE(decartian.B().Contains(Factory::Tuple({ el3, el3 })));
|
||||||
EXPECT_FALSE(decart.B().Contains(Factory::Tuple({ el1, el3, el3 })));
|
EXPECT_FALSE(decartian.B().Contains(Factory::Tuple({ el1, el3, el3 })));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UTStructuredData, DecartianIteration) {
|
TEST_F(UTStructuredData, DecartianIteration) {
|
||||||
const auto bSet1 = Factory::Set({ el1, el2 });
|
const auto bSet1 = Factory::Set({ el1, el2 });
|
||||||
const auto bSet2 = Factory::Set({ el1, el2, el3 });
|
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<StructuredData>{};
|
auto elements = std::set<StructuredData>{};
|
||||||
for (const auto& el : decart.B()) {
|
for (const auto& el : decartian.B()) {
|
||||||
elements.insert(el);
|
elements.insert(el);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(decart.B().Cardinality(), ssize(elements));
|
EXPECT_EQ(decartian.B().Cardinality(), ssize(elements));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(UTStructuredData, BooleanCreate) {
|
TEST_F(UTStructuredData, BooleanCreate) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Generate lexers for RSlang
|
# 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"
|
$workDir = Resolve-Path -Path "${PSScriptRoot}\..\ccl\rslang\src"
|
||||||
$grammar = 'RSParserImpl.y'
|
$grammar = 'RSParserImpl.y'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user