[antlr-interest] Re: syn pred / lookahaed doesn't work

mzukowski at yci.com mzukowski at yci.com
Tue Mar 11 12:00:04 PST 2003


You need the syn pred higher up, where the decision is being made to try and
match a statement.  That would be in the statementList rule.  Try this to
start:

statementList: ((statement)=>statement)* ;

Monty

-----Original Message-----
From: Gunnar Wagenknecht [mailto:kreismeister at yahoo.de]
Sent: Tuesday, March 11, 2003 11:56 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: syn pred / lookahaed doesn't work


The problem is the "static" or "exit"

In the language the following is a valid statement:
---
static myVar
---

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 
found "function").

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. 

Cu, Gunnar


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> There's not quite enough information there to see what the problem 
is.  Be
> 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 
ambiguity.
> Antlr warns about that but handles it properly too.  There should be
> something about that in the docs about ambiguites.
> 
> Monty
> 
> -----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
> 
> 
> Hi!
> 
> 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
>            statementList;
> 
> identName : IDENTIFIER;
> 
> crlf : SEMICOLON | NEWLINE;
> 
> statementList: (statement)*;  // <<< here I get non-determinisme 
>                               // warning upon
>                               // k=1 "static"|"exit"
>                               // k=2 
> IDENTIFIER|"function"|NEWLINE|SEMICOLON
> 
> statement: ...
>          | variableDeclaration
>          | ...
>          | "exit" crlf
>          | ...
>          ;
> 
> variableDeclaration : ("public"|"private"|"local"|"static") 
identName 
> crlf;
> 
> 
> 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 
> correct.
> 
> What can I do to resolve the warning?
> 
> Thanks, Gunnar
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list