[antlr-interest] philosophy about translation

Jim Idle jimi at intersystems.com
Mon Nov 6 11:16:51 PST 2006


To address your points:

* It is great to be able to re-use and existing grammar and more power to the elbow's of those who donate them :-). However if you are going to use an ANTLR grammar, I honestly can think of no valid reason to avoid learning how ANTLR works in as much detail as you can. This applies to anything really. You can write much better Java code if you understand the effects of your code upon the runtime;
* As you seem to have surmised, counting things is not generally done in the syntax parsing unless there is some reason that it is easier there or there is no need for anything but a single syntactical parse. In general, counting things would be done for semantic verification or code generation or something akin to these and you would do it in the tree parser. However, the code for counting things is small anyway and specific to the task at hand and therefore will be more efficient. The more computing time you can save on things like this, the more time you have to spend on optimization and so on.
* Size of C grammar eh? I assure you that the C grammar is relatively simple compared to many. But I have not found a larger grammar to create any more problems than a smaller grammar. Problems with grammars are usually engendered by how well the original 'language' you are trying to parse was structured. C++ is a more difficult parsing prospect. I guess I just don't find embedding actions awkward, but then I don't tend to put all the code for the action right inline if it is more complex than a small number of lines.
* There are other projects than ones with impossible deadlines? :-)

Jim

-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Andy Tripp


Jim Idle wrote:

>To be honest it is this sort of question (and the answer) that we need to have in the book. The problem is that I would not have thought of this question in a million years (and that is no slight on Andy at all).
>
>  
>
I assume you mean here that you would have just gone ahead and plugged 
in the "calculate n" code at the appropriate place in your grammar.

It might help to see my perspective if you realize:
* I didn't write the grammar. I use Monty's C grammar, and so I've 
avoided learning much about ANTLR.

* I'm now in beta trial on a COBOL-to-Java translator and a C++-to-Java 
translator. I bet I wrote the whole
   COBOL-to-Java translator in less time than those couple of poor souls 
who are trying to create an ANTLR COBOL grammar.
* I'll almost certainly need to "calculate n" at other places in the 
tree sooner or later. It makes no sense at all to me to put "calculate 
n" code
  at one place in the grammar, and then keep having to repeat that. Even 
an AST lets me avoid that (with some kind of
  getChildCount()).
* If you haven't worked with a grammar the size of the C grammar, you 
probably don't have a feel for how awkward embedding
  actions is. And the C++ and COBOL (if ever finished) are even larger.
* Nothing makes you really want to avoid learning ANTLR (or anything 
else new)
   like a large and impossible project with an unreasonable deadline. :)

Andy

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.13.28/518 - Release Date: 11/4/2006 5:30 PM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.430 / Virus Database: 268.13.28/518 - Release Date: 11/4/2006 5:30 PM
 


More information about the antlr-interest mailing list