[antlr-interest] Collecting parameters

Bart Kiers bkiers at gmail.com
Sat May 21 10:50:34 PDT 2011


Hi David,

Every root (or leaf) in the AST must be an instance of a `
org.antlr.runtime.tree.Tree`, so you can't create a node that is a
`java.util.List`.

By default, ANTLR creates its AST using `org.antlr.runtime.tree.CommonTree`
objects which inherits the `getChildren()` method from
`org.antlr.runtime.tree.BaseTree` which returns a List. This List contains
`CommonTree`'s. So your VECTOR root already has a method to get the children
`1,2,3,4`.

Regards,

Bart.


On Sat, May 21, 2011 at 7:14 PM, David Smith <david.smith at cc.gatech.edu>wrote:

> Your contributors have been very helpful with my novice questions,
> and I thank them.  Here's another:
>
> I am trying to build an AST that processes text like:
>           v4 = [1 2 3 4]
> The following rule works:
>
> term  :   (OPENB .+ CLOSEB) => OPENB vals CLOSEB
>                                -> ^(VECTOR vals)
>       |    OPENB CLOSEB        -> EMPTY_VECTOR
>       |    DOUBLE
>       |    ID
>       |    '('! expr ')'!
>       ;
>
> vals returns [List items]
>       :   vl+=expr (COMMA? vl+=expr)* {$items = $vl;}
>       ;
>
> but it produces tree nodes like:
>
> (= v4 (VECTOR 1 2 3 4))
> but I really want
>
> (= v4 (VECTOR values))
>
> where 'values' is some kind of Java collection like an ArrayList.
>
> How do I do that?
>
>
> David M. Smith http://www.cc.gatech.edu/fac/David.Smith
> Georgia Institute of Technology, College of Computing
> Sent from my ASR-33 Teletype
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list