Hello,
Is it possible to do something in a rule's action that either makes the
parser finish (with success status) or insert a token in the input stream?
I need something like that for a JavaScript grammar. Considering the
following rules:
program
: sourceElements EOF
;
sourceElements
: LT* ( sourceElement LT* )*
;
sourceElement
: functionDeclaration
| statement
;
statement
: emptyStatement
| variableStatement
| blockStatement
;
variableStatement
: 'var' LT* variableDeclarationList ( LT | ';' )
;
If the input stream is for e.g. "var test" (no newline or semi-colon before
the EOF), my parser fails. ANTLRWorks debuggers shows "NoViableAltException"
nodes coming from the "variableDeclarationList" rule.
If I change my rules to:
program
: sourceElements
;
/* rules in between remain unchanged */
variableStatement
: 'var' LT* variableDeclarationList ( LT | ';' | EOF )
;
The same thing happens.
So my initial thought is to add a ';' for e.g. into the input stream if an
EOF is following the "variableDeclarationList" ub tge "variableStatement"
rule.
As a complete beginner to ANTLR, any suggestions are very welcome.
cheers
--
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
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address