[antlr-interest] ANTLRWorks interpreter vs debugger

Johannes Luber jaluber at gmx.de
Mon Feb 23 22:32:39 PST 2009


Filipe David Manana schrieb:
> Hello,
> 
> I've just started learning and playing with ANTLR.
> I am writing a subset of the JavaScript grammar (as the examples at
> antlr.org <http://antlr.org> don'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}?)"
> 
> (parse tree with the error nodes can be found in the attachment)
> 
> However, if I use the debugger, the parsing is successful.
> Why is this so?

Because Jean Bovet hasn't done the effort required to make the
interpreter capable to deal with predicates yet. Considering that such
predicates can do everything like actions doing so is a lot of work,
compared to just using the debugger and improving the editor with other
features.

Johannes
> 
> 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 <mailto:fdmanana at ieee.org>
> PGP key - http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC569452B
> <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."
> 
> 
> ------------------------------------------------------------------------
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list