[antlr-interest] ANTLRWorks interpreter vs debugger

Filipe David Manana fdmanana at ieee.org
Mon Feb 23 14:28:05 PST 2009


Hello,

I've just started learning and playing with ANTLR.
I am writing a subset of the JavaScript grammar (as the ones at
antlr.orgdon't work for me).
In ANTLRWorks, when I use the interpreter, the second rule generates two
errors with messages:

first node -> "FailedPredicateException(sourceElements, {can't deal with
predicates yet}?)"
second node -> "FailedPredicateException(sourceElements,
{synpred3_JavaScript}?)"

However, if I use the debugger, the parsing is successful.
Why is this so?

My grammar is the following (also in attachment):

grammar JavaScript;

options {
    backtrack=true;
    memoize=true;
}

program
    : sourceElements EOF
    ;

sourceElements
    : LT* ( sourceElement LT* )*
    ;

sourceElement
    : functionDeclaration
    | statement
    ;

functionDeclaration
    : 'function' LT* Identifier LT* formalParameterList LT* functionBody
    ;

formalParameterList
    : '(' LT* ( Identifier ( LT* ',' LT* Identifier )* )? LT* ')'
    ;

functionBody
    : '{' sourceElements '}'
    ;

statement
    : emptyStatement
    | blockStatement
    ;

emptyStatement
    : ';'
    ;

blockStatement
    : '{' LT* statementList? LT* '}'
    ;

statementList
    : statement ( LT* statement )*
    ;


Identifier
    : IdentifierStart IdentifierPart*
    ;

fragment IdentifierStart
    : UnicodeLetter
    | '$'
    | '_'
        ;

fragment IdentifierPart
    : IdentifierStart
    | UnicodeDigit
    ;

fragment UnicodeLetter
    : 'a'..'z' | 'A'..'Z'
    ;

fragment UnicodeDigit
    : '0'..'9'
    ;

LT
    : '\n' | '\r'
    ;

MultilineComment
    : '/*' (options { greedy=false; } : .)* '*/' { $channel=HIDDEN; }
    ;

LineComment
    : '//' ~(LT)* { $channel=HIDDEN; }
    ;

WhiteSpace
    :  ( ' ' | '\t' | '\v' | '\f' )  { $channel=HIDDEN; }
    ;



Thank you,
regards


-- 
Filipe David Manana,
fdmanana at ieee.org
PGP key - http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC569452B

"Reasonable men adapt themselves to the world.
Unreasonable men adapt the world to themselves.
That's why all progress depends on unreasonable men."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090223/b6adb49b/attachment.html 


More information about the antlr-interest mailing list