[antlr-interest] ENHANCEMENT: Friendlier parser class, syntactic sugar for top level production.

Austin Hastings Austin_Hastings at Yahoo.com
Wed Jul 30 21:05:02 PDT 2008


I didn't see this in the 3.1b? release notes, so I thought I'd ask for 
it again.

I'd like to see the Parser class come with a .parse(...) method. This 
would do what the examples suggest: create  a lexer, etc., and then 
invoke the top level production.

Obviously, you could override this. If you do, then no harm done. But 
most people are doing the same things, so why should the code generator 
generate the last little bit that they need?

Equally obviously, there would need to be a way to identify the  top 
level production. The most obvious way is to use the first one 
encountered. A slightly better way would be to add some syntax to 
identify it. Either as an option, or as a rule attribute:

options {
    language = Java;
    main_rule = compilation_unit;
}

// or

algebraic_expr
    : ...
    ;

boolean_expr
    : ...
    ;

compilation_unit
    @main_rule
    : ...
    ;


=Austin



More information about the antlr-interest mailing list