[antlr-interest] New article on StringTemplates and Treewalkers

shmuel siegel antlr at shmuelhome.mine.nu
Tue Jan 10 15:02:39 PST 2006


Sorry, my typo got you started on another tact. I meant to use ==. The 
point is that not all paths have a return statement.

Andy Tripp wrote:
>>
>>
>> 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
>>
> 
> I'm worried about that too :)
> I do mention that issue in the article, saying "how do you make sure x 
> is a boolean when you have if(x)".
> My ForceToBooleanRule is one of the most complex, and one of the few 
> that uses an ANTLR parser :)
> 
> The interesting thing about your example is that the "natural" Java 
> translation (what a person would write) is
> if (x == 5)
> whereas any traditional AST-walking translator would probably produce
> if ((x = 5) != 0)
> 
> While the second one is technically correct, and is probably what my 
> product would produce today,
> my product is designed so that I can easily add a rule to check for a 
> "if (v=n)" bug, and go ahead and
> fix the bug during translation. And I can and do add those sorts of 
> rules! Do not try this at home
> with your treewalking translator, kids :)
> 
> Andy
> 
> 



-- 
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