[antlr-interest] Recursive parenthesises in the tree.

Fatih Tolga Ata fatih at diyezon.com
Mon Feb 16 07:30:08 PST 2009


Hi,

I'm learning antlr by implementing a javascript parser. My target 
language is C#. I'm using Patrick Hulsmeijer's Ecmascript3 grammar. I 
converted java codes to c# code in the grammar file. I was able to 
compile a lexer, a parser and a tree walker with this grammar. I tried a 
lot of js input, and I fixed some errors in the c# code in the grammar 
file. But in the belov input, tree walker display "no viable alternative 
at input 'PAREXPR'".
The input is :
if ((a1 = this.prototype[a1])) return add(this, a2, a1, a3);

I looked at grammar and tree walker files, but I didn't solve this 
problem. In grammar file, I saw:

primaryExpression
    : THIS
    | Identifier
    | literal
    | arrayLiteral
    | objectLiteral
    | lpar=LPAREN expression RPAREN -> ^( PAREXPR[$lpar, "PAREXPR"] 
expression )
    ;

And in the tree walker file, there is:
primaryExpression
    : Identifier
    | literal
    ;

This implementation works well when the input has not recursive 
parenthesises. If the input has recursive parens like "((( expression 
)))", the tree walker gives the error I mentioned before.

I studied compilers before. But I am new at antlr grammar. I couldn't 
understand what PARAEXPR is and what is the "-> ^(    )" in the 
primaryExpression.

How can solve this problem?

Any help'll be appreciated.

Regards.


More information about the antlr-interest mailing list