[antlr-interest] [v3] LITERAL_xxx tokens?

David Holroyd dave at badgers-in-foil.co.uk
Wed Aug 16 00:41:17 PDT 2006


On Tue, Aug 15, 2006 at 05:20:23PM -0700, Terence Parr wrote:
> 
> On Aug 15, 2006, at 3:47 PM, David Holroyd wrote:
> 
> >ANTLR 3 doesn't produce the LITERAL_xxx token type constant  
> >definitions
> >that v2 did.  Hey, I was using them! :)
> >
> >Should I define a TOKEN='token' for each than my application needs to
> >know about, or is there (going to be) another way?
> 
> Yep, literals are rferenced as just 'foo' in tree grammars and  
> everwhere.  If you need an identifier, you'll have to create.  What  
> do you use them for?

My application does lots of things like,

  public boolean isStatic() {
    AST modifiers = findModifiers();
    return ASTUtils.findChildByType(modifiers,
                                    AS3TokenTypes.LITERAL_static) != null;
  }

and

  public ASIfStatement newIf(String condition) {
    AST ifStmt = ASTUtils.newAST(AS3TokenTypes.LITERAL_if, "if");
    ast.addChild(ifStmt);
    ifStmt.addChild(ASTUtils.parseExpr(condition));
    ifStmt.addChild(ASTUtils.newBlock());
    return new ASTASIfStatement(ifStmt);
  }

i.e. it's very nice to have the option of doing AST stuff outside of the
ANTLR-generated code.

For the moment, I'll just add lots of entries like

  tokens { IF='if'; STATIC='static'; ... }


ta,
dave

-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list