Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete example of visitor or expression processor. #4365

Open
vega0 opened this issue Jul 21, 2023 · 1 comment
Open

Complete example of visitor or expression processor. #4365

vega0 opened this issue Jul 21, 2023 · 1 comment

Comments

@vega0
Copy link

vega0 commented Jul 21, 2023

is there complete possible example of visitor or expression processor on C++? Not sure how to make this work.

#include <iostream>
#include <antlr4-runtime.h>

#include "ЧислаLexer.h"
#include "ЧислаParser.h"
#include "ЧислаVisitor.h"

using namespace std;
//using namespace antlr4;
using namespace парсер;



class  ЧислаBaseVisitor : public ЧислаVisitor {
public:

  virtual std::any visitAОбщееЧисло(ЧислаParser::AОбщееЧислоContext *ctx) override {
    return visitChildren(ctx);
  }

  virtual std::any visitЧислоРимское(ЧислаParser::ЧислоРимскоеContext *ctx) override {
    return visitChildren(ctx);
  }

  virtual std::any visitЧислоВремени(ЧислаParser::ЧислоВремениContext *ctx) override {
    return visitChildren(ctx);
  }

  virtual std::any visitЧисло(ЧислаParser::ЧислоContext *ctx) override {
    return visitChildren(ctx);
  }


};


int main(int argc, const char* argv[]) {
/*
    std::ifstream stream;

    stream.open("input.scene");
*/

    antlr4::ANTLRInputStream input( "0124646ABAB" /*"123.0b 010101001e12"*/);
    ЧислаLexer lexer(&input);
    antlr4::CommonTokenStream tokens(&lexer);
    tokens.fill();

    ЧислаParser parser(&tokens);

    std::cout << "[] Парсер построен: " << parser.getBuildParseTree() << " " << parser.getSourceName() << std::endl;

    antlr4::tree::ParseTree *update_tree = parser.stored_definition();

    //std::cout << tree->toStringTree(&parser) << std::endl;
    return 0;
}


@vega0
Copy link
Author

vega0 commented Jul 22, 2023

4.12.1 version doesn't have https://github.com/GiuMaz/antlr4-cpp-example/blob/master/src/main.cpp

.input method or .expression or .expr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant