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 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?
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,
[email protected]
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."
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
JavaScript.g
Description: Binary data
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
