Hello,<br><br>I've just started learning and playing with ANTLR.<br>I am writing a subset of the JavaScript grammar (as the examples at <a href="http://antlr.org">antlr.org</a> don't work for me).<br>In ANTLRWorks, when I use the interpreter, the second rule generates two errors with messages:<br>
<br>first node -> "FailedPredicateException(sourceElements, {can't deal with predicates yet}?)"<br>second node -> "FailedPredicateException(sourceElements, {synpred3_JavaScript}?)"<br><br>(parse tree with the error nodes can be found in the attachment)<br>
<br>However, if I use the debugger, the parsing is successful.<br>Why is this so?<br><br>My grammar is the following (also in attachment):<br><br><div style="margin-left: 40px; font-family: courier new,monospace;">grammar JavaScript;<br>
<br>options {<br> backtrack=true;<br> memoize=true;<br>}<br><br>program<br> : sourceElements EOF<br> ;<br> <br>sourceElements<br> : LT* ( sourceElement LT* )*<br> ;<br> <br>sourceElement<br> : functionDeclaration<br>
| statement<br> ;<br> <br>functionDeclaration<br> : 'function' LT* Identifier LT* formalParameterList LT* functionBody<br> ;<br> <br>formalParameterList<br> : '(' LT* ( Identifier ( LT* ',' LT* Identifier )* )? LT* ')'<br>
;<br><br>functionBody<br> : '{' sourceElements '}'<br> ;<br><br>statement<br> : emptyStatement<br> | blockStatement<br> ;<br> <br>emptyStatement<br> : ';'<br> ;<br> <br>
blockStatement<br> : '{' LT* statementList? LT* '}'<br> ;<br> <br>statementList<br> : statement ( LT* statement )*<br> ;<br><br><br>Identifier<br> : IdentifierStart IdentifierPart*<br> ;<br>
<br>fragment IdentifierStart<br> : UnicodeLetter<br> | '$'<br> | '_'<br> ;<br> <br>fragment IdentifierPart<br> : IdentifierStart<br> | UnicodeDigit<br> ;<br> <br>fragment UnicodeLetter<br>
: 'a'..'z' | 'A'..'Z'<br> ;<br><br>fragment UnicodeDigit<br> : '0'..'9'<br> ;<br><br>LT<br> : '\n' | '\r'<br> ;<br> <br>MultilineComment<br>
: '/*' (options { greedy=false; } : .)* '*/' { $channel=HIDDEN; }<br> ;<br><br>LineComment<br> : '//' ~(LT)* { $channel=HIDDEN; }<br> ;<br> <br>WhiteSpace <br> : ( ' ' | '\t' | '\v' | '\f' ) { $channel=HIDDEN; }<br>
;<br><br><br></div><br>Thank you,<br>regards<br><br><br>-- <br>Filipe David Manana,<br><a href="mailto:fdmanana@ieee.org">fdmanana@ieee.org</a><br>PGP key - <a href="http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC569452B">http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xC569452B</a><br>
<br>"Reasonable men adapt themselves to the world.<br> Unreasonable men adapt the world to themselves.<br> That's why all progress depends on unreasonable men."<br><br>