[antlr-interest] look ahead and backtracking

Yvan LUSSAUD yvan.lussaud at obeo.fr
Wed Oct 5 07:25:24 PDT 2011


Hi,

  I have a problem with recursive prefix and backtracking. I have a
parser that do not ignore spaces or comments, and that has many semantic
actions. The backtrack option is set to true.

  For some alternative antlr seems to generate the code to predict the
alternative to use, but this code do nothing and lead to always choose
the last alternative (no check on the last alternative).

When I call directly the right rule the parsing succeed and when I call
the rule that contains the alternative it fails. I tried to reproduce
the problem with a simple example but with this example it works as
expected using backtracking...

Compilation of my grammar gives no errors and no warnings but I can't
debug it from antlrworks. I always get a timeout. I'm under Linux and
the port is never opened by the debugged application. I always get the
same exception in the shell :

...../antlrworks-1.4.3.jar/templates/DBParserGlueCode.st (Not a
directory)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:137)
	at java.io.FileInputStream.<init>(FileInputStream.java:96)
	at org.antlr.works.utils.Utils.stringFromFile(Utils.java:43)
	at
org.antlr.works.dialog.AWPrefsDialog.prepareTestRigTabValues(AWPrefsDialog.java:345)
...

So I'm a bit stuck here... Is there a way to force backtracking on a
given rule or alternative? I tried to force it with k=1 but it seems to
have no effect on the produced code. I also used the left factoring to
resolve the problem and it works for some alternatives but it's not
always possible to factorize... I also used syntactic predicates but
it's also not always possible to find a working predicate. Any idea ?

regards,
-- 
Yvan LUSSAUD <yvan.lussaud at obeo.fr>




More information about the antlr-interest mailing list