[antlr-interest] New article on StringTemplates and Treewalkers
shmuel siegel
antlr at shmuelhome.mine.nu
Tue Jan 10 14:29:21 PST 2006
Terence Parr wrote:
> Hi. My impression from reading his article was that Andy was
> interpreting tree walker to be the simple visitor pattern where all you
> can see is "I'm at node function definition" as opposed to the more
> powerful grammar-based tree pattern matching:
>
> funcdef
> : ^(FUNCDEF ID args body)
> ;
>
> Specifically he asked where one would worry about whether or not a
> return statement was present in the body. Seems straightforward to
> have an action after the body rule reference that checked a boolean set
> by body. You might do this (using the new dynamic scope stuff):
>
> funcdef
> scope {
> boolean hasReturn;
> }
> @init {
> hasReturn = false;
> }
> : ^(FUNCDEF ID args body) {if ($hasReturn) ...}
> ;
>
> body : stat+ ;
>
> stat : ... | ^(RETURN expr) {$funcdef::hasReturn=true;} | ... ;
>
> Andy, is this easier or harder than you imagined? Does it address your
> point?
>
> Ter
>
>
I think that Andy was more bothered by how to translate something like
int func(int x)
{
if(x=5)
return 3;
}
since even though it looks like java, it is not valid java.
Shmuel
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 1/9/2006
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 1/9/2006
More information about the antlr-interest
mailing list