Is ANTLR Visitor the right tool for my usage

I am using ANTLR4 and here some context:

my grammar:

I am using the made available tsql grammar. I extend and modified this grammar a little bit with a few exceptions.

my generated java classes

ANTLRWorks 2 generated me tsql.tokens,, and so on

my ""
import ...

public class MyTsqlVisitor extends tsqlBaseVisitor<String>{
    //here I need to implement my rules
my Main Method
public static void main(String[] args) {
    tsqlLexer lexer = null;

    try {
        lexer = new tsqlLexer(new ANTLRFileStream("test.iql"));
    } catch (Exception e) {}

    tsqlParser parser = new tsqlParser(new CommonTokenStream(lexer));

    ParseTree tree = parser.tsql_file();
    MyTsqlVisitor visitor = new MyTsqlVisitor();
my test.iql
    declare var_etl_log_message varchar(2000);
    declare var_etl_proc_line int;

        when others then

        set var_etl_error_message = sqlstate || errormsg ();

my question

I want use ANTLR for example to get the value of var_etl_error_message and then to print system.out.println(valueOfVar);

First of all is ANTLR the right tool for my usage? I read a lot of things about ANTLR and it looked really nice and fine for my usage. I did generated with ANTLRWorks2 a parsetree and it was perfect if I can get for example the value or the object as a String.

If yes, is my guess right, that the Visitor is better then the Listener for my usage?

If again yes ;-), then I am on the right way for my tool and I want to ask you guys because I have trouble to implement Can you guys tell me a refer or something like that.

Thanks in advance


I want use ANTLR for example to get the value of var_etl_error_message and then to print system.out.println(valueOfVar);

It seems you will have to develop a more or less working interpreter for this language. It probably won't have to be fully functional, but if you want to get the result after execution then you will have to execute it in some way (so it will be some kind of interpreter).

Yes, ANTLR is the right tool for it, but it won't necessarily be simple, especially if you are dealing with a language implementation first time. The Visitor is probably also a better choice than Listener (I'd pick Visitor too). IMO the Listener API is sufficient only for very simple usecases (like prettyprinting or extracting comments).

Need Your Help

Add a UISegmentedController to navigation bar with NSFetchedResultsController

iphone cocoa-touch core-data nsfetchedresultscontroller

I am working with a UITableView that gets its data from an NSFetchedResultsController. I would like to add a UISegmentedControl to my navigation bar that would toggle the table between displaying ...

32bit Operating systems vs 64 bit operating system

operating-system x86 64-bit benchmarking 32bit-64bit

I want to ask that if 32 bit window7 and 64 bit window7 is installed on two PCs having same configurations (i.e processor, RAM, etc) then I run same program(i.e data compression) on both OS then wh...