[antlr-interest] Identifying a TNode

Alan Larkin nobrow at eircom.net
Sat Feb 24 07:58:40 PST 2007


b:binaryOperator
{
    TNode e1, e2;
    e1 = (TNode)b.getFirstChild();
    e2 = (TNode)e1.getNextSibling();
    expr(e1);
    print(b);
    expr(e2);
}

You see the above ... It comes from cgram (GnuCEmitter.g). I am taking this as a starting point to
implement some unusual language translation. I have a question.

Is it possible to look into each of the TNodes to see what they expand to?

In this case,

expr ::= binaryExpr | conditionalExpr | castExpr | unaryExpr | ...

I need to be able to identify the case where e1 and/or e2 turn into unaryExpr, and in such cases
avoid doing the processing I would otherwise do.

Any ideas?

Thanks.


More information about the antlr-interest mailing list