Category : antlr4

I’m working on an ANTLR4 project in C++ that uses listeners. In my listener I utilize the TokenStreamRewriter replace method to make changes to the TokenStream. I then use the following code to call the getText method to retrieve these changes for a specific Interval: antlr4::misc::Interval sqInterval = context->sq->getSourceInterval(); queryText = rewrite->getText(sqInterval); The call to ..

Read more

I’m compiling some cpp files with: $ ​g++ -c –std=c++17 -I/antlr4/runtime/Cpp/runtime/src/ *.cpp And everything goes fine: $ ls -l *.cpp *.o -rw-r–r– 1 root root 76637 Dec 1 14:33 Java8Lexer.cpp -rw-r–r– 1 root root 370768 Dec 1 15:13 Java8Lexer.o -rw-r–r– 1 root root 925012 Dec 1 14:33 Java8Parser.cpp -rw-r–r– 1 root root 5037896 Dec 1 ..

Read more

I’m still new at Antlr4, and I have what is probably a really stupid problem. Here’s a fragment from my .g4 file: assignStatement : VariableName ‘=’ expression ‘;’ ; expression : (value | VariableName) | bin_op='(‘ expression ‘)’ | expression UNARY_PRE_OR_POST | (UNARY_PRE_OR_POST | ‘+’ | ‘-‘ | ‘!’ | ‘~’ | type_cast) expression | ..

Read more

Blow is my grammar file. grammar My; tokens { DELIMITER } string:SINGLE_QUOTED_TEXT; SINGLE_QUOTED_TEXT: ( ”’ (.)*? ”’ )+ ; I’m trying to use this to accpet all string(It’s part of mysql’s g4 actually). Then I use this code to test it: #include "MyLexer.h" #include "MyParser.h" #include <string> using namespace My; int main() { std::string s ..

Read more

I’m using antlr4-4.9.2 on Windows 10. I want to use antlr4 in c++, and here’s part of my CMakeLists.txt file(GLOB antlr4-cpp-src third_party/antlr4-cpp-runtime-4.9.2/src/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/atn/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/dfa/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/misc/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/support/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/tree/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/tree/pattern/*.cpp third_party/antlr4-cpp-runtime-4.9.2/src/tree/xpath/*.cpp ) add_library (antlr4-cpp-runtime ${antlr4-cpp-src}) add_executable(MiniSql ${src_dir} src/main.cpp) target_link_libraries(MiniSql antlr4-cpp-runtime) But I got 171 errors and warnings. For example, in BufferedTokenStream, TokenSource *BufferedTokenStream::getTokenSource() const { return _tokenSource; ..

Read more

I have a function like this to get the the AST from a file. antlr4::tree::ParseTree *get_ast(std::string &filename) { std::ifstream stream; stream.open(filename); antlr4::ANTLRInputStream input(stream); Lexer lexer(&input); antlr4::CommonTokenStream tokens(&lexer); Parser parser(&tokens); antlr4::tree::ParseTree *tree = parser.program(); return tree; } But when using the return value, it seems that what tree is pointing to is already cleared (on the ..

Read more