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

Albert Huh albert.huh at embarcadero-ca.com
Tue Mar 11 16:16:34 PST 2003


simply using a syntactic predicate in a loop will not work here.

Ambiguity with k=1
------------------
1) if you see the word "static", it can belong to BOTH the function rule and the variableDeclaration rule.
2) similarly, if you see the word "exit", it can belong to both the function rule and the statement rule.
3) the variableDeclaration rule reduces to the statement rule i.e. they are the same rule.
4) so a statement looks exactly like a function at k=1

ambiguity with k=2
------------------
1) the second token of a function can be either an IDENTIFIER or "function"
2) the second token of a variableDeclaration is an IDENTIFIER
3) we know that variableDeclaration is a statement
4) so a statement looks exactly like a function at k=2


i'm probably not stating anything new here to anybody.  i *think* this is a linear approximation issue, can somebody else confirm this?

in any case, it is pretty clear that a variableDeclaration can't be confused with a function (to us humans anyways =).

i think this was already suggested, but one strategy is to just test it to make sure it does the right thing.  odds are, you can just ignore this warning and turn it off and antlr will do the right thing.

alternatively, you can get rid of teh warning with a combination of recursion and syntactic predicates.  try rewriting your statementList rule like this:

statementList:
  (statement statement)=>statement statementList
  |(statement)=>statement
  | //empty rule, do nothing
;


p's
albert

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



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

I tried this but the non-determinisme warning is still there and 
there is another warning saying somthing gist to "single syn. pred. 
that doesn't make sence".

Cu, 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/ 



More information about the antlr-interest mailing list