[antlr-interest] Skipping AST nodes in tree-parsing

Arnar Birgisson arnarb at oddi.is
Tue Sep 23 03:04:57 PDT 2003


Thank you for a very clear answer, it is much appreciated (this goes to
Loring as well).

I will probably want to validate the syntax for the subtree in some
places, depending on context, but it is nice to have the option.

Thanks again.

Arnar

> -----Original Message-----
> From: mzukowski at yci.com [mailto:mzukowski at yci.com] 
> Sent: 22. september 2003 20:04
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] Skipping AST nodes in tree-parsing
> 
> 
> ! is to turn off tree generation.  If you tree parser is not 
> building a tree
> (buildAST=false) then ! won't do a thing.
> 
> Also, if it so happens that you have an imaginary root for 
> block_stmt, say
> BLOCK_STMT, then you could write your rule like this without 
> bothering with
> the syntactic predicate (unless you really want to validate 
> the syntax for
> the whole block_stmt subtree)
> 
> funcdef
>   : #("function" ID arg_list BLOCK_STMT)
>   ;
> 
> Monty
> 
> -----Original Message-----
> From: Arnar Birgisson [mailto:arnarb at oddi.is] 
> Sent: Monday, September 22, 2003 11:52 AM
> To: antlr-interest at yahoogroups.com
> Subject: RE: [antlr-interest] Skipping AST nodes in tree-parsing
> 
> 
> Hello..
> 
> Thanks for the lightning fast response :o)
> 
> This works, I have:
> 
> funcdef
>   : #("function" ID arg_list (block_stmt)=> block:.)
>   ;
> 
> This ensures that the atom is of the correct token.
> 
> One thought this leads to: what meaning does ! have in tree parsers?
> Excpecting to match a token and create the AST for it but 
> skip descending
> into it, I first tried
> 
> funcdef
>   : #("function" ID arg_list block_stmt!)
>   ;
> 
> which was accepted by ANTLR but generated the exact same code 
> as it did
> without the !.
> 
> Arnar
> 
> > -----Original Message-----
> > From: mzukowski at yci.com [mailto:mzukowski at yci.com]
> > Sent: 22. september 2003 18:35
> > To: antlr-interest at yahoogroups.com
> > Subject: RE: [antlr-interest] Skipping AST nodes in tree-parsing
> > 
> > 
> > funcdef
> >   : #("function" ID arg_list .)
> >   ;
> > 
> > '.' is a wild card and just matches one node but does not
> > decend into the
> > tree, just like ID above does not descend into a tree and 
> > just matches one
> > node of type ID.
> > 
> > Monty
> > 
> > -----Original Message-----
> > From: Arnar Birgisson [mailto:arnarb at oddi.is]
> > Sent: Monday, September 22, 2003 11:30 AM
> > To: antlr-interest at yahoogroups.com
> > Subject: [antlr-interest] Skipping AST nodes in tree-parsing
> > 
> > 
> > Hello there..
> > 
> > Is there a way in a treeparser to skip the walking/parsing of
> > a tree node? I
> > want to store a reference to the AST instead. Two examples: 
> > 
> > This is in my parser:
> > 
> > funcdef
> >   : "function"^ ID LPAREN! arg_list RPAREN! block_stmt
> >   ;
> > 
> > and in the tree parser:
> > funcdef
> >   : #("function" ID arg_list block_stmt)
> >   ;
> > 
> > Now, instead of parsing ID, arg_list and then block_stmt
> > nodes, I only want
> > to parse the ID and arg_list and skip over block_stmt, 
> > instead I will store
> > a reference to the node in a hashtable indexed on the given ID. 
> > 
> > Later, when the function is called in the user-program, the
> > tree-parser rule
> > for a function call will look up the AST for the function 
> > definition by its
> > name and manually call appropriate rule for walkin the AST, 
> > after installing
> > the given paremeters into the symbol table. 
> > 
> > Another example of this is rewriting for loops to while loops:
> > 
> > for (stmt1; expr; stmt2) stmt3;
> > 
> > becomes
> > 
> > stmt1; while (expr) { stmt3; stmt2; }
> > 
> > This involves the reordering of the atoms, i.e. this
> > translation scheme is
> > not simple by the definiton of the Dragonbook. 
> > 
> > How does one do this kind of translation in a tree walker?
> > Perhaps someone
> > could point out a simpler solution, but if one could skip 
> > over nodes as
> > described above and manually call the parsing method for them 
> > at a later
> > time, this becomes trivial. 
> > 
> > Arnar
> > 
> > 
> >  
> > 
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/ 
> > 
> > 
> >  
> > 
> > Your use of Yahoo!
> > Groups is subject to http://docs.yahoo.com/info/terms/ 
> > 
> > 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
> http://docs.yahoo.com/info/terms/ 
> 
> 
>  
> 
> Your use of Yahoo! 
> Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list