[antlr-interest] Re: syn pred / lookahaed doesn't work
kreismeister at yahoo.de
Tue Mar 11 11:55:40 PST 2003
The problem is the "static" or "exit"
In the language the following is a valid statement:
Also the following is valid as a function declaration
static function myFun
The parser is configured to use a fix lookahead of k=2. Now after a
function is matched, it looks for statements. If it comes to
a "static" it tries to match a variable declaration. This fails and
the parser throws an exception (expecting IDENTIFIER
I tried to setup syn. pred "("static" IDENTIFIER) =>" before the
variable declaration in the statement rule but the generated parser
ignores this completly - still the same exception. Thus I know ANTLR
doesn't handle it right.
--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> There's not quite enough information there to see what the problem
> sure to inspect the generated code to see what antlr
is "thinking". This
> can often help you decide where a syntactic predicate is needed.
> Sometimes there are true ambiguities, such as the classic if/else
> Antlr warns about that but handles it properly too. There should be
> something about that in the docs about ambiguites.
> -----Original Message-----
> From: Gunnar Wagenknecht [mailto:kreismeister at y...]
> Sent: Tuesday, March 11, 2003 11:26 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] syn pred / lookahaed doesn't work
> I have a grammar where the syn. pred. doesn't seem to work. I can
> post the whole grammar but the following example should be ok to
> recognize the problem.
> compilationUnit : statementList (function)*;
> function : ("static"|"init"|"exit")? "function" identName crlf
> identName : IDENTIFIER;
> crlf : SEMICOLON | NEWLINE;
> statementList: (statement)*; // <<< here I get non-determinisme
> // warning upon
> // k=1 "static"|"exit"
> // k=2
> statement: ...
> | variableDeclaration
> | ...
> | "exit" crlf
> | ...
> variableDeclaration : ("public"|"private"|"local"|"static")
> I tried to reslove things with syn. pred. but whatever I do I
> couldn't remove the warning. The generated parser also doen't work
> What can I do to resolve the warning?
> Thanks, Gunnar
> Your use of Yahoo! Groups is subject to
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest