[antlr-interest] Flow of control in AST parsing.

Bryan Ewbank ewbank at gmail.com
Wed Feb 16 09:38:22 PST 2005


It happens automatically; each production is a function, and when it
falls off the end of your code, control returns to the callER.

Try generating your code with -traceTreeParse and you will see that
the call trace represents a traversal of the tree.


On Wed, 16 Feb 2005 10:08:59 -0600, Bharath Sundararaman
<Bharath.Sundararaman at starthis.com> wrote:
> Hi all,
> 
> I have a tree walker which walks function calls in the AST to perform
> type checking in the following form:
> 
> A function sqrt(a,b); will be walked as #(s:IDENT #(PARAM param_List));
> 
> If I find out the "sqrt" is an undefined/erroneous function, I want to
> avoid walking through the parameters of the function. So, I did this:
> 
> If (sqrt is an erroneous function) #s.removeChildren(); Note that "s" is
> the label for the "IDENT" token which is the name of the function.
> 
> The problem is, the children are removed but I don't know how to return
> the flow of control to the rule that invoked this rule. For example, I
> am unable to return to an assignment statement of the form:
> 
> result := sqrt(a,b); How can I return the control to the assignment
> statement after I remove the children?
> 
> Thanks,
> 
> Bharath.
> 
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Terence Parr
> Sent: Tuesday, February 15, 2005 8:30 PM
> To: ANTLR Interest
> Subject: [antlr-interest] new article on language translation
> withStringTemplate
> 
> Howdy,
> 
> You all might be interested in the following article I just put up at
> codegeneration.net:
> 
> http://www.codegeneration.net/tiki-read_article.php?articleId=77
> 
> "This article demonstrates how to translate a very simple C dialect,
> which I will call "C-" in honor of the grades I received in college, to
> three different languages, again using a single model and controller
> with multiple views. The targets are Java, Python, and bytecodes
> similar to the Jasmin Java bytecode assembler format. Merely swapping
> in a new template file generates completely different output without
> even recompiling the translator!"
> 
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> 
>


More information about the antlr-interest mailing list