[antlr-interest] New article on StringTemplates and Treewalkers

Andy Tripp antlr at jazillian.com
Thu Jan 12 07:43:01 PST 2006



sohail at taggedtype.net wrote:

>>Gregg Reynolds wrote:
>>
>>    
>>
>>>Andy Tripp wrote:
>>>More specifically:  how hard would it be to write an ML or Haskell
>>>emitter for Antlr (something I'd like to see)?
>>>      
>>>
>>Good question, and my related question is "will StringTemplate make that
>>any easier?".
>>    
>>
>
>Now you're just being mean. This is as big a difference as generating code
>for a stack based machine when your AST assumes a register based machine
>(like gcc). This is an analogy for functional languages and imperative
>languages like C++ or Java. Therefore, you might need to tweak your AST
>(but then again, you might not!)
>  
>
I'm not following you exactly, but I think it's a reasonable question. I 
don't buy that I could, for example,
use StringTemplate to output C# instead of Java, without major changes 
to my code. I don't think
ANTLR could output MS or Haskell (or Lisp) without major changes. ST is 
not fullfilling the
"separate your view from your translation" promise in any cases other 
than the most trivial, contrived cases
(or when the output languages are so similar as C++/Java/C# and the 
domain is so limited as in the case
of all the code that ANTLR spits out).

>  
>
>>>How hard would it be to write an ML or Haskell front-end for
>>>Jazillion?  (I mean relative to a C frontend, not relative to a
>>>backend to Antlr, which would no doubt be easier.)
>>>      
>>>
>>Answer: very hard: the translation rules are all C-specific. To put it
>>bluntly, the Jazillian "front-end" is not in any way separated from the
>>"engine"
>>and "backend". I believe it's impossible to design such a
>>any-language-to-any-language translation engine, despite the fact that
>>Semantic Designs claims to have such a product.
>>    
>>
>
>With some constraints, I think this is possible.
>  
>

OK then, what is the Java equivalent of "memset (111, 222, 333);"?
 I suppose that's a constraint :)

>  
>
>>brain has already tokenized it into a sequence of 5 tokens:
>>int [ ] i ;
>>But given that same chunk of code, our brains to NOT easily form an AST
>>structure:
>>    
>>
>
>I think some people do. Thats why lisp is so easy to read. For those :)
>  
>
I'm not sure if you're joking here or not. I sure hope you are.
If not, try looking at 20 lines of Lisp without "cheating"...without any 
indentation.
Besides, Lisp source maps one-to-one to its AST structure. Barely any 
parser needed.
C, Java, C#, etc. source doesn't look much like it's AST structure at all.


More information about the antlr-interest mailing list