[antlr-interest] acceptance of new ideas (was philosophy about translation)

Andy Tripp antlr at jazillian.com
Thu Oct 12 16:01:23 PDT 2006


Kay Roepke wrote:

>
> On 12. Oct 2006, at 22:17 Uhr, Andy Tripp wrote:
>
>> I think the "it's ok to generate less-than-perfect code" mindset is  
>> especially hard to get
>> for someone in the compiler crowd.
>
>
> Of course it depends. Clearly, no one can expect a code translator  
> that can convert huge programs
> flawlessly, in every instance. Those who expect that probably have no  
> inkling about the problem domain,
> even if they are successful compiler engineers. The sad thing is,  
> most of the time they are just pointing to
> the really hard stuff and ignore the 90% of the work you can take off  
> their shoulders. Stupid behavior, if you ask
> me.

It can and has been done. See http://ovid.tigris.org/Ephedra/.
I don't doubt that it works perfectly. Just don't expect to be able to 
read or maintain the
generated code just because it's Java and not assembly.

>
> What really interests me are automatic code refactoring (how I hate  
> that word) tools for a variety of languages (including
> script languages that have a very implicit type system, like Perl).
> In particular for Objective-C, since that has the immensely  
> fascinating mixture of both early and late binding,
> the latter inherited from Smalltalk.
> In that problem domain, accuracy is a must and it is a hard problem  
> to prove correctness of transformation, if you
> cannot completely rely on types. You don't want to mess with code  
> that will be failing in obscure ways at runtime.
> The effects of rearranging code can be hard to visualize so there  
> must not be any foul surprises lurking behind the corner.
> Coming from that direction, your work interests me immensely, and  
> your success gives me the hint that it indeed is
> feasible to try for something like I'm aiming at.

 From what I've seen, all the refactoring tools, IDEs, etc. all use ASTs.
Also note that Sun is adding adding an API to be able to access all 
javac functionality. That's pretty cool.
If you really do need 100% correctness, you'd better stick with ASTs.

> In that respect, it is of course valuable to know your motivations  
> for avoiding a tree based approach, and be it just
> for seeing a different approach which causes me to reflect my  
> presuppositions, which is always good.

I didn't start out avoiding ASTs. I had just jotted down a couple 
hundred simple rules like:
strcpy(a, b) --> a = b;
if (true) { x } --> x  // as long as there's no 'else'
printf(x) --> sprintf(stdout, x)

And I found it very hard to work with the ASTs. At least for these 
trivial cases, it shouldn't take much
longer than the few seconds it took to type that mapping.

>
>
>> Lex and Yacc where around for, what? 20 years
>> before ANTLR came along? 20 years of people using lex and yacc, and  
>> getting things
>> to work by trial-and-error because the generated code was  
>> unreadable? That's crazy!
>> Thank goodness Terence came along and saw the value in generating  
>> readable code.
>
>
> All hail the chief! :) BTW, I totally agree.

On some things, we can all agree :)

>
> -k
>
>
>
>



More information about the antlr-interest mailing list