[antlr-interest] Repeating Group of Statements (Weird)

Bryan Ewbank ewbank at gmail.com
Mon Jun 20 03:09:20 PDT 2005


There is a mismatch in the parser and the tree parser for const_decl nodes...

Parser generates const_decl with ASSIGN as the root node here:
        const_decl : "const" ID ASSIGN^ NUM;

Tree parser expects "const" as the root node here: 
        const_decl : #("const" ID ASSIGN NUM) ;

This means that the tree parser will "correctly" match a sequence of
zero statements, due to the "*" in the topmost production for the tree
parser.

I think you also need to have "EOF" at the end of the top-most parser
rule, but that may not be required, here:
    class CalcParser extends Parser;
    options { buildAST = true; }
    statement : (assignment SEMI! | const_decl SEMI!)* EOF; // <-- here


More information about the antlr-interest mailing list