[antlr-interest] Noob TreeWalker Template question
Terence Parr
parrt at cs.usfca.edu
Fri Apr 4 12:29:49 PDT 2008
Hi. the return structs are really internal use. you have to manually
add the elements to a list if you want the return values other than
template.
Ter
On Apr 4, 2008, at 6:33 AM, PSheehan at decaresystems.ie wrote:
>
> Hi all,
> I'm completely new to Antlr with no previous complier/parser
> experience. I'm create a simple lexer/parser and treewalker to help
> me understand the ins and outs of Antlr. I also have the Antlr
> reference book, which I would be completely lost without!
>
> I'm having a simple problem when trying to process a rule that does
> not have a template associated with it. When I run my example I get
> an ArrayList of nulls for 'fields'.
>
> options{
> tokenVocab=mytest;
> ASTLabelType=CommonTree;
> output=template;
> }
>
> model : ^(MODEL TYPE fs+=fielddef+) ->
> modeltmp(name={$TYPE},fields={$fs})
> ;
>
> fielddef returns [String type,String id]
> : ^(FIELD TYPE ID) {$type=$TYPE.text;$id=$ID.text;}
> ;
>
>
> When I look at the generate code it is like this
>
> fs=fielddef();
> _fsp--;
>
> if (list_fs==null) list_fs=new ArrayList();
> list_fs.add(fs.getTemplate());
>
> Sorry if this is a simple question but is there a way I can modify
> the grammar so that I end up with an ArrayList of return_fielddef
> like so:-
>
> fs=fielddef();
> _fsp--;
>
> if (list_fs==null) list_fs=new ArrayList();
> list_fs.add(fs);
>
> Or do have I have to use scopes in my grammar to deal with this
> problem.
> Thanks,
> Paul
> This e-mail and any files transmitted with it are intended solely
> for the individual or entity to whom they are addressed. This
> communication may contain material that is privileged, confidential
> and protected from disclosure under the law. If you are not the
> intended recipient, any disclosure, distribution, copying, or use of
> this information is strictly prohibited and may be unlawful.
>
> If you have received this e-mail in error, please reply immediately
> to the sender and delete it.
>
> Registered Address:
> DeCare Systems Ireland Ltd,
> Building 1, University Technology Centre, Curraheen Road, Cork,
> Ireland.
> Company Registration Number: 278462
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080404/a4aeb28a/attachment.html
More information about the antlr-interest
mailing list