diff --git a/include/autoq/parsing/ExtendedDirac/EvaluationVisitor.h b/include/autoq/parsing/ExtendedDirac/EvaluationVisitor.h new file mode 100644 index 000000000..4b5b89d3c --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/EvaluationVisitor.h @@ -0,0 +1,109 @@ + +#include "ExtendedDiracBaseVisitor.h" +#include "ExtendedDiracParser.h" + +#include "autoq/aut_description.hh" +#include "autoq/symbol/concrete.hh" +#include "autoq/complex/complex.hh" + +// Thanks to https://github.com/boostorg/multiprecision/issues/297 +boost::multiprecision::cpp_int bin_2_dec2(const std::string_view& num) +{ + boost::multiprecision::cpp_int dec_value = 0; + auto cptr = num.data(); + long long len = num.size(); + // check if big enough to have 0b postfix + if (num.size() > 2) { + // check if 2nd character is the 'b' binary postfix + // skip over it & adjust length accordingly if it is + if (num[1] == 'b' || num[1] == 'B') { + cptr += 2; + len -= 2; + } + } + // change i's type to cpp_int if the number of digits is greater + // than std::numeric_limits::max() + for (long long i = len - 1; 0 <= i; ++cptr, --i) { + if (*cptr == '1') { + boost::multiprecision::bit_set(/*.val = */ dec_value, /*.pos = */ i); + } + } + return dec_value; +} + +template +class EvaluationVisitor : public ExtendedDiracBaseVisitor { +public: + std::map constants; + std::map predicates; + EvaluationVisitor(const std::map &constants, const std::map &predicates) : constants(constants), predicates(predicates) {} + + std::any visitExtendedDirac(ExtendedDiracParser::ExtendedDiracContext *ctx) override { + if (ctx->set().size() == 1) { // RULE: set + return visit(ctx->set(0)); + } else { // RULE: set '\\' set + // TODO: + /* + auto left = visit(ctx->set(0)); // Left operand + auto right = visit(ctx->set(1)); // Right operand + return visit(ctx->set(0)); //std::make_pair(left, right); + */ + return {}; + } + } + + std::any visitSet(ExtendedDiracParser::SetContext *ctx) override { + if (ctx->n != nullptr) { // RULE: set '^' n + int times = std::stoi(ctx->n->getText()); + if (times == 1) { + return visit(ctx->set(0)); + } else { // if (times > 1) { + auto lsta = std::any_cast>(visit(ctx->set(0))); + auto result = lsta; + while ((--times) > 0) { + result = result * lsta; // TODO: implement *= + } + return result; + } + } else if (ctx->op == nullptr) { + if (!ctx->set().empty()) { // RULE: '(' set ')' + return visit(ctx->set(0)); + } else if (ctx->diracs() != nullptr) { // RULE: '{' diracs '}' + return visit(ctx->diracs()); + } else { // if (ctx->dirac() != nullptr && ctx->ijklens() != nullptr) { // RULE: '{' dirac '|' ijklens '}' + // TODO + /**/ + return {}; + } + } else if (ctx->op->getType() == ExtendedDiracParser::PROD) { // RULE: set op=PROD set + return std::any_cast>(visit(ctx->set(0))) * std::any_cast>(visit(ctx->set(1))); + } else if (ctx->op->getType() == ExtendedDiracParser::UNION) { // RULE: set op=UNION set + return std::any_cast>(visit(ctx->set(0))) || std::any_cast>(visit(ctx->set(1))); + } else { // if (ctx->op->getType() == ExtendedDiracParser::INTERSECTION) { // RULE: set op=INTERSECTION set + // TODO: implement && + /**/ + return {}; + } + } + + std::any visitDiracs(ExtendedDiracParser::DiracsContext *ctx) override { + if (ctx->diracs() == nullptr) { // RULE: dirac + return visit(ctx->dirac()); + } else { // RULE: diracs ',' dirac + return std::any_cast>(visit(ctx->diracs())) || std::any_cast>(visit(ctx->dirac())); + } + } + + std::any visitDirac(ExtendedDiracParser::DiracContext *ctx) override { + bool dummy; + return from_tree_to_automaton(ctx->getText(), constants, predicates, dummy); + } + + // std::any visitIjklens(ExtendedDiracParser::IjklensContext *ctx) override { + // return visitChildren(ctx); + // } + + // std::any visitIjklen(ExtendedDiracParser::IjklenContext *ctx) override { + // return visitChildren(ctx); + // } +}; diff --git a/include/autoq/parsing/ExtendedDirac/ExtendedDiracBaseListener.h b/include/autoq/parsing/ExtendedDirac/ExtendedDiracBaseListener.h new file mode 100644 index 000000000..f7f2190f7 --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/ExtendedDiracBaseListener.h @@ -0,0 +1,53 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" +#include "ExtendedDiracListener.h" + + +/** + * This class provides an empty implementation of ExtendedDiracListener, + * which can be extended to create a listener which only needs to handle a subset + * of the available methods. + */ +class ExtendedDiracBaseListener : public ExtendedDiracListener { +public: + + virtual void enterExtendedDirac(ExtendedDiracParser::ExtendedDiracContext * /*ctx*/) override { } + virtual void exitExtendedDirac(ExtendedDiracParser::ExtendedDiracContext * /*ctx*/) override { } + + virtual void enterSet(ExtendedDiracParser::SetContext * /*ctx*/) override { } + virtual void exitSet(ExtendedDiracParser::SetContext * /*ctx*/) override { } + + virtual void enterDiracs(ExtendedDiracParser::DiracsContext * /*ctx*/) override { } + virtual void exitDiracs(ExtendedDiracParser::DiracsContext * /*ctx*/) override { } + + virtual void enterDirac(ExtendedDiracParser::DiracContext * /*ctx*/) override { } + virtual void exitDirac(ExtendedDiracParser::DiracContext * /*ctx*/) override { } + + virtual void enterCket(ExtendedDiracParser::CketContext * /*ctx*/) override { } + virtual void exitCket(ExtendedDiracParser::CketContext * /*ctx*/) override { } + + virtual void enterComplex(ExtendedDiracParser::ComplexContext * /*ctx*/) override { } + virtual void exitComplex(ExtendedDiracParser::ComplexContext * /*ctx*/) override { } + + virtual void enterAngle(ExtendedDiracParser::AngleContext * /*ctx*/) override { } + virtual void exitAngle(ExtendedDiracParser::AngleContext * /*ctx*/) override { } + + virtual void enterIjklens(ExtendedDiracParser::IjklensContext * /*ctx*/) override { } + virtual void exitIjklens(ExtendedDiracParser::IjklensContext * /*ctx*/) override { } + + virtual void enterIjklen(ExtendedDiracParser::IjklenContext * /*ctx*/) override { } + virtual void exitIjklen(ExtendedDiracParser::IjklenContext * /*ctx*/) override { } + + + virtual void enterEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { } + virtual void exitEveryRule(antlr4::ParserRuleContext * /*ctx*/) override { } + virtual void visitTerminal(antlr4::tree::TerminalNode * /*node*/) override { } + virtual void visitErrorNode(antlr4::tree::ErrorNode * /*node*/) override { } + +}; + diff --git a/include/autoq/parsing/ExtendedDirac/ExtendedDiracBaseVisitor.h b/include/autoq/parsing/ExtendedDirac/ExtendedDiracBaseVisitor.h new file mode 100644 index 000000000..941f199af --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/ExtendedDiracBaseVisitor.h @@ -0,0 +1,56 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" +#include "ExtendedDiracVisitor.h" + + +/** + * This class provides an empty implementation of ExtendedDiracVisitor, which can be + * extended to create a visitor which only needs to handle a subset of the available methods. + */ +class ExtendedDiracBaseVisitor : public ExtendedDiracVisitor { +public: + + virtual std::any visitExtendedDirac(ExtendedDiracParser::ExtendedDiracContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitSet(ExtendedDiracParser::SetContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitDiracs(ExtendedDiracParser::DiracsContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitDirac(ExtendedDiracParser::DiracContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitCket(ExtendedDiracParser::CketContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitComplex(ExtendedDiracParser::ComplexContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitAngle(ExtendedDiracParser::AngleContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitIjklens(ExtendedDiracParser::IjklensContext *ctx) override { + return visitChildren(ctx); + } + + virtual std::any visitIjklen(ExtendedDiracParser::IjklenContext *ctx) override { + return visitChildren(ctx); + } + + +}; + diff --git a/include/autoq/parsing/ExtendedDirac/ExtendedDiracLexer.h b/include/autoq/parsing/ExtendedDirac/ExtendedDiracLexer.h new file mode 100644 index 000000000..abcd70f41 --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/ExtendedDiracLexer.h @@ -0,0 +1,52 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" + + + + +class ExtendedDiracLexer : public antlr4::Lexer { +public: + enum { + T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, + T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, ADD = 13, DIV = 14, + DIGITS = 15, INTERSECTION = 16, KET = 17, MUL = 18, NAME = 19, PROD = 20, + SUB = 21, UNION = 22, WS = 23 + }; + + explicit ExtendedDiracLexer(antlr4::CharStream *input); + + ~ExtendedDiracLexer() override; + + + std::string getGrammarFileName() const override; + + const std::vector& getRuleNames() const override; + + const std::vector& getChannelNames() const override; + + const std::vector& getModeNames() const override; + + const antlr4::dfa::Vocabulary& getVocabulary() const override; + + antlr4::atn::SerializedATNView getSerializedATN() const override; + + const antlr4::atn::ATN& getATN() const override; + + // By default the static state used to implement the lexer is lazily initialized during the first + // call to the constructor. You can call this function if you wish to initialize the static state + // ahead of time. + static void initialize(); + +private: + + // Individual action functions triggered by action() above. + + // Individual semantic predicate functions triggered by sempred() above. + +}; + diff --git a/include/autoq/parsing/ExtendedDirac/ExtendedDiracListener.h b/include/autoq/parsing/ExtendedDirac/ExtendedDiracListener.h new file mode 100644 index 000000000..6f688a445 --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/ExtendedDiracListener.h @@ -0,0 +1,46 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" +#include "ExtendedDiracParser.h" + + +/** + * This interface defines an abstract listener for a parse tree produced by ExtendedDiracParser. + */ +class ExtendedDiracListener : public antlr4::tree::ParseTreeListener { +public: + + virtual void enterExtendedDirac(ExtendedDiracParser::ExtendedDiracContext *ctx) = 0; + virtual void exitExtendedDirac(ExtendedDiracParser::ExtendedDiracContext *ctx) = 0; + + virtual void enterSet(ExtendedDiracParser::SetContext *ctx) = 0; + virtual void exitSet(ExtendedDiracParser::SetContext *ctx) = 0; + + virtual void enterDiracs(ExtendedDiracParser::DiracsContext *ctx) = 0; + virtual void exitDiracs(ExtendedDiracParser::DiracsContext *ctx) = 0; + + virtual void enterDirac(ExtendedDiracParser::DiracContext *ctx) = 0; + virtual void exitDirac(ExtendedDiracParser::DiracContext *ctx) = 0; + + virtual void enterCket(ExtendedDiracParser::CketContext *ctx) = 0; + virtual void exitCket(ExtendedDiracParser::CketContext *ctx) = 0; + + virtual void enterComplex(ExtendedDiracParser::ComplexContext *ctx) = 0; + virtual void exitComplex(ExtendedDiracParser::ComplexContext *ctx) = 0; + + virtual void enterAngle(ExtendedDiracParser::AngleContext *ctx) = 0; + virtual void exitAngle(ExtendedDiracParser::AngleContext *ctx) = 0; + + virtual void enterIjklens(ExtendedDiracParser::IjklensContext *ctx) = 0; + virtual void exitIjklens(ExtendedDiracParser::IjklensContext *ctx) = 0; + + virtual void enterIjklen(ExtendedDiracParser::IjklenContext *ctx) = 0; + virtual void exitIjklen(ExtendedDiracParser::IjklenContext *ctx) = 0; + + +}; + diff --git a/include/autoq/parsing/ExtendedDirac/ExtendedDiracParser.h b/include/autoq/parsing/ExtendedDirac/ExtendedDiracParser.h new file mode 100644 index 000000000..1fec5125b --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/ExtendedDiracParser.h @@ -0,0 +1,259 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" + + + + +class ExtendedDiracParser : public antlr4::Parser { +public: + enum { + T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, T__4 = 5, T__5 = 6, T__6 = 7, + T__7 = 8, T__8 = 9, T__9 = 10, T__10 = 11, T__11 = 12, ADD = 13, DIV = 14, + DIGITS = 15, INTERSECTION = 16, KET = 17, MUL = 18, NAME = 19, PROD = 20, + SUB = 21, UNION = 22, WS = 23 + }; + + enum { + RuleExtendedDirac = 0, RuleSet = 1, RuleDiracs = 2, RuleDirac = 3, RuleCket = 4, + RuleComplex = 5, RuleAngle = 6, RuleIjklens = 7, RuleIjklen = 8 + }; + + explicit ExtendedDiracParser(antlr4::TokenStream *input); + + ExtendedDiracParser(antlr4::TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options); + + ~ExtendedDiracParser() override; + + std::string getGrammarFileName() const override; + + const antlr4::atn::ATN& getATN() const override; + + const std::vector& getRuleNames() const override; + + const antlr4::dfa::Vocabulary& getVocabulary() const override; + + antlr4::atn::SerializedATNView getSerializedATN() const override; + + + bool isSymbolicAutomaton = false; + std::set predefinedVars; + + bool isNonZero(const std::string& text) { + return std::stoi(text) != 0; + } + bool isASingleLetter(const std::string& text) { + return text.length() == 1 && 'a' <= text.at(0) && text.at(0) <= 'z'; + } + + + class ExtendedDiracContext; + class SetContext; + class DiracsContext; + class DiracContext; + class CketContext; + class ComplexContext; + class AngleContext; + class IjklensContext; + class IjklenContext; + + class ExtendedDiracContext : public antlr4::ParserRuleContext { + public: + ExtendedDiracContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector set(); + SetContext* set(size_t i); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + ExtendedDiracContext* extendedDirac(); + + class SetContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *op = nullptr; + antlr4::Token *n = nullptr; + SetContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector set(); + SetContext* set(size_t i); + DiracsContext *diracs(); + DiracContext *dirac(); + IjklensContext *ijklens(); + antlr4::tree::TerminalNode *PROD(); + antlr4::tree::TerminalNode *UNION(); + antlr4::tree::TerminalNode *INTERSECTION(); + antlr4::tree::TerminalNode *DIGITS(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + SetContext* set(); + SetContext* set(int precedence); + class DiracsContext : public antlr4::ParserRuleContext { + public: + DiracsContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + DiracContext *dirac(); + DiracsContext *diracs(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + DiracsContext* diracs(); + DiracsContext* diracs(int precedence); + class DiracContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *op = nullptr; + DiracContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + CketContext *cket(); + DiracContext *dirac(); + antlr4::tree::TerminalNode *ADD(); + antlr4::tree::TerminalNode *SUB(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + DiracContext* dirac(); + DiracContext* dirac(int precedence); + class CketContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *op = nullptr; + antlr4::Token *ketToken = nullptr; + CketContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *KET(); + ComplexContext *complex(); + antlr4::tree::TerminalNode *SUB(); + antlr4::tree::TerminalNode *MUL(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + CketContext* cket(); + + class ComplexContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *var = nullptr; + antlr4::Token *op = nullptr; + antlr4::Token *n = nullptr; + ComplexContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + std::vector complex(); + ComplexContext* complex(size_t i); + antlr4::tree::TerminalNode *SUB(); + AngleContext *angle(); + antlr4::tree::TerminalNode *DIGITS(); + antlr4::tree::TerminalNode *NAME(); + antlr4::tree::TerminalNode *MUL(); + antlr4::tree::TerminalNode *DIV(); + antlr4::tree::TerminalNode *ADD(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + ComplexContext* complex(); + ComplexContext* complex(int precedence); + class AngleContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *x = nullptr; + antlr4::Token *y = nullptr; + antlr4::Token *n = nullptr; + AngleContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *DIV(); + std::vector DIGITS(); + antlr4::tree::TerminalNode* DIGITS(size_t i); + antlr4::tree::TerminalNode *SUB(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + AngleContext* angle(); + + class IjklensContext : public antlr4::ParserRuleContext { + public: + IjklensContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + IjklenContext *ijklen(); + IjklensContext *ijklens(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + IjklensContext* ijklens(); + IjklensContext* ijklens(int precedence); + class IjklenContext : public antlr4::ParserRuleContext { + public: + antlr4::Token *var = nullptr; + antlr4::Token *len = nullptr; + IjklenContext(antlr4::ParserRuleContext *parent, size_t invokingState); + virtual size_t getRuleIndex() const override; + antlr4::tree::TerminalNode *NAME(); + antlr4::tree::TerminalNode *DIGITS(); + + virtual void enterRule(antlr4::tree::ParseTreeListener *listener) override; + virtual void exitRule(antlr4::tree::ParseTreeListener *listener) override; + + virtual std::any accept(antlr4::tree::ParseTreeVisitor *visitor) override; + + }; + + IjklenContext* ijklen(); + + + bool sempred(antlr4::RuleContext *_localctx, size_t ruleIndex, size_t predicateIndex) override; + + bool setSempred(SetContext *_localctx, size_t predicateIndex); + bool diracsSempred(DiracsContext *_localctx, size_t predicateIndex); + bool diracSempred(DiracContext *_localctx, size_t predicateIndex); + bool complexSempred(ComplexContext *_localctx, size_t predicateIndex); + bool angleSempred(AngleContext *_localctx, size_t predicateIndex); + bool ijklensSempred(IjklensContext *_localctx, size_t predicateIndex); + bool ijklenSempred(IjklenContext *_localctx, size_t predicateIndex); + + // By default the static state used to implement the parser is lazily initialized during the first + // call to the constructor. You can call this function if you wish to initialize the static state + // ahead of time. + static void initialize(); + +private: +}; + diff --git a/include/autoq/parsing/ExtendedDirac/ExtendedDiracVisitor.h b/include/autoq/parsing/ExtendedDirac/ExtendedDiracVisitor.h new file mode 100644 index 000000000..24b4a22c8 --- /dev/null +++ b/include/autoq/parsing/ExtendedDirac/ExtendedDiracVisitor.h @@ -0,0 +1,42 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + +#pragma once + + +#include "antlr4-runtime.h" +#include "ExtendedDiracParser.h" + + + +/** + * This class defines an abstract visitor for a parse tree + * produced by ExtendedDiracParser. + */ +class ExtendedDiracVisitor : public antlr4::tree::AbstractParseTreeVisitor { +public: + + /** + * Visit parse trees produced by ExtendedDiracParser. + */ + virtual std::any visitExtendedDirac(ExtendedDiracParser::ExtendedDiracContext *context) = 0; + + virtual std::any visitSet(ExtendedDiracParser::SetContext *context) = 0; + + virtual std::any visitDiracs(ExtendedDiracParser::DiracsContext *context) = 0; + + virtual std::any visitDirac(ExtendedDiracParser::DiracContext *context) = 0; + + virtual std::any visitCket(ExtendedDiracParser::CketContext *context) = 0; + + virtual std::any visitComplex(ExtendedDiracParser::ComplexContext *context) = 0; + + virtual std::any visitAngle(ExtendedDiracParser::AngleContext *context) = 0; + + virtual std::any visitIjklens(ExtendedDiracParser::IjklensContext *context) = 0; + + virtual std::any visitIjklen(ExtendedDiracParser::IjklenContext *context) = 0; + + +}; + diff --git a/include/autoq/parsing/timbuk_parser.hh b/include/autoq/parsing/timbuk_parser.hh index 1572636d6..fc0455a90 100644 --- a/include/autoq/parsing/timbuk_parser.hh +++ b/include/autoq/parsing/timbuk_parser.hh @@ -37,7 +37,7 @@ struct AUTOQ::Parsing::TimbukParser // static AUTOQ::Automata ParseString(std::string fileContents); static AUTOQ::Automata ReadAutomaton(const std::string& filepath); static AUTOQ::Automata ReadAutomaton(const std::string& filepath, bool &do_not_throw_term_undefined_error); - static AUTOQ::Automata parse_hsl_from_istream(std::istream *is, bool &do_not_throw_term_undefined_error, const std::map &constants = {}, const std::map &predicates = {}); + static AUTOQ::Automata parse_extended_dirac_from_istream(std::istream *is, bool &do_not_throw_term_undefined_error, const std::map &constants = {}, const std::map &predicates = {}); }; std::variant, AUTOQ::Automata, AUTOQ::Automata> ReadAutomaton(const std::string& filepath); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc0d79537..9971dddb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,6 +38,10 @@ include_directories(../include) file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cc" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") add_library(lsta STATIC ${SOURCE_FILES}) +# Suppress all warnings in the mentioned directory +file(GLOB_RECURSE Extended_Dirac_SOURCE_FILES "./ExtendedDirac/*.cpp") +set_source_files_properties(${Extended_Dirac_SOURCE_FILES} PROPERTIES COMPILE_FLAGS "-w") + ############################################################################## # DEPENDENCIES - Z3 ############################################################################## diff --git a/src/ExtendedDirac/ExtendedDirac.g4 b/src/ExtendedDirac/ExtendedDirac.g4 new file mode 100644 index 000000000..d5bfb5151 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDirac.g4 @@ -0,0 +1,88 @@ +grammar ExtendedDirac; + +@parser::members { + bool isSymbolicAutomaton = false; + std::set predefinedVars; + + bool isNonZero(const std::string& text) { + return std::stoi(text) != 0; + } + bool isASingleLetter(const std::string& text) { + return text.length() == 1 && 'a' <= text.at(0) && text.at(0) <= 'z'; + } +} + +/******************************************************************* + * TOKENS + *******************************************************************/ +ADD: '+'; +DIV: '/'; +DIGITS: [0-9]+; +INTERSECTION: '∩'; +KET: '|' [01A-Za-z*']+ ('⟩'|'>'); +MUL: '*'; +NAME: [A-Za-z][A-Za-z0-9]*; +PROD: '⊗'; +SUB: '-'; +UNION: '∪'; + +/******************************************************************* + * GRAMMAR + *******************************************************************/ +extendedDirac: set + | set '\\' set + ; + +set: set '^' n=DIGITS {isNonZero($n.text)}? + | '(' set ')' + | '{' diracs '}' + | '{' dirac '|' ijklens '}' + | set op=PROD set + | set op=(UNION|INTERSECTION) set + ; + +diracs: dirac + | diracs ',' dirac + ; + +dirac: cket + | dirac op=(ADD|SUB) cket + ; + +cket: (complex | complex op='*' | '-')? KET { + std::string text = $KET.text; // Get the full text of the KET token + std::string state = text.substr(1, text.length() - 2); // Remove the first and last characters + }; + +complex: complex '^' n=DIGITS {isNonZero($n.text)}? + | complex complex + | complex op=(MUL|DIV) complex + | complex op=(ADD|SUB) complex + | '(' complex ')' + | '-' complex + | 'ei2pi(' angle ')' + | 'eipi(' angle ')' + | DIGITS + | '√2' + | var=NAME { if (!predefinedVars.contains($var.text)) isSymbolicAutomaton = true; } + ; + +angle: '-'? x=DIGITS '/' y=DIGITS {isNonZero($y.text)}? + | '-'? n=DIGITS + ; + +ijklens: ijklen + | ijklens ',' ijklen + ; + +ijklen: '|' var=NAME '|=' len=DIGITS {isASingleLetter($var.text) && isNonZero($len.text)}? + ; + +/******************************************************************* +* THE END +*******************************************************************/ + +WS: [ \t\r\n]+ -> skip; + +// In the project root folder, execute: +// antlr4 -Dlanguage=Cpp -visitor src/ExtendedDirac/ExtendedDirac.g4 && mv src/ExtendedDirac/ExtendedDirac*.h include/autoq/parsing/ExtendedDirac/ && make release \ No newline at end of file diff --git a/src/ExtendedDirac/ExtendedDirac.interp b/src/ExtendedDirac/ExtendedDirac.interp new file mode 100644 index 000000000..81e760c29 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDirac.interp @@ -0,0 +1,66 @@ +token literal names: +null +'\\' +'^' +'(' +')' +'{' +'}' +'|' +',' +'ei2pi(' +'eipi(' +'√2' +'|=' +'+' +'/' +null +'∩' +null +'*' +null +'⊗' +'-' +'∪' +null + +token symbolic names: +null +null +null +null +null +null +null +null +null +null +null +null +null +ADD +DIV +DIGITS +INTERSECTION +KET +MUL +NAME +PROD +SUB +UNION +WS + +rule names: +extendedDirac +set +diracs +dirac +cket +complex +angle +ijklens +ijklen + + +atn: +[4, 1, 23, 158, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 3, 0, 24, 8, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 41, 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 53, 8, 1, 10, 1, 12, 1, 56, 9, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 5, 2, 64, 8, 2, 10, 2, 12, 2, 67, 9, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 75, 8, 3, 10, 3, 12, 3, 78, 9, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 85, 8, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 3, 5, 109, 8, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 123, 8, 5, 10, 5, 12, 5, 126, 9, 5, 1, 6, 3, 6, 129, 8, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 136, 8, 6, 1, 6, 3, 6, 139, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 147, 8, 7, 10, 7, 12, 7, 150, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 0, 5, 2, 4, 6, 10, 14, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 0, 3, 2, 0, 16, 16, 22, 22, 2, 0, 13, 13, 21, 21, 2, 0, 14, 14, 18, 18, 173, 0, 23, 1, 0, 0, 0, 2, 40, 1, 0, 0, 0, 4, 57, 1, 0, 0, 0, 6, 68, 1, 0, 0, 0, 8, 84, 1, 0, 0, 0, 10, 108, 1, 0, 0, 0, 12, 138, 1, 0, 0, 0, 14, 140, 1, 0, 0, 0, 16, 151, 1, 0, 0, 0, 18, 24, 3, 2, 1, 0, 19, 20, 3, 2, 1, 0, 20, 21, 5, 1, 0, 0, 21, 22, 3, 2, 1, 0, 22, 24, 1, 0, 0, 0, 23, 18, 1, 0, 0, 0, 23, 19, 1, 0, 0, 0, 24, 1, 1, 0, 0, 0, 25, 26, 6, 1, -1, 0, 26, 27, 5, 3, 0, 0, 27, 28, 3, 2, 1, 0, 28, 29, 5, 4, 0, 0, 29, 41, 1, 0, 0, 0, 30, 31, 5, 5, 0, 0, 31, 32, 3, 4, 2, 0, 32, 33, 5, 6, 0, 0, 33, 41, 1, 0, 0, 0, 34, 35, 5, 5, 0, 0, 35, 36, 3, 6, 3, 0, 36, 37, 5, 7, 0, 0, 37, 38, 3, 14, 7, 0, 38, 39, 5, 6, 0, 0, 39, 41, 1, 0, 0, 0, 40, 25, 1, 0, 0, 0, 40, 30, 1, 0, 0, 0, 40, 34, 1, 0, 0, 0, 41, 54, 1, 0, 0, 0, 42, 43, 10, 2, 0, 0, 43, 44, 5, 20, 0, 0, 44, 53, 3, 2, 1, 3, 45, 46, 10, 1, 0, 0, 46, 47, 7, 0, 0, 0, 47, 53, 3, 2, 1, 2, 48, 49, 10, 6, 0, 0, 49, 50, 5, 2, 0, 0, 50, 51, 5, 15, 0, 0, 51, 53, 4, 1, 3, 1, 52, 42, 1, 0, 0, 0, 52, 45, 1, 0, 0, 0, 52, 48, 1, 0, 0, 0, 53, 56, 1, 0, 0, 0, 54, 52, 1, 0, 0, 0, 54, 55, 1, 0, 0, 0, 55, 3, 1, 0, 0, 0, 56, 54, 1, 0, 0, 0, 57, 58, 6, 2, -1, 0, 58, 59, 3, 6, 3, 0, 59, 65, 1, 0, 0, 0, 60, 61, 10, 1, 0, 0, 61, 62, 5, 8, 0, 0, 62, 64, 3, 6, 3, 0, 63, 60, 1, 0, 0, 0, 64, 67, 1, 0, 0, 0, 65, 63, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 5, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 68, 69, 6, 3, -1, 0, 69, 70, 3, 8, 4, 0, 70, 76, 1, 0, 0, 0, 71, 72, 10, 1, 0, 0, 72, 73, 7, 1, 0, 0, 73, 75, 3, 8, 4, 0, 74, 71, 1, 0, 0, 0, 75, 78, 1, 0, 0, 0, 76, 74, 1, 0, 0, 0, 76, 77, 1, 0, 0, 0, 77, 7, 1, 0, 0, 0, 78, 76, 1, 0, 0, 0, 79, 85, 3, 10, 5, 0, 80, 81, 3, 10, 5, 0, 81, 82, 5, 18, 0, 0, 82, 85, 1, 0, 0, 0, 83, 85, 5, 21, 0, 0, 84, 79, 1, 0, 0, 0, 84, 80, 1, 0, 0, 0, 84, 83, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 86, 1, 0, 0, 0, 86, 87, 5, 17, 0, 0, 87, 88, 6, 4, -1, 0, 88, 9, 1, 0, 0, 0, 89, 90, 6, 5, -1, 0, 90, 91, 5, 3, 0, 0, 91, 92, 3, 10, 5, 0, 92, 93, 5, 4, 0, 0, 93, 109, 1, 0, 0, 0, 94, 95, 5, 21, 0, 0, 95, 109, 3, 10, 5, 6, 96, 97, 5, 9, 0, 0, 97, 98, 3, 12, 6, 0, 98, 99, 5, 4, 0, 0, 99, 109, 1, 0, 0, 0, 100, 101, 5, 10, 0, 0, 101, 102, 3, 12, 6, 0, 102, 103, 5, 4, 0, 0, 103, 109, 1, 0, 0, 0, 104, 109, 5, 15, 0, 0, 105, 109, 5, 11, 0, 0, 106, 107, 5, 19, 0, 0, 107, 109, 6, 5, -1, 0, 108, 89, 1, 0, 0, 0, 108, 94, 1, 0, 0, 0, 108, 96, 1, 0, 0, 0, 108, 100, 1, 0, 0, 0, 108, 104, 1, 0, 0, 0, 108, 105, 1, 0, 0, 0, 108, 106, 1, 0, 0, 0, 109, 124, 1, 0, 0, 0, 110, 111, 10, 10, 0, 0, 111, 123, 3, 10, 5, 11, 112, 113, 10, 9, 0, 0, 113, 114, 7, 2, 0, 0, 114, 123, 3, 10, 5, 10, 115, 116, 10, 8, 0, 0, 116, 117, 7, 1, 0, 0, 117, 123, 3, 10, 5, 9, 118, 119, 10, 11, 0, 0, 119, 120, 5, 2, 0, 0, 120, 121, 5, 15, 0, 0, 121, 123, 4, 5, 10, 1, 122, 110, 1, 0, 0, 0, 122, 112, 1, 0, 0, 0, 122, 115, 1, 0, 0, 0, 122, 118, 1, 0, 0, 0, 123, 126, 1, 0, 0, 0, 124, 122, 1, 0, 0, 0, 124, 125, 1, 0, 0, 0, 125, 11, 1, 0, 0, 0, 126, 124, 1, 0, 0, 0, 127, 129, 5, 21, 0, 0, 128, 127, 1, 0, 0, 0, 128, 129, 1, 0, 0, 0, 129, 130, 1, 0, 0, 0, 130, 131, 5, 15, 0, 0, 131, 132, 5, 14, 0, 0, 132, 133, 5, 15, 0, 0, 133, 139, 4, 6, 11, 1, 134, 136, 5, 21, 0, 0, 135, 134, 1, 0, 0, 0, 135, 136, 1, 0, 0, 0, 136, 137, 1, 0, 0, 0, 137, 139, 5, 15, 0, 0, 138, 128, 1, 0, 0, 0, 138, 135, 1, 0, 0, 0, 139, 13, 1, 0, 0, 0, 140, 141, 6, 7, -1, 0, 141, 142, 3, 16, 8, 0, 142, 148, 1, 0, 0, 0, 143, 144, 10, 1, 0, 0, 144, 145, 5, 8, 0, 0, 145, 147, 3, 16, 8, 0, 146, 143, 1, 0, 0, 0, 147, 150, 1, 0, 0, 0, 148, 146, 1, 0, 0, 0, 148, 149, 1, 0, 0, 0, 149, 15, 1, 0, 0, 0, 150, 148, 1, 0, 0, 0, 151, 152, 5, 7, 0, 0, 152, 153, 5, 19, 0, 0, 153, 154, 5, 12, 0, 0, 154, 155, 5, 15, 0, 0, 155, 156, 4, 8, 13, 1, 156, 17, 1, 0, 0, 0, 14, 23, 40, 52, 54, 65, 76, 84, 108, 122, 124, 128, 135, 138, 148] \ No newline at end of file diff --git a/src/ExtendedDirac/ExtendedDirac.tokens b/src/ExtendedDirac/ExtendedDirac.tokens new file mode 100644 index 000000000..09f8d8817 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDirac.tokens @@ -0,0 +1,42 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +ADD=13 +DIV=14 +DIGITS=15 +INTERSECTION=16 +KET=17 +MUL=18 +NAME=19 +PROD=20 +SUB=21 +UNION=22 +WS=23 +'\\'=1 +'^'=2 +'('=3 +')'=4 +'{'=5 +'}'=6 +'|'=7 +','=8 +'ei2pi('=9 +'eipi('=10 +'√2'=11 +'|='=12 +'+'=13 +'/'=14 +'∩'=16 +'*'=18 +'⊗'=20 +'-'=21 +'∪'=22 diff --git a/src/ExtendedDirac/ExtendedDiracBaseListener.cpp b/src/ExtendedDirac/ExtendedDiracBaseListener.cpp new file mode 100644 index 000000000..1b8eaf68e --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracBaseListener.cpp @@ -0,0 +1,7 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + + +#include "ExtendedDiracBaseListener.h" + + diff --git a/src/ExtendedDirac/ExtendedDiracBaseVisitor.cpp b/src/ExtendedDirac/ExtendedDiracBaseVisitor.cpp new file mode 100644 index 000000000..64276e08f --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracBaseVisitor.cpp @@ -0,0 +1,7 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + + +#include "ExtendedDiracBaseVisitor.h" + + diff --git a/src/ExtendedDirac/ExtendedDiracLexer.cpp b/src/ExtendedDirac/ExtendedDiracLexer.cpp new file mode 100644 index 000000000..9e4e30322 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracLexer.cpp @@ -0,0 +1,184 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + + +#include "ExtendedDiracLexer.h" + + +using namespace antlr4; + + + +using namespace antlr4; + +namespace { + +struct ExtendedDiracLexerStaticData final { + ExtendedDiracLexerStaticData(std::vector ruleNames, + std::vector channelNames, + std::vector modeNames, + std::vector literalNames, + std::vector symbolicNames) + : ruleNames(std::move(ruleNames)), channelNames(std::move(channelNames)), + modeNames(std::move(modeNames)), literalNames(std::move(literalNames)), + symbolicNames(std::move(symbolicNames)), + vocabulary(this->literalNames, this->symbolicNames) {} + + ExtendedDiracLexerStaticData(const ExtendedDiracLexerStaticData&) = delete; + ExtendedDiracLexerStaticData(ExtendedDiracLexerStaticData&&) = delete; + ExtendedDiracLexerStaticData& operator=(const ExtendedDiracLexerStaticData&) = delete; + ExtendedDiracLexerStaticData& operator=(ExtendedDiracLexerStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector channelNames; + const std::vector modeNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; +}; + +::antlr4::internal::OnceFlag extendeddiraclexerLexerOnceFlag; +#if ANTLR4_USE_THREAD_LOCAL_CACHE +static thread_local +#endif +std::unique_ptr extendeddiraclexerLexerStaticData = nullptr; + +void extendeddiraclexerLexerInitialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + if (extendeddiraclexerLexerStaticData != nullptr) { + return; + } +#else + assert(extendeddiraclexerLexerStaticData == nullptr); +#endif + auto staticData = std::make_unique( + std::vector{ + "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6", "T__7", "T__8", + "T__9", "T__10", "T__11", "ADD", "DIV", "DIGITS", "INTERSECTION", + "KET", "MUL", "NAME", "PROD", "SUB", "UNION", "WS" + }, + std::vector{ + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }, + std::vector{ + "DEFAULT_MODE" + }, + std::vector{ + "", "'\\'", "'^'", "'('", "')'", "'{'", "'}'", "'|'", "','", "'ei2pi('", + "'eipi('", "'\\u221A2'", "'|='", "'+'", "'/'", "", "'\\u2229'", "", + "'*'", "", "'\\u2297'", "'-'", "'\\u222A'" + }, + std::vector{ + "", "", "", "", "", "", "", "", "", "", "", "", "", "ADD", "DIV", + "DIGITS", "INTERSECTION", "KET", "MUL", "NAME", "PROD", "SUB", "UNION", + "WS" + } + ); + static const int32_t serializedATNSegment[] = { + 4,0,23,123,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7, + 6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14, + 7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21, + 7,21,2,22,7,22,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1, + 6,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1, + 10,1,10,1,11,1,11,1,11,1,12,1,12,1,13,1,13,1,14,4,14,88,8,14,11,14,12, + 14,89,1,15,1,15,1,16,1,16,4,16,96,8,16,11,16,12,16,97,1,16,1,16,1,17, + 1,17,1,18,1,18,5,18,106,8,18,10,18,12,18,109,9,18,1,19,1,19,1,20,1,20, + 1,21,1,21,1,22,4,22,118,8,22,11,22,12,22,119,1,22,1,22,0,0,23,1,1,3,2, + 5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31, + 16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,1,0,6,1,0,48,57,5,0,39,39, + 42,42,48,49,65,90,97,122,2,0,62,62,10217,10217,2,0,65,90,97,122,3,0,48, + 57,65,90,97,122,3,0,9,10,13,13,32,32,126,0,1,1,0,0,0,0,3,1,0,0,0,0,5, + 1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0, + 0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0, + 27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1, + 0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,1,47,1,0,0, + 0,3,49,1,0,0,0,5,51,1,0,0,0,7,53,1,0,0,0,9,55,1,0,0,0,11,57,1,0,0,0,13, + 59,1,0,0,0,15,61,1,0,0,0,17,63,1,0,0,0,19,70,1,0,0,0,21,76,1,0,0,0,23, + 79,1,0,0,0,25,82,1,0,0,0,27,84,1,0,0,0,29,87,1,0,0,0,31,91,1,0,0,0,33, + 93,1,0,0,0,35,101,1,0,0,0,37,103,1,0,0,0,39,110,1,0,0,0,41,112,1,0,0, + 0,43,114,1,0,0,0,45,117,1,0,0,0,47,48,5,92,0,0,48,2,1,0,0,0,49,50,5,94, + 0,0,50,4,1,0,0,0,51,52,5,40,0,0,52,6,1,0,0,0,53,54,5,41,0,0,54,8,1,0, + 0,0,55,56,5,123,0,0,56,10,1,0,0,0,57,58,5,125,0,0,58,12,1,0,0,0,59,60, + 5,124,0,0,60,14,1,0,0,0,61,62,5,44,0,0,62,16,1,0,0,0,63,64,5,101,0,0, + 64,65,5,105,0,0,65,66,5,50,0,0,66,67,5,112,0,0,67,68,5,105,0,0,68,69, + 5,40,0,0,69,18,1,0,0,0,70,71,5,101,0,0,71,72,5,105,0,0,72,73,5,112,0, + 0,73,74,5,105,0,0,74,75,5,40,0,0,75,20,1,0,0,0,76,77,5,8730,0,0,77,78, + 5,50,0,0,78,22,1,0,0,0,79,80,5,124,0,0,80,81,5,61,0,0,81,24,1,0,0,0,82, + 83,5,43,0,0,83,26,1,0,0,0,84,85,5,47,0,0,85,28,1,0,0,0,86,88,7,0,0,0, + 87,86,1,0,0,0,88,89,1,0,0,0,89,87,1,0,0,0,89,90,1,0,0,0,90,30,1,0,0,0, + 91,92,5,8745,0,0,92,32,1,0,0,0,93,95,5,124,0,0,94,96,7,1,0,0,95,94,1, + 0,0,0,96,97,1,0,0,0,97,95,1,0,0,0,97,98,1,0,0,0,98,99,1,0,0,0,99,100, + 7,2,0,0,100,34,1,0,0,0,101,102,5,42,0,0,102,36,1,0,0,0,103,107,7,3,0, + 0,104,106,7,4,0,0,105,104,1,0,0,0,106,109,1,0,0,0,107,105,1,0,0,0,107, + 108,1,0,0,0,108,38,1,0,0,0,109,107,1,0,0,0,110,111,5,8855,0,0,111,40, + 1,0,0,0,112,113,5,45,0,0,113,42,1,0,0,0,114,115,5,8746,0,0,115,44,1,0, + 0,0,116,118,7,5,0,0,117,116,1,0,0,0,118,119,1,0,0,0,119,117,1,0,0,0,119, + 120,1,0,0,0,120,121,1,0,0,0,121,122,6,22,0,0,122,46,1,0,0,0,5,0,89,97, + 107,119,1,6,0,0 + }; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + } + extendeddiraclexerLexerStaticData = std::move(staticData); +} + +} + +ExtendedDiracLexer::ExtendedDiracLexer(CharStream *input) : Lexer(input) { + ExtendedDiracLexer::initialize(); + _interpreter = new atn::LexerATNSimulator(this, *extendeddiraclexerLexerStaticData->atn, extendeddiraclexerLexerStaticData->decisionToDFA, extendeddiraclexerLexerStaticData->sharedContextCache); +} + +ExtendedDiracLexer::~ExtendedDiracLexer() { + delete _interpreter; +} + +std::string ExtendedDiracLexer::getGrammarFileName() const { + return "ExtendedDirac.g4"; +} + +const std::vector& ExtendedDiracLexer::getRuleNames() const { + return extendeddiraclexerLexerStaticData->ruleNames; +} + +const std::vector& ExtendedDiracLexer::getChannelNames() const { + return extendeddiraclexerLexerStaticData->channelNames; +} + +const std::vector& ExtendedDiracLexer::getModeNames() const { + return extendeddiraclexerLexerStaticData->modeNames; +} + +const dfa::Vocabulary& ExtendedDiracLexer::getVocabulary() const { + return extendeddiraclexerLexerStaticData->vocabulary; +} + +antlr4::atn::SerializedATNView ExtendedDiracLexer::getSerializedATN() const { + return extendeddiraclexerLexerStaticData->serializedATN; +} + +const atn::ATN& ExtendedDiracLexer::getATN() const { + return *extendeddiraclexerLexerStaticData->atn; +} + + + + +void ExtendedDiracLexer::initialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + extendeddiraclexerLexerInitialize(); +#else + ::antlr4::internal::call_once(extendeddiraclexerLexerOnceFlag, extendeddiraclexerLexerInitialize); +#endif +} diff --git a/src/ExtendedDirac/ExtendedDiracLexer.interp b/src/ExtendedDirac/ExtendedDiracLexer.interp new file mode 100644 index 000000000..01493d238 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracLexer.interp @@ -0,0 +1,86 @@ +token literal names: +null +'\\' +'^' +'(' +')' +'{' +'}' +'|' +',' +'ei2pi(' +'eipi(' +'√2' +'|=' +'+' +'/' +null +'∩' +null +'*' +null +'⊗' +'-' +'∪' +null + +token symbolic names: +null +null +null +null +null +null +null +null +null +null +null +null +null +ADD +DIV +DIGITS +INTERSECTION +KET +MUL +NAME +PROD +SUB +UNION +WS + +rule names: +T__0 +T__1 +T__2 +T__3 +T__4 +T__5 +T__6 +T__7 +T__8 +T__9 +T__10 +T__11 +ADD +DIV +DIGITS +INTERSECTION +KET +MUL +NAME +PROD +SUB +UNION +WS + +channel names: +DEFAULT_TOKEN_CHANNEL +HIDDEN + +mode names: +DEFAULT_MODE + +atn: +[4, 0, 23, 123, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 4, 14, 88, 8, 14, 11, 14, 12, 14, 89, 1, 15, 1, 15, 1, 16, 1, 16, 4, 16, 96, 8, 16, 11, 16, 12, 16, 97, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 5, 18, 106, 8, 18, 10, 18, 12, 18, 109, 9, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 21, 1, 21, 1, 22, 4, 22, 118, 8, 22, 11, 22, 12, 22, 119, 1, 22, 1, 22, 0, 0, 23, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 1, 0, 6, 1, 0, 48, 57, 5, 0, 39, 39, 42, 42, 48, 49, 65, 90, 97, 122, 2, 0, 62, 62, 10217, 10217, 2, 0, 65, 90, 97, 122, 3, 0, 48, 57, 65, 90, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 126, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 1, 47, 1, 0, 0, 0, 3, 49, 1, 0, 0, 0, 5, 51, 1, 0, 0, 0, 7, 53, 1, 0, 0, 0, 9, 55, 1, 0, 0, 0, 11, 57, 1, 0, 0, 0, 13, 59, 1, 0, 0, 0, 15, 61, 1, 0, 0, 0, 17, 63, 1, 0, 0, 0, 19, 70, 1, 0, 0, 0, 21, 76, 1, 0, 0, 0, 23, 79, 1, 0, 0, 0, 25, 82, 1, 0, 0, 0, 27, 84, 1, 0, 0, 0, 29, 87, 1, 0, 0, 0, 31, 91, 1, 0, 0, 0, 33, 93, 1, 0, 0, 0, 35, 101, 1, 0, 0, 0, 37, 103, 1, 0, 0, 0, 39, 110, 1, 0, 0, 0, 41, 112, 1, 0, 0, 0, 43, 114, 1, 0, 0, 0, 45, 117, 1, 0, 0, 0, 47, 48, 5, 92, 0, 0, 48, 2, 1, 0, 0, 0, 49, 50, 5, 94, 0, 0, 50, 4, 1, 0, 0, 0, 51, 52, 5, 40, 0, 0, 52, 6, 1, 0, 0, 0, 53, 54, 5, 41, 0, 0, 54, 8, 1, 0, 0, 0, 55, 56, 5, 123, 0, 0, 56, 10, 1, 0, 0, 0, 57, 58, 5, 125, 0, 0, 58, 12, 1, 0, 0, 0, 59, 60, 5, 124, 0, 0, 60, 14, 1, 0, 0, 0, 61, 62, 5, 44, 0, 0, 62, 16, 1, 0, 0, 0, 63, 64, 5, 101, 0, 0, 64, 65, 5, 105, 0, 0, 65, 66, 5, 50, 0, 0, 66, 67, 5, 112, 0, 0, 67, 68, 5, 105, 0, 0, 68, 69, 5, 40, 0, 0, 69, 18, 1, 0, 0, 0, 70, 71, 5, 101, 0, 0, 71, 72, 5, 105, 0, 0, 72, 73, 5, 112, 0, 0, 73, 74, 5, 105, 0, 0, 74, 75, 5, 40, 0, 0, 75, 20, 1, 0, 0, 0, 76, 77, 5, 8730, 0, 0, 77, 78, 5, 50, 0, 0, 78, 22, 1, 0, 0, 0, 79, 80, 5, 124, 0, 0, 80, 81, 5, 61, 0, 0, 81, 24, 1, 0, 0, 0, 82, 83, 5, 43, 0, 0, 83, 26, 1, 0, 0, 0, 84, 85, 5, 47, 0, 0, 85, 28, 1, 0, 0, 0, 86, 88, 7, 0, 0, 0, 87, 86, 1, 0, 0, 0, 88, 89, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 30, 1, 0, 0, 0, 91, 92, 5, 8745, 0, 0, 92, 32, 1, 0, 0, 0, 93, 95, 5, 124, 0, 0, 94, 96, 7, 1, 0, 0, 95, 94, 1, 0, 0, 0, 96, 97, 1, 0, 0, 0, 97, 95, 1, 0, 0, 0, 97, 98, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 100, 7, 2, 0, 0, 100, 34, 1, 0, 0, 0, 101, 102, 5, 42, 0, 0, 102, 36, 1, 0, 0, 0, 103, 107, 7, 3, 0, 0, 104, 106, 7, 4, 0, 0, 105, 104, 1, 0, 0, 0, 106, 109, 1, 0, 0, 0, 107, 105, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 38, 1, 0, 0, 0, 109, 107, 1, 0, 0, 0, 110, 111, 5, 8855, 0, 0, 111, 40, 1, 0, 0, 0, 112, 113, 5, 45, 0, 0, 113, 42, 1, 0, 0, 0, 114, 115, 5, 8746, 0, 0, 115, 44, 1, 0, 0, 0, 116, 118, 7, 5, 0, 0, 117, 116, 1, 0, 0, 0, 118, 119, 1, 0, 0, 0, 119, 117, 1, 0, 0, 0, 119, 120, 1, 0, 0, 0, 120, 121, 1, 0, 0, 0, 121, 122, 6, 22, 0, 0, 122, 46, 1, 0, 0, 0, 5, 0, 89, 97, 107, 119, 1, 6, 0, 0] \ No newline at end of file diff --git a/src/ExtendedDirac/ExtendedDiracLexer.tokens b/src/ExtendedDirac/ExtendedDiracLexer.tokens new file mode 100644 index 000000000..09f8d8817 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracLexer.tokens @@ -0,0 +1,42 @@ +T__0=1 +T__1=2 +T__2=3 +T__3=4 +T__4=5 +T__5=6 +T__6=7 +T__7=8 +T__8=9 +T__9=10 +T__10=11 +T__11=12 +ADD=13 +DIV=14 +DIGITS=15 +INTERSECTION=16 +KET=17 +MUL=18 +NAME=19 +PROD=20 +SUB=21 +UNION=22 +WS=23 +'\\'=1 +'^'=2 +'('=3 +')'=4 +'{'=5 +'}'=6 +'|'=7 +','=8 +'ei2pi('=9 +'eipi('=10 +'√2'=11 +'|='=12 +'+'=13 +'/'=14 +'∩'=16 +'*'=18 +'⊗'=20 +'-'=21 +'∪'=22 diff --git a/src/ExtendedDirac/ExtendedDiracListener.cpp b/src/ExtendedDirac/ExtendedDiracListener.cpp new file mode 100644 index 000000000..b69bfd957 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracListener.cpp @@ -0,0 +1,7 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + + +#include "ExtendedDiracListener.h" + + diff --git a/src/ExtendedDirac/ExtendedDiracParser.cpp b/src/ExtendedDirac/ExtendedDiracParser.cpp new file mode 100644 index 000000000..9da4109a4 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracParser.cpp @@ -0,0 +1,1433 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + + +#include "ExtendedDiracListener.h" +#include "ExtendedDiracVisitor.h" + +#include "ExtendedDiracParser.h" + + +using namespace antlrcpp; + +using namespace antlr4; + +namespace { + +struct ExtendedDiracParserStaticData final { + ExtendedDiracParserStaticData(std::vector ruleNames, + std::vector literalNames, + std::vector symbolicNames) + : ruleNames(std::move(ruleNames)), literalNames(std::move(literalNames)), + symbolicNames(std::move(symbolicNames)), + vocabulary(this->literalNames, this->symbolicNames) {} + + ExtendedDiracParserStaticData(const ExtendedDiracParserStaticData&) = delete; + ExtendedDiracParserStaticData(ExtendedDiracParserStaticData&&) = delete; + ExtendedDiracParserStaticData& operator=(const ExtendedDiracParserStaticData&) = delete; + ExtendedDiracParserStaticData& operator=(ExtendedDiracParserStaticData&&) = delete; + + std::vector decisionToDFA; + antlr4::atn::PredictionContextCache sharedContextCache; + const std::vector ruleNames; + const std::vector literalNames; + const std::vector symbolicNames; + const antlr4::dfa::Vocabulary vocabulary; + antlr4::atn::SerializedATNView serializedATN; + std::unique_ptr atn; +}; + +::antlr4::internal::OnceFlag extendeddiracParserOnceFlag; +#if ANTLR4_USE_THREAD_LOCAL_CACHE +static thread_local +#endif +std::unique_ptr extendeddiracParserStaticData = nullptr; + +void extendeddiracParserInitialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + if (extendeddiracParserStaticData != nullptr) { + return; + } +#else + assert(extendeddiracParserStaticData == nullptr); +#endif + auto staticData = std::make_unique( + std::vector{ + "extendedDirac", "set", "diracs", "dirac", "cket", "complex", "angle", + "ijklens", "ijklen" + }, + std::vector{ + "", "'\\'", "'^'", "'('", "')'", "'{'", "'}'", "'|'", "','", "'ei2pi('", + "'eipi('", "'\\u221A2'", "'|='", "'+'", "'/'", "", "'\\u2229'", "", + "'*'", "", "'\\u2297'", "'-'", "'\\u222A'" + }, + std::vector{ + "", "", "", "", "", "", "", "", "", "", "", "", "", "ADD", "DIV", + "DIGITS", "INTERSECTION", "KET", "MUL", "NAME", "PROD", "SUB", "UNION", + "WS" + } + ); + static const int32_t serializedATNSegment[] = { + 4,1,23,158,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2, + 7,7,7,2,8,7,8,1,0,1,0,1,0,1,0,1,0,3,0,24,8,0,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,41,8,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,5,1,53,8,1,10,1,12,1,56,9,1,1,2,1,2,1,2,1,2,1,2,1,2, + 5,2,64,8,2,10,2,12,2,67,9,2,1,3,1,3,1,3,1,3,1,3,1,3,5,3,75,8,3,10,3,12, + 3,78,9,3,1,4,1,4,1,4,1,4,1,4,3,4,85,8,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1, + 5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,3,5,109,8,5, + 1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,5,5,123,8,5,10,5,12,5, + 126,9,5,1,6,3,6,129,8,6,1,6,1,6,1,6,1,6,1,6,3,6,136,8,6,1,6,3,6,139,8, + 6,1,7,1,7,1,7,1,7,1,7,1,7,5,7,147,8,7,10,7,12,7,150,9,7,1,8,1,8,1,8,1, + 8,1,8,1,8,1,8,0,5,2,4,6,10,14,9,0,2,4,6,8,10,12,14,16,0,3,2,0,16,16,22, + 22,2,0,13,13,21,21,2,0,14,14,18,18,173,0,23,1,0,0,0,2,40,1,0,0,0,4,57, + 1,0,0,0,6,68,1,0,0,0,8,84,1,0,0,0,10,108,1,0,0,0,12,138,1,0,0,0,14,140, + 1,0,0,0,16,151,1,0,0,0,18,24,3,2,1,0,19,20,3,2,1,0,20,21,5,1,0,0,21,22, + 3,2,1,0,22,24,1,0,0,0,23,18,1,0,0,0,23,19,1,0,0,0,24,1,1,0,0,0,25,26, + 6,1,-1,0,26,27,5,3,0,0,27,28,3,2,1,0,28,29,5,4,0,0,29,41,1,0,0,0,30,31, + 5,5,0,0,31,32,3,4,2,0,32,33,5,6,0,0,33,41,1,0,0,0,34,35,5,5,0,0,35,36, + 3,6,3,0,36,37,5,7,0,0,37,38,3,14,7,0,38,39,5,6,0,0,39,41,1,0,0,0,40,25, + 1,0,0,0,40,30,1,0,0,0,40,34,1,0,0,0,41,54,1,0,0,0,42,43,10,2,0,0,43,44, + 5,20,0,0,44,53,3,2,1,3,45,46,10,1,0,0,46,47,7,0,0,0,47,53,3,2,1,2,48, + 49,10,6,0,0,49,50,5,2,0,0,50,51,5,15,0,0,51,53,4,1,3,1,52,42,1,0,0,0, + 52,45,1,0,0,0,52,48,1,0,0,0,53,56,1,0,0,0,54,52,1,0,0,0,54,55,1,0,0,0, + 55,3,1,0,0,0,56,54,1,0,0,0,57,58,6,2,-1,0,58,59,3,6,3,0,59,65,1,0,0,0, + 60,61,10,1,0,0,61,62,5,8,0,0,62,64,3,6,3,0,63,60,1,0,0,0,64,67,1,0,0, + 0,65,63,1,0,0,0,65,66,1,0,0,0,66,5,1,0,0,0,67,65,1,0,0,0,68,69,6,3,-1, + 0,69,70,3,8,4,0,70,76,1,0,0,0,71,72,10,1,0,0,72,73,7,1,0,0,73,75,3,8, + 4,0,74,71,1,0,0,0,75,78,1,0,0,0,76,74,1,0,0,0,76,77,1,0,0,0,77,7,1,0, + 0,0,78,76,1,0,0,0,79,85,3,10,5,0,80,81,3,10,5,0,81,82,5,18,0,0,82,85, + 1,0,0,0,83,85,5,21,0,0,84,79,1,0,0,0,84,80,1,0,0,0,84,83,1,0,0,0,84,85, + 1,0,0,0,85,86,1,0,0,0,86,87,5,17,0,0,87,88,6,4,-1,0,88,9,1,0,0,0,89,90, + 6,5,-1,0,90,91,5,3,0,0,91,92,3,10,5,0,92,93,5,4,0,0,93,109,1,0,0,0,94, + 95,5,21,0,0,95,109,3,10,5,6,96,97,5,9,0,0,97,98,3,12,6,0,98,99,5,4,0, + 0,99,109,1,0,0,0,100,101,5,10,0,0,101,102,3,12,6,0,102,103,5,4,0,0,103, + 109,1,0,0,0,104,109,5,15,0,0,105,109,5,11,0,0,106,107,5,19,0,0,107,109, + 6,5,-1,0,108,89,1,0,0,0,108,94,1,0,0,0,108,96,1,0,0,0,108,100,1,0,0,0, + 108,104,1,0,0,0,108,105,1,0,0,0,108,106,1,0,0,0,109,124,1,0,0,0,110,111, + 10,10,0,0,111,123,3,10,5,11,112,113,10,9,0,0,113,114,7,2,0,0,114,123, + 3,10,5,10,115,116,10,8,0,0,116,117,7,1,0,0,117,123,3,10,5,9,118,119,10, + 11,0,0,119,120,5,2,0,0,120,121,5,15,0,0,121,123,4,5,10,1,122,110,1,0, + 0,0,122,112,1,0,0,0,122,115,1,0,0,0,122,118,1,0,0,0,123,126,1,0,0,0,124, + 122,1,0,0,0,124,125,1,0,0,0,125,11,1,0,0,0,126,124,1,0,0,0,127,129,5, + 21,0,0,128,127,1,0,0,0,128,129,1,0,0,0,129,130,1,0,0,0,130,131,5,15,0, + 0,131,132,5,14,0,0,132,133,5,15,0,0,133,139,4,6,11,1,134,136,5,21,0,0, + 135,134,1,0,0,0,135,136,1,0,0,0,136,137,1,0,0,0,137,139,5,15,0,0,138, + 128,1,0,0,0,138,135,1,0,0,0,139,13,1,0,0,0,140,141,6,7,-1,0,141,142,3, + 16,8,0,142,148,1,0,0,0,143,144,10,1,0,0,144,145,5,8,0,0,145,147,3,16, + 8,0,146,143,1,0,0,0,147,150,1,0,0,0,148,146,1,0,0,0,148,149,1,0,0,0,149, + 15,1,0,0,0,150,148,1,0,0,0,151,152,5,7,0,0,152,153,5,19,0,0,153,154,5, + 12,0,0,154,155,5,15,0,0,155,156,4,8,13,1,156,17,1,0,0,0,14,23,40,52,54, + 65,76,84,108,122,124,128,135,138,148 + }; + staticData->serializedATN = antlr4::atn::SerializedATNView(serializedATNSegment, sizeof(serializedATNSegment) / sizeof(serializedATNSegment[0])); + + antlr4::atn::ATNDeserializer deserializer; + staticData->atn = deserializer.deserialize(staticData->serializedATN); + + const size_t count = staticData->atn->getNumberOfDecisions(); + staticData->decisionToDFA.reserve(count); + for (size_t i = 0; i < count; i++) { + staticData->decisionToDFA.emplace_back(staticData->atn->getDecisionState(i), i); + } + extendeddiracParserStaticData = std::move(staticData); +} + +} + +ExtendedDiracParser::ExtendedDiracParser(TokenStream *input) : ExtendedDiracParser(input, antlr4::atn::ParserATNSimulatorOptions()) {} + +ExtendedDiracParser::ExtendedDiracParser(TokenStream *input, const antlr4::atn::ParserATNSimulatorOptions &options) : Parser(input) { + ExtendedDiracParser::initialize(); + _interpreter = new atn::ParserATNSimulator(this, *extendeddiracParserStaticData->atn, extendeddiracParserStaticData->decisionToDFA, extendeddiracParserStaticData->sharedContextCache, options); +} + +ExtendedDiracParser::~ExtendedDiracParser() { + delete _interpreter; +} + +const atn::ATN& ExtendedDiracParser::getATN() const { + return *extendeddiracParserStaticData->atn; +} + +std::string ExtendedDiracParser::getGrammarFileName() const { + return "ExtendedDirac.g4"; +} + +const std::vector& ExtendedDiracParser::getRuleNames() const { + return extendeddiracParserStaticData->ruleNames; +} + +const dfa::Vocabulary& ExtendedDiracParser::getVocabulary() const { + return extendeddiracParserStaticData->vocabulary; +} + +antlr4::atn::SerializedATNView ExtendedDiracParser::getSerializedATN() const { + return extendeddiracParserStaticData->serializedATN; +} + + +//----------------- ExtendedDiracContext ------------------------------------------------------------------ + +ExtendedDiracParser::ExtendedDiracContext::ExtendedDiracContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector ExtendedDiracParser::ExtendedDiracContext::set() { + return getRuleContexts(); +} + +ExtendedDiracParser::SetContext* ExtendedDiracParser::ExtendedDiracContext::set(size_t i) { + return getRuleContext(i); +} + + +size_t ExtendedDiracParser::ExtendedDiracContext::getRuleIndex() const { + return ExtendedDiracParser::RuleExtendedDirac; +} + +void ExtendedDiracParser::ExtendedDiracContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterExtendedDirac(this); +} + +void ExtendedDiracParser::ExtendedDiracContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitExtendedDirac(this); +} + + +std::any ExtendedDiracParser::ExtendedDiracContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitExtendedDirac(this); + else + return visitor->visitChildren(this); +} + +ExtendedDiracParser::ExtendedDiracContext* ExtendedDiracParser::extendedDirac() { + ExtendedDiracContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 0, ExtendedDiracParser::RuleExtendedDirac); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(23); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 0, _ctx)) { + case 1: { + enterOuterAlt(_localctx, 1); + setState(18); + set(0); + break; + } + + case 2: { + enterOuterAlt(_localctx, 2); + setState(19); + set(0); + setState(20); + match(ExtendedDiracParser::T__0); + setState(21); + set(0); + break; + } + + default: + break; + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- SetContext ------------------------------------------------------------------ + +ExtendedDiracParser::SetContext::SetContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector ExtendedDiracParser::SetContext::set() { + return getRuleContexts(); +} + +ExtendedDiracParser::SetContext* ExtendedDiracParser::SetContext::set(size_t i) { + return getRuleContext(i); +} + +ExtendedDiracParser::DiracsContext* ExtendedDiracParser::SetContext::diracs() { + return getRuleContext(0); +} + +ExtendedDiracParser::DiracContext* ExtendedDiracParser::SetContext::dirac() { + return getRuleContext(0); +} + +ExtendedDiracParser::IjklensContext* ExtendedDiracParser::SetContext::ijklens() { + return getRuleContext(0); +} + +tree::TerminalNode* ExtendedDiracParser::SetContext::PROD() { + return getToken(ExtendedDiracParser::PROD, 0); +} + +tree::TerminalNode* ExtendedDiracParser::SetContext::UNION() { + return getToken(ExtendedDiracParser::UNION, 0); +} + +tree::TerminalNode* ExtendedDiracParser::SetContext::INTERSECTION() { + return getToken(ExtendedDiracParser::INTERSECTION, 0); +} + +tree::TerminalNode* ExtendedDiracParser::SetContext::DIGITS() { + return getToken(ExtendedDiracParser::DIGITS, 0); +} + + +size_t ExtendedDiracParser::SetContext::getRuleIndex() const { + return ExtendedDiracParser::RuleSet; +} + +void ExtendedDiracParser::SetContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterSet(this); +} + +void ExtendedDiracParser::SetContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitSet(this); +} + + +std::any ExtendedDiracParser::SetContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitSet(this); + else + return visitor->visitChildren(this); +} + + +ExtendedDiracParser::SetContext* ExtendedDiracParser::set() { + return set(0); +} + +ExtendedDiracParser::SetContext* ExtendedDiracParser::set(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExtendedDiracParser::SetContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExtendedDiracParser::SetContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 2; + enterRecursionRule(_localctx, 2, ExtendedDiracParser::RuleSet, precedence); + + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(40); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 1, _ctx)) { + case 1: { + setState(26); + match(ExtendedDiracParser::T__2); + setState(27); + set(0); + setState(28); + match(ExtendedDiracParser::T__3); + break; + } + + case 2: { + setState(30); + match(ExtendedDiracParser::T__4); + setState(31); + diracs(0); + setState(32); + match(ExtendedDiracParser::T__5); + break; + } + + case 3: { + setState(34); + match(ExtendedDiracParser::T__4); + setState(35); + dirac(0); + setState(36); + match(ExtendedDiracParser::T__6); + setState(37); + ijklens(0); + setState(38); + match(ExtendedDiracParser::T__5); + break; + } + + default: + break; + } + _ctx->stop = _input->LT(-1); + setState(54); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 3, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + setState(52); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 2, _ctx)) { + case 1: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleSet); + setState(42); + + if (!(precpred(_ctx, 2))) throw FailedPredicateException(this, "precpred(_ctx, 2)"); + setState(43); + antlrcpp::downCast(_localctx)->op = match(ExtendedDiracParser::PROD); + setState(44); + set(3); + break; + } + + case 2: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleSet); + setState(45); + + if (!(precpred(_ctx, 1))) throw FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(46); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExtendedDiracParser::INTERSECTION + + || _la == ExtendedDiracParser::UNION)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(47); + set(2); + break; + } + + case 3: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleSet); + setState(48); + + if (!(precpred(_ctx, 6))) throw FailedPredicateException(this, "precpred(_ctx, 6)"); + setState(49); + match(ExtendedDiracParser::T__1); + setState(50); + antlrcpp::downCast(_localctx)->n = match(ExtendedDiracParser::DIGITS); + setState(51); + + if (!(isNonZero((antlrcpp::downCast(_localctx)->n != nullptr ? antlrcpp::downCast(_localctx)->n->getText() : "")))) throw FailedPredicateException(this, "isNonZero($n.text)"); + break; + } + + default: + break; + } + } + setState(56); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 3, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- DiracsContext ------------------------------------------------------------------ + +ExtendedDiracParser::DiracsContext::DiracsContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +ExtendedDiracParser::DiracContext* ExtendedDiracParser::DiracsContext::dirac() { + return getRuleContext(0); +} + +ExtendedDiracParser::DiracsContext* ExtendedDiracParser::DiracsContext::diracs() { + return getRuleContext(0); +} + + +size_t ExtendedDiracParser::DiracsContext::getRuleIndex() const { + return ExtendedDiracParser::RuleDiracs; +} + +void ExtendedDiracParser::DiracsContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterDiracs(this); +} + +void ExtendedDiracParser::DiracsContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitDiracs(this); +} + + +std::any ExtendedDiracParser::DiracsContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitDiracs(this); + else + return visitor->visitChildren(this); +} + + +ExtendedDiracParser::DiracsContext* ExtendedDiracParser::diracs() { + return diracs(0); +} + +ExtendedDiracParser::DiracsContext* ExtendedDiracParser::diracs(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExtendedDiracParser::DiracsContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExtendedDiracParser::DiracsContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 4; + enterRecursionRule(_localctx, 4, ExtendedDiracParser::RuleDiracs, precedence); + + + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(58); + dirac(0); + _ctx->stop = _input->LT(-1); + setState(65); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 4, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleDiracs); + setState(60); + + if (!(precpred(_ctx, 1))) throw FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(61); + match(ExtendedDiracParser::T__7); + setState(62); + dirac(0); + } + setState(67); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 4, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- DiracContext ------------------------------------------------------------------ + +ExtendedDiracParser::DiracContext::DiracContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +ExtendedDiracParser::CketContext* ExtendedDiracParser::DiracContext::cket() { + return getRuleContext(0); +} + +ExtendedDiracParser::DiracContext* ExtendedDiracParser::DiracContext::dirac() { + return getRuleContext(0); +} + +tree::TerminalNode* ExtendedDiracParser::DiracContext::ADD() { + return getToken(ExtendedDiracParser::ADD, 0); +} + +tree::TerminalNode* ExtendedDiracParser::DiracContext::SUB() { + return getToken(ExtendedDiracParser::SUB, 0); +} + + +size_t ExtendedDiracParser::DiracContext::getRuleIndex() const { + return ExtendedDiracParser::RuleDirac; +} + +void ExtendedDiracParser::DiracContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterDirac(this); +} + +void ExtendedDiracParser::DiracContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitDirac(this); +} + + +std::any ExtendedDiracParser::DiracContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitDirac(this); + else + return visitor->visitChildren(this); +} + + +ExtendedDiracParser::DiracContext* ExtendedDiracParser::dirac() { + return dirac(0); +} + +ExtendedDiracParser::DiracContext* ExtendedDiracParser::dirac(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExtendedDiracParser::DiracContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExtendedDiracParser::DiracContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 6; + enterRecursionRule(_localctx, 6, ExtendedDiracParser::RuleDirac, precedence); + + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(69); + cket(); + _ctx->stop = _input->LT(-1); + setState(76); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleDirac); + setState(71); + + if (!(precpred(_ctx, 1))) throw FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(72); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExtendedDiracParser::ADD + + || _la == ExtendedDiracParser::SUB)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(73); + cket(); + } + setState(78); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 5, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- CketContext ------------------------------------------------------------------ + +ExtendedDiracParser::CketContext::CketContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* ExtendedDiracParser::CketContext::KET() { + return getToken(ExtendedDiracParser::KET, 0); +} + +ExtendedDiracParser::ComplexContext* ExtendedDiracParser::CketContext::complex() { + return getRuleContext(0); +} + +tree::TerminalNode* ExtendedDiracParser::CketContext::SUB() { + return getToken(ExtendedDiracParser::SUB, 0); +} + +tree::TerminalNode* ExtendedDiracParser::CketContext::MUL() { + return getToken(ExtendedDiracParser::MUL, 0); +} + + +size_t ExtendedDiracParser::CketContext::getRuleIndex() const { + return ExtendedDiracParser::RuleCket; +} + +void ExtendedDiracParser::CketContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterCket(this); +} + +void ExtendedDiracParser::CketContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitCket(this); +} + + +std::any ExtendedDiracParser::CketContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitCket(this); + else + return visitor->visitChildren(this); +} + +ExtendedDiracParser::CketContext* ExtendedDiracParser::cket() { + CketContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 8, ExtendedDiracParser::RuleCket); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(84); + _errHandler->sync(this); + + switch (getInterpreter()->adaptivePredict(_input, 6, _ctx)) { + case 1: { + setState(79); + complex(0); + break; + } + + case 2: { + setState(80); + complex(0); + setState(81); + antlrcpp::downCast(_localctx)->op = match(ExtendedDiracParser::MUL); + break; + } + + case 3: { + setState(83); + match(ExtendedDiracParser::SUB); + break; + } + + default: + break; + } + setState(86); + antlrcpp::downCast(_localctx)->ketToken = match(ExtendedDiracParser::KET); + + std::string text = (antlrcpp::downCast(_localctx)->ketToken != nullptr ? antlrcpp::downCast(_localctx)->ketToken->getText() : ""); // Get the full text of the KET token + std::string state = text.substr(1, text.length() - 2); // Remove the first and last characters + + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- ComplexContext ------------------------------------------------------------------ + +ExtendedDiracParser::ComplexContext::ComplexContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +std::vector ExtendedDiracParser::ComplexContext::complex() { + return getRuleContexts(); +} + +ExtendedDiracParser::ComplexContext* ExtendedDiracParser::ComplexContext::complex(size_t i) { + return getRuleContext(i); +} + +tree::TerminalNode* ExtendedDiracParser::ComplexContext::SUB() { + return getToken(ExtendedDiracParser::SUB, 0); +} + +ExtendedDiracParser::AngleContext* ExtendedDiracParser::ComplexContext::angle() { + return getRuleContext(0); +} + +tree::TerminalNode* ExtendedDiracParser::ComplexContext::DIGITS() { + return getToken(ExtendedDiracParser::DIGITS, 0); +} + +tree::TerminalNode* ExtendedDiracParser::ComplexContext::NAME() { + return getToken(ExtendedDiracParser::NAME, 0); +} + +tree::TerminalNode* ExtendedDiracParser::ComplexContext::MUL() { + return getToken(ExtendedDiracParser::MUL, 0); +} + +tree::TerminalNode* ExtendedDiracParser::ComplexContext::DIV() { + return getToken(ExtendedDiracParser::DIV, 0); +} + +tree::TerminalNode* ExtendedDiracParser::ComplexContext::ADD() { + return getToken(ExtendedDiracParser::ADD, 0); +} + + +size_t ExtendedDiracParser::ComplexContext::getRuleIndex() const { + return ExtendedDiracParser::RuleComplex; +} + +void ExtendedDiracParser::ComplexContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterComplex(this); +} + +void ExtendedDiracParser::ComplexContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitComplex(this); +} + + +std::any ExtendedDiracParser::ComplexContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitComplex(this); + else + return visitor->visitChildren(this); +} + + +ExtendedDiracParser::ComplexContext* ExtendedDiracParser::complex() { + return complex(0); +} + +ExtendedDiracParser::ComplexContext* ExtendedDiracParser::complex(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExtendedDiracParser::ComplexContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExtendedDiracParser::ComplexContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 10; + enterRecursionRule(_localctx, 10, ExtendedDiracParser::RuleComplex, precedence); + + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(108); + _errHandler->sync(this); + switch (_input->LA(1)) { + case ExtendedDiracParser::T__2: { + setState(90); + match(ExtendedDiracParser::T__2); + setState(91); + complex(0); + setState(92); + match(ExtendedDiracParser::T__3); + break; + } + + case ExtendedDiracParser::SUB: { + setState(94); + match(ExtendedDiracParser::SUB); + setState(95); + complex(6); + break; + } + + case ExtendedDiracParser::T__8: { + setState(96); + match(ExtendedDiracParser::T__8); + setState(97); + angle(); + setState(98); + match(ExtendedDiracParser::T__3); + break; + } + + case ExtendedDiracParser::T__9: { + setState(100); + match(ExtendedDiracParser::T__9); + setState(101); + angle(); + setState(102); + match(ExtendedDiracParser::T__3); + break; + } + + case ExtendedDiracParser::DIGITS: { + setState(104); + match(ExtendedDiracParser::DIGITS); + break; + } + + case ExtendedDiracParser::T__10: { + setState(105); + match(ExtendedDiracParser::T__10); + break; + } + + case ExtendedDiracParser::NAME: { + setState(106); + antlrcpp::downCast(_localctx)->var = match(ExtendedDiracParser::NAME); + if (!predefinedVars.contains((antlrcpp::downCast(_localctx)->var != nullptr ? antlrcpp::downCast(_localctx)->var->getText() : ""))) isSymbolicAutomaton = true; + break; + } + + default: + throw NoViableAltException(this); + } + _ctx->stop = _input->LT(-1); + setState(124); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 9, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + setState(122); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 8, _ctx)) { + case 1: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleComplex); + setState(110); + + if (!(precpred(_ctx, 10))) throw FailedPredicateException(this, "precpred(_ctx, 10)"); + setState(111); + complex(11); + break; + } + + case 2: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleComplex); + setState(112); + + if (!(precpred(_ctx, 9))) throw FailedPredicateException(this, "precpred(_ctx, 9)"); + setState(113); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExtendedDiracParser::DIV + + || _la == ExtendedDiracParser::MUL)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(114); + complex(10); + break; + } + + case 3: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleComplex); + setState(115); + + if (!(precpred(_ctx, 8))) throw FailedPredicateException(this, "precpred(_ctx, 8)"); + setState(116); + antlrcpp::downCast(_localctx)->op = _input->LT(1); + _la = _input->LA(1); + if (!(_la == ExtendedDiracParser::ADD + + || _la == ExtendedDiracParser::SUB)) { + antlrcpp::downCast(_localctx)->op = _errHandler->recoverInline(this); + } + else { + _errHandler->reportMatch(this); + consume(); + } + setState(117); + complex(9); + break; + } + + case 4: { + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleComplex); + setState(118); + + if (!(precpred(_ctx, 11))) throw FailedPredicateException(this, "precpred(_ctx, 11)"); + setState(119); + match(ExtendedDiracParser::T__1); + setState(120); + antlrcpp::downCast(_localctx)->n = match(ExtendedDiracParser::DIGITS); + setState(121); + + if (!(isNonZero((antlrcpp::downCast(_localctx)->n != nullptr ? antlrcpp::downCast(_localctx)->n->getText() : "")))) throw FailedPredicateException(this, "isNonZero($n.text)"); + break; + } + + default: + break; + } + } + setState(126); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 9, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- AngleContext ------------------------------------------------------------------ + +ExtendedDiracParser::AngleContext::AngleContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* ExtendedDiracParser::AngleContext::DIV() { + return getToken(ExtendedDiracParser::DIV, 0); +} + +std::vector ExtendedDiracParser::AngleContext::DIGITS() { + return getTokens(ExtendedDiracParser::DIGITS); +} + +tree::TerminalNode* ExtendedDiracParser::AngleContext::DIGITS(size_t i) { + return getToken(ExtendedDiracParser::DIGITS, i); +} + +tree::TerminalNode* ExtendedDiracParser::AngleContext::SUB() { + return getToken(ExtendedDiracParser::SUB, 0); +} + + +size_t ExtendedDiracParser::AngleContext::getRuleIndex() const { + return ExtendedDiracParser::RuleAngle; +} + +void ExtendedDiracParser::AngleContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterAngle(this); +} + +void ExtendedDiracParser::AngleContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitAngle(this); +} + + +std::any ExtendedDiracParser::AngleContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitAngle(this); + else + return visitor->visitChildren(this); +} + +ExtendedDiracParser::AngleContext* ExtendedDiracParser::angle() { + AngleContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 12, ExtendedDiracParser::RuleAngle); + size_t _la = 0; + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + setState(138); + _errHandler->sync(this); + switch (getInterpreter()->adaptivePredict(_input, 12, _ctx)) { + case 1: { + enterOuterAlt(_localctx, 1); + setState(128); + _errHandler->sync(this); + + _la = _input->LA(1); + if (_la == ExtendedDiracParser::SUB) { + setState(127); + match(ExtendedDiracParser::SUB); + } + setState(130); + antlrcpp::downCast(_localctx)->x = match(ExtendedDiracParser::DIGITS); + setState(131); + match(ExtendedDiracParser::DIV); + setState(132); + antlrcpp::downCast(_localctx)->y = match(ExtendedDiracParser::DIGITS); + setState(133); + + if (!(isNonZero((antlrcpp::downCast(_localctx)->y != nullptr ? antlrcpp::downCast(_localctx)->y->getText() : "")))) throw FailedPredicateException(this, "isNonZero($y.text)"); + break; + } + + case 2: { + enterOuterAlt(_localctx, 2); + setState(135); + _errHandler->sync(this); + + _la = _input->LA(1); + if (_la == ExtendedDiracParser::SUB) { + setState(134); + match(ExtendedDiracParser::SUB); + } + setState(137); + antlrcpp::downCast(_localctx)->n = match(ExtendedDiracParser::DIGITS); + break; + } + + default: + break; + } + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +//----------------- IjklensContext ------------------------------------------------------------------ + +ExtendedDiracParser::IjklensContext::IjklensContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +ExtendedDiracParser::IjklenContext* ExtendedDiracParser::IjklensContext::ijklen() { + return getRuleContext(0); +} + +ExtendedDiracParser::IjklensContext* ExtendedDiracParser::IjklensContext::ijklens() { + return getRuleContext(0); +} + + +size_t ExtendedDiracParser::IjklensContext::getRuleIndex() const { + return ExtendedDiracParser::RuleIjklens; +} + +void ExtendedDiracParser::IjklensContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterIjklens(this); +} + +void ExtendedDiracParser::IjklensContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitIjklens(this); +} + + +std::any ExtendedDiracParser::IjklensContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitIjklens(this); + else + return visitor->visitChildren(this); +} + + +ExtendedDiracParser::IjklensContext* ExtendedDiracParser::ijklens() { + return ijklens(0); +} + +ExtendedDiracParser::IjklensContext* ExtendedDiracParser::ijklens(int precedence) { + ParserRuleContext *parentContext = _ctx; + size_t parentState = getState(); + ExtendedDiracParser::IjklensContext *_localctx = _tracker.createInstance(_ctx, parentState); + ExtendedDiracParser::IjklensContext *previousContext = _localctx; + (void)previousContext; // Silence compiler, in case the context is not used by generated code. + size_t startState = 14; + enterRecursionRule(_localctx, 14, ExtendedDiracParser::RuleIjklens, precedence); + + + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + unrollRecursionContexts(parentContext); + }); + try { + size_t alt; + enterOuterAlt(_localctx, 1); + setState(141); + ijklen(); + _ctx->stop = _input->LT(-1); + setState(148); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 13, _ctx); + while (alt != 2 && alt != atn::ATN::INVALID_ALT_NUMBER) { + if (alt == 1) { + if (!_parseListeners.empty()) + triggerExitRuleEvent(); + previousContext = _localctx; + _localctx = _tracker.createInstance(parentContext, parentState); + pushNewRecursionContext(_localctx, startState, RuleIjklens); + setState(143); + + if (!(precpred(_ctx, 1))) throw FailedPredicateException(this, "precpred(_ctx, 1)"); + setState(144); + match(ExtendedDiracParser::T__7); + setState(145); + ijklen(); + } + setState(150); + _errHandler->sync(this); + alt = getInterpreter()->adaptivePredict(_input, 13, _ctx); + } + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + return _localctx; +} + +//----------------- IjklenContext ------------------------------------------------------------------ + +ExtendedDiracParser::IjklenContext::IjklenContext(ParserRuleContext *parent, size_t invokingState) + : ParserRuleContext(parent, invokingState) { +} + +tree::TerminalNode* ExtendedDiracParser::IjklenContext::NAME() { + return getToken(ExtendedDiracParser::NAME, 0); +} + +tree::TerminalNode* ExtendedDiracParser::IjklenContext::DIGITS() { + return getToken(ExtendedDiracParser::DIGITS, 0); +} + + +size_t ExtendedDiracParser::IjklenContext::getRuleIndex() const { + return ExtendedDiracParser::RuleIjklen; +} + +void ExtendedDiracParser::IjklenContext::enterRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->enterIjklen(this); +} + +void ExtendedDiracParser::IjklenContext::exitRule(tree::ParseTreeListener *listener) { + auto parserListener = dynamic_cast(listener); + if (parserListener != nullptr) + parserListener->exitIjklen(this); +} + + +std::any ExtendedDiracParser::IjklenContext::accept(tree::ParseTreeVisitor *visitor) { + if (auto parserVisitor = dynamic_cast(visitor)) + return parserVisitor->visitIjklen(this); + else + return visitor->visitChildren(this); +} + +ExtendedDiracParser::IjklenContext* ExtendedDiracParser::ijklen() { + IjklenContext *_localctx = _tracker.createInstance(_ctx, getState()); + enterRule(_localctx, 16, ExtendedDiracParser::RuleIjklen); + +#if __cplusplus > 201703L + auto onExit = finally([=, this] { +#else + auto onExit = finally([=] { +#endif + exitRule(); + }); + try { + enterOuterAlt(_localctx, 1); + setState(151); + match(ExtendedDiracParser::T__6); + setState(152); + antlrcpp::downCast(_localctx)->var = match(ExtendedDiracParser::NAME); + setState(153); + match(ExtendedDiracParser::T__11); + setState(154); + antlrcpp::downCast(_localctx)->len = match(ExtendedDiracParser::DIGITS); + setState(155); + + if (!(isASingleLetter((antlrcpp::downCast(_localctx)->var != nullptr ? antlrcpp::downCast(_localctx)->var->getText() : "")) && isNonZero((antlrcpp::downCast(_localctx)->len != nullptr ? antlrcpp::downCast(_localctx)->len->getText() : "")))) throw FailedPredicateException(this, "isASingleLetter($var.text) && isNonZero($len.text)"); + + } + catch (RecognitionException &e) { + _errHandler->reportError(this, e); + _localctx->exception = std::current_exception(); + _errHandler->recover(this, _localctx->exception); + } + + return _localctx; +} + +bool ExtendedDiracParser::sempred(RuleContext *context, size_t ruleIndex, size_t predicateIndex) { + switch (ruleIndex) { + case 1: return setSempred(antlrcpp::downCast(context), predicateIndex); + case 2: return diracsSempred(antlrcpp::downCast(context), predicateIndex); + case 3: return diracSempred(antlrcpp::downCast(context), predicateIndex); + case 5: return complexSempred(antlrcpp::downCast(context), predicateIndex); + case 6: return angleSempred(antlrcpp::downCast(context), predicateIndex); + case 7: return ijklensSempred(antlrcpp::downCast(context), predicateIndex); + case 8: return ijklenSempred(antlrcpp::downCast(context), predicateIndex); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::setSempred(SetContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 0: return precpred(_ctx, 2); + case 1: return precpred(_ctx, 1); + case 2: return precpred(_ctx, 6); + case 3: return isNonZero((antlrcpp::downCast(_localctx)->n != nullptr ? antlrcpp::downCast(_localctx)->n->getText() : "")); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::diracsSempred(DiracsContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 4: return precpred(_ctx, 1); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::diracSempred(DiracContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 5: return precpred(_ctx, 1); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::complexSempred(ComplexContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 6: return precpred(_ctx, 10); + case 7: return precpred(_ctx, 9); + case 8: return precpred(_ctx, 8); + case 9: return precpred(_ctx, 11); + case 10: return isNonZero((antlrcpp::downCast(_localctx)->n != nullptr ? antlrcpp::downCast(_localctx)->n->getText() : "")); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::angleSempred(AngleContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 11: return isNonZero((antlrcpp::downCast(_localctx)->y != nullptr ? antlrcpp::downCast(_localctx)->y->getText() : "")); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::ijklensSempred(IjklensContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 12: return precpred(_ctx, 1); + + default: + break; + } + return true; +} + +bool ExtendedDiracParser::ijklenSempred(IjklenContext *_localctx, size_t predicateIndex) { + switch (predicateIndex) { + case 13: return isASingleLetter((antlrcpp::downCast(_localctx)->var != nullptr ? antlrcpp::downCast(_localctx)->var->getText() : "")) && isNonZero((antlrcpp::downCast(_localctx)->len != nullptr ? antlrcpp::downCast(_localctx)->len->getText() : "")); + + default: + break; + } + return true; +} + +void ExtendedDiracParser::initialize() { +#if ANTLR4_USE_THREAD_LOCAL_CACHE + extendeddiracParserInitialize(); +#else + ::antlr4::internal::call_once(extendeddiracParserOnceFlag, extendeddiracParserInitialize); +#endif +} diff --git a/src/ExtendedDirac/ExtendedDiracVisitor.cpp b/src/ExtendedDirac/ExtendedDiracVisitor.cpp new file mode 100644 index 000000000..3cd70d328 --- /dev/null +++ b/src/ExtendedDirac/ExtendedDiracVisitor.cpp @@ -0,0 +1,7 @@ + +// Generated from src/ExtendedDirac/ExtendedDirac.g4 by ANTLR 4.13.2 + + +#include "ExtendedDiracVisitor.h" + + diff --git a/src/timbuk_parser-nobison.cc b/src/timbuk_parser-nobison.cc index 9a6603455..b9a6344aa 100644 --- a/src/timbuk_parser-nobison.cc +++ b/src/timbuk_parser-nobison.cc @@ -29,6 +29,17 @@ #include "autoq/parsing/symboliccomplex_parser.hh" #include "autoq/parsing/constraint_parser.hh" +// ANTLR4 headers +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" +#pragma GCC diagnostic ignored "-Woverloaded-virtual" +#pragma GCC diagnostic ignored "-Weffc++" +#include "antlr4-runtime.h" +#include "autoq/parsing/ExtendedDirac/ExtendedDiracLexer.h" +#include "autoq/parsing/ExtendedDirac/ExtendedDiracParser.h" +#pragma GCC diagnostic pop +#include "autoq/parsing/ExtendedDirac/EvaluationVisitor.h" + // Thanks to https://github.com/boostorg/multiprecision/issues/297 boost::multiprecision::cpp_int bin_2_dec(const std::string_view& num) { @@ -1432,15 +1443,31 @@ std::vector state_expansion(std::string line, std::vector orde return result; } +class CustomErrorListener : public antlr4::BaseErrorListener { +public: + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-parameter" + void syntaxError(antlr4::Recognizer *recognizer, + antlr4::Token *offendingSymbol, + size_t line, size_t charPositionInLine, + const std::string &msg, + std::exception_ptr e) override { + THROW_AUTOQ_ERROR("Parsing Error: Line " + std::to_string(line) + ":" + std::to_string(charPositionInLine) + + " in ExtendedDirac.g4 - " + msg); + } + #pragma GCC diagnostic pop +}; + template -AUTOQ::Automata AUTOQ::Parsing::TimbukParser::parse_hsl_from_istream(std::istream *is, bool &do_not_throw_term_undefined_error, const std::map &constants, const std::map &predicates) { +AUTOQ::Automata AUTOQ::Parsing::TimbukParser::parse_extended_dirac_from_istream(std::istream *is, bool &do_not_throw_term_undefined_error, const std::map &constants, const std::map &predicates) { bool start_transitions = false; - bool get_ordering = false; + // bool get_ordering = false; AUTOQ::Automata aut_final; std::string line; //reordering std::vector ordering_map; + std::string extended_dirac; while (std::getline(*is, line)) { @@ -1450,12 +1477,12 @@ AUTOQ::Automata AUTOQ::Parsing::TimbukParser::parse_hsl_from_ist { continue; } - if (line == "Variable Order") - { - std::getline(*is, line); - ordering_map = qubit_ordering(line); - get_ordering = true; - } + // if (line == "Variable Order") + // { + // std::getline(*is, line); + // ordering_map = qubit_ordering(line); + // get_ordering = true; + // } else if (!start_transitions) { if (std::regex_search(line, std::regex("Extended +Dirac"))) @@ -1468,49 +1495,76 @@ AUTOQ::Automata AUTOQ::Parsing::TimbukParser::parse_hsl_from_ist } // processing states else { - auto a = do_not_throw_term_undefined_error; - //to do : make line with reordering e.g. |ii000> -> |00000> || |11000> ... make two lines then reorder - if(get_ordering) - { - std::vector equation_expension = state_expansion(line, ordering_map); - for(unsigned i = 0 ; i < equation_expension.size(); i++) - { - auto aut = from_line_to_automaton(equation_expension[i], constants, predicates, do_not_throw_term_undefined_error); - if (a && !do_not_throw_term_undefined_error) { - return {}; - } - aut_final = aut_final.operator||(aut); - aut_final.reduce(); - } - } - else - { - auto aut = from_line_to_automaton(line, constants, predicates,do_not_throw_term_undefined_error); - if (a && !do_not_throw_term_undefined_error) { - return {}; - } - aut_final = aut_final.operator||(aut); - } - aut_final.reduce(); + // auto a = do_not_throw_term_undefined_error; + // //to do : make line with reordering e.g. |ii000> -> |00000> || |11000> ... make two lines then reorder + // if(get_ordering) + // { + // std::vector equation_expension = state_expansion(line, ordering_map); + // for(unsigned i = 0 ; i < equation_expension.size(); i++) + // { + // auto aut = from_line_to_automaton(equation_expension[i], constants, predicates, do_not_throw_term_undefined_error); + // if (a && !do_not_throw_term_undefined_error) { + // return {}; + // } + // aut_final = aut_final.operator||(aut); + // aut_final.reduce(); + // } + // } + // else + // { + // auto aut = from_line_to_automaton(line, constants, predicates,do_not_throw_term_undefined_error); + // if (a && !do_not_throw_term_undefined_error) { + // return {}; + // } + // aut_final = aut_final.operator||(aut); + // } + // aut_final.reduce(); + extended_dirac += line; } } + + /**************************************** + * Parse the Extended Dirac with ANTLR v4. + *****************************************/ + // std::cout << extended_dirac << std::endl; + antlr4::ANTLRInputStream inputStream(extended_dirac); + ExtendedDiracLexer lexer(&inputStream); + antlr4::CommonTokenStream tokens(&lexer); + std::set vars; + for (const auto &kv : constants) + vars.insert(kv.first); + for (const auto &kv : predicates) + vars.insert(kv.first); + ExtendedDiracParser parser(&tokens); + parser.predefinedVars = vars; + parser.removeErrorListeners(); // Remove the default error listener + CustomErrorListener errorListener; + parser.addErrorListener(&errorListener); // Add a custom error listener + ExtendedDiracParser::ExtendedDiracContext* tree = parser.extendedDirac(); // Parse the input + // std::cout << parser.isSymbolicAutomaton << std::endl; + // std::cout << tree->toStringTree(&parser) << std::endl; + + if (parser.isSymbolicAutomaton && std::is_same_v) { + do_not_throw_term_undefined_error = false; + return {}; + } + EvaluationVisitor visitor(constants, predicates); + return std::any_cast>(visitor.visit(tree)); // Evaluate using the visitor + /****************************************/ + // DO NOT fraction_simplification() here since the resulting automaton may be used as pre.spec // and in this case all k's must be the same. - return aut_final; + // return aut_final; } template -AUTOQ::Automata parse_hsl(const std::string& str, const std::map &constants, const std::map &predicates, bool &do_not_throw_term_undefined_error) { +AUTOQ::Automata parse_extended_dirac(const std::string& str, const std::map &constants, const std::map &predicates, bool &do_not_throw_term_undefined_error) { std::istringstream inputStream(str); // delimited by '\n' - auto aut = AUTOQ::Parsing::TimbukParser::parse_hsl_from_istream(&inputStream, do_not_throw_term_undefined_error, constants, predicates); + auto aut = AUTOQ::Parsing::TimbukParser::parse_extended_dirac_from_istream(&inputStream, do_not_throw_term_undefined_error, constants, predicates); // aut.print(str); return aut; } -// template -// AUTOQ::Automata AUTOQ::Parsing::TimbukParser::ReadAutomaton(const std::string& filepath) { -// return ParseString(AUTOQ::Util::ReadFile(filepath)); -// } template AUTOQ::Automata AUTOQ::Parsing::TimbukParser::ReadAutomaton(const std::string& filepath) { bool do_not_throw_term_undefined_error = false; @@ -1642,7 +1696,7 @@ try { } else if (boost::algorithm::ends_with(filepath, ".aut")) { result = parse_timbuk(automaton); } else if (boost::algorithm::ends_with(filepath, ".hsl")) { - result = parse_hsl(automaton, constants, predicates, do_not_throw_term_undefined_error); + result = parse_extended_dirac(automaton, constants, predicates, do_not_throw_term_undefined_error); } else { THROW_AUTOQ_ERROR("The filename extension is not supported."); }