[antlr-interest] grammar problem with recursion?

Gerald Rosenberg gerald at certiv.net
Thu Aug 5 21:24:50 PDT 2010


------ Original Message (Thursday, August 05, 2010 11:41:57 
PM) From: Dervin Thunk ------
Subject: [antlr-interest] grammar problem with recursion?
> Hello. I am new to ANTLR. Below is a grammar I wrote, and I'm trying to
> test it with the following string, but it just stops before it even
> consumes the n_pp... identifier, so it stops at the "conjunction"
> rule. Any idea about what I could be doing wrong?
>
>
> conjunction
>         :  term
>         | (term '&' conjunction)
>         ;
Once 'term' gets matched in alt 1, Antlr has no where to go next.  You 
could reverse the order of the alts, but better would be

         conjunction : term ( '&' conjunction )? ;

You have this problem in most of your compound rules.  There is an Antlr 
Wiki page on left factoring that you should read.




More information about the antlr-interest mailing list