[antlr-interest] philosophy about translation

Andy Tripp antlr at jazillian.com
Wed Nov 1 12:58:07 PST 2006


Terence Parr wrote:

>
> On Nov 1, 2006, at 11:45 AM, Andy Tripp wrote:
>
>>> Try feeding Java code or an ANTLR grammar to a C++ compiler. ;-)
>>>
>> Of course you need to know the input syntax and symantics (a  
>> little). That's different from
>> knowing the details of what the tool is doing. When talking to Ter,  
>> at one point I said
>> "and how do I know how many times that pattern was matched?" and he  
>> said "just check
>> n < 4". How was I supposed to know that ANTLR generated some code  
>> that included
>> a variable called n?
>
>
> You aren't.  You need to generate int n=0 and n++ code so you know  
> what's up. ;)

Or better yet, just call some sort of astNode.getChildCount() method 
while walking the AST :)

So, to sum up...when I have
...( statement )+...
Not only do I not want to have to figure out and then generate the 
"n-type-code" is that I need to
embedd in the ANTLR-generated code, I don't even want to walk the tree 
and call astNode.getChildCount()!

I just want to say something like:
int n = statementList.getStatementList().size()
In other words, I want an ANTLR-generated Java API that mirrors my grammar.
I want my parser's output to be a Java API (and implementation), not an 
AST like ANTLR produces
or even Java code that implements a treewalk like javacc produces.

Guess I'm just being difficult :)
Andy


>
> Ter
>



More information about the antlr-interest mailing list