Category : antlr4

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

I am trying to compile my own ANTLR4 parser in C++ #include "nibble.h" using namespace antlr4; using namespace nibble; int main(int argc, const char* argv[]){ const std::string file_name = argv[1]; ANTLRInputStream input(file_name); return 0; } but when I compile it by typing g++ nibblec.cpp -o nibblec -I /usr/local/include/antlr4-runtime I get /usr/bin/ld: /tmp/ccqG8KT4.o: warning: relocation against ..

Read more

I use antlr4 to parse C++ using antrl visitors, when I have extern "C" in my code I will get the following error, line 1:7 no viable alternative at input ‘extern"C"’ line 10:0 mismatched input ‘}’ expecting <EOF> This is the sample code I fail to parse using antlr, extern "C" { #include <stdio.h> #include ..

Read more

Is there a way to distinguish language targets and provide appropriate version of @members in a grammar file? Different language targets use different comment and syntax. I would like to maintain the same grammar file for different target languages. For Cpp (C++) target: @members { // C++ target: bool a_boolean = 0; } For Python3 ..

Read more

I am newble in antlr and till now I know how to parse the source file and access to visitor and listener. I want to make indicator in the source file ex. //@start and //@end and I want to access to this indicator by using listener ,, but the issue I faced the comments skiped ..

Read more

I’m parsing C++ using ANTLR4 grammars and I have a basic code that I cannot get without having too much noisy/unrelated output. The code I’m trying to parse is simple, Person *p; char *buf; int *i; I tried visiting on multiplicativeExpression, PointerDeclarator etc but I either didn’t get useful result or I was getting very ..

Read more

I am using the below ANTLR grammar for parsing my code. https://github.com/antlr/grammars-v4/tree/master/cpp Here "08" is not identifying as an integer literal. TEST_F(suite_name_test_p, 08) { //… } I have made the following changes to fix this error: Decimalliteral //: NONZERODIGIT (”’? DIGIT)* //old : NONZERODIGIT* (”’? DIGIT)+ // changed to ; But with these changes, octal ..

Read more

I’m trying to write a cmake file by following this git repo: https://github.com/paraka/c-compiler-antlr4-cpp-llvm However, I have the issue on 100% of CMake: ld: symbol(s) not found for architecture x86_64. Its’ full error message is this: [100%] Linking CXX executable pryst Undefined symbols for architecture x86_64: "antlrcpptest::PrystLexer::PrystLexer(antlr4::CharStream*)", referenced from: Compiler::compile() in compiler.cpp.o "antlrcpptest::PrystLexer::~PrystLexer()", referenced from: Compiler::compile() ..

Read more