[antlr-interest] philosophy about translation

Oliver Wong owong at benchmarkconsulting.com
Fri Oct 27 11:40:48 PDT 2006


-----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