[antlr-interest] philosophy about translation

Andy Tripp antlr at jazillian.com
Fri Oct 27 13:56:39 PDT 2006


Oliver,

Yes, that's a great point. In theory, that's the price I pay for 
avoiding the treewalker approach :
I'm never sure if my "snippet" (e.g. "a.add(1)") actually might match 
something more than
what I'm picturing.

But because of the way I'm doing things, that's rarely a problem. In 
this case, I'm only
invoking this "snippet matcher" on each reference to a BigDecimal 
variable. In other words,
I've already found a "BigDecimal a;" declaration, and I'm looping 
through all the references
to that "a", and I only process the expression that surrounds it.

But this is the sort of thing I was hoping that Terence would hit if he 
attempted to "do it right".
That is, I'd like to have a tool that sees "a.add(1)", and then looks 
through the grammar,
sees that there are, say, 3 different places in the grammar that may 
match that pattern,
and then force me to specify which of those 3 I'm referring to.

Andy

Oliver Wong wrote:

>-----Original Message-----
>From: antlr-interest-bounces at antlr.org
>[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Andy Tripp
>  
>
>>I don't care how smart someone is, I doubt they'll know what
>>    
>>
>"a.add(1)"
>  
>
>>looks like as a C-AST, a Java-AST and a COBOL-AST. And that's about as
>>trivial a snippet of code as you'll ever see.
>>    
>>
>
>    That may be because there's some information in the AST form which
>isn't present in the raw string (or token stream) form. Assuming
>"a.add(1)" is Java, just from the raw string or the token stream, you
>can't tell whether that's an instance method invocation, a static method
>invocation, or something else. That snippet might even appear within the
>bigger context of "new a.add(1);", where "a" is a package name, and
>"add" is a class name, for example.
>    
>    But given an AST like...
>
><Statement>
>  <StatementExpression>
>    <Expression>
>      <QualifiedMethodInvocation>
>        <Expression>
>          <LocalVariableRef image="a">
>        </Expression>
>        <MethodInvocation image="add">
>          <Params>
>            <Param>
>              <Expression>
>                <Literal>
>                  <IntegerLiteral image="1"/>
>                </Literal>
>             </Expression>
>            </Param>
>          </Params>
>       </MethodInvocation>
>      </QualifiedMethodInvocation>
>    </Expression>
>  </StatementExpression>
></Statement>
>
>    ... you can eliminate the possibility of a static method invocation
>and constructor invocation.
>
>    - Oliver
>
>  
>



More information about the antlr-interest mailing list