macroxmu
macroxmu

Reputation: 65

Does ANTLR4 NOT support ASTLabelType?

I'm using ANTLR4 to build AST tree, I download g4 file from: https://github.com/antlr/grammars-v4/tree/master/sqlite Add the option in the head of g4 file:

options{  
    output=AST;  
    ASTLabelType=CommonTree;  
    language=Java;  
}

but while compile g4 file, it output :

ANTLR Tool v4.6 (D:\antlr-4.6-complete.jar)
SQLite.g4 -o C:\Users\macro\workspace\tdsql\target\generated-sources\antlr4 -listener -no-visitor -encoding UTF-8
warning(83): SQLite.g4:34:4: unsupported option output
warning(83): SQLite.g4:35:4: unsupported option ASTLabelType

does antlr4 not support using ASTLabelType to build a AST tree? and how can I build a AST tree with antlr4?

Upvotes: 0

Views: 652

Answers (1)

user7564947
user7564947

Reputation:

I'm an Antlr newbie myself so there are better-qualified people who can answer this. That said, the AST output option was deprecated between Antlr3 and Antlr4. Antlr3 will generate an AST but Antlr4 won't.

Your alternatives in Antlr4 are to use the Listener pattern (to walk the parse tree) or the Visitor pattern (to visit & evaluate nodes). Either - or both - of those can be used after running the Lexer and Parser.

There are a number of examples that can be found with some searching. Here's one for the Visitor pattern. This page compares Listeners and Visitors.

Upvotes: 1

Related Questions