Greetings!
On Tue, 2010-03-09 at 14:43 +0100, Christoph Schinko wrote:
> Hi!
>
> Using the grammar below we experience unexpected behavior. The parser
> accepts the following input line:
>
> <<<<<<< .mine
>
> without throwing an error - which it should - according to the grammar.
> The grammar has been reduced to
> a toy example reproducing the error. Any thoughts on that?
ANTLR is simply doing what you told it to do!
> grammar JScriptDoc;
>
> options
> {
> output=AST;
> backtrack=true;
> memoize=true;
> }
>
> source
> : (statement)*
> ;
so your source is permitted to be zero (or more) statements.
your input: "<<<<<<< .mine" contains zero statements.
ANTLR is cool with that and does nothing (as you have instructed it to
do).
you probably want to add EOF to your source rule in order to instruct
ANTLR to consume all of the input it is given. I also suspect that
source is really One (or more) statements -- an empty input can be
discovered without invoking the parser/lexer... So I think you probably
want your source rule to be this:
source : statement+ EOF! ; // does not include EOF in the AST...
>
> statement
> : statementEmpty
> | statementBlock
> ;
>
> statementBlock
>
> : '{' (statement )* '}'
> ;
>
> statementEmpty
> : ';'
> ;
>
....rest snipped....
Hope this helps
-jbb
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
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.