[antlr-interest] Syntactic predicate not being generated

Olivier Dragon dragonoe at mcmaster.ca
Sun Jul 31 08:18:37 PDT 2005


On Sun, Jul 31, 2005 at 03:41:14PM +0700, Terence Parr wrote:
> On Jul 30, 2005, at 7:44 PM, Olivier Dragon wrote:
> >On Fri, Jul 29, 2005 at 11:54:37AM -0400, Olivier Dragon wrote:
> >
> >>I have this problem where I put a syntactic predicate inside the  
> >>lexer
> >>and no code is being generated for it. I get no warnings or errors  
> >>(it's
> >>inside an alternative block with more than one). Here is the lexer  
> >>rule:
> >>
> >
> >I found that by increasing codeGenMakeSwitchThreshold to something
> >higher than the number of alternatives I had would generate proper  
> >code
> >with the syntactic predicate check. Before that I was using the  
> >default
> >value, that is not specifying one.
> >
> >Is this a known bug with ANTLR?
> 
> Yikes!  That sounds like a problem.  I was going to suggest that  
> perhaps ANTLR decided you didn't need the pred, but this second email  
> makes it sounds just wrong; that switch shouldn't change  
> functionality. :(

What happens is that you can't have a switch because of the predicate.
ANTLR should detect that and revert back to if-statements. The switch
causes problems because once LA(1) matches, the code is stuck in that
case (unless there's no break but that defeats the switch purpose and
complicates the logic). That makes predicates useless. ANTLR seems to
decide that using the switch is more important than using the predicate.

I can reproduce with 2.7.5 and 2.7.6 (which comes with antlr eclipse).

If there's anything I can do to help identify it better let me know. Try
building a lexer with that rule I put in my previous email.

-Olivier

-- 
          __-/|    ? ?     |\-__
     __--/  /  \   (^^)   /  \  \--__
  _-/   /   /  /\ / ( )  /\  \   \   \-_
 /  /   /  /  /  (   ^^ ~  \  \  \   \  \
 / Oli Dragon    ( dragonoe at mcmaster.ca \
/  B.Eng. Sfwr   (     )    \    \  \    \
/  /  /    /__--_ (   ) __--__\    \  \  \
|  /  /  _/        \_ \_       \_  \  \  |
 \/  / _/            \_ \_       \_ \  \/
  \_/ /                -\_\        \ \_/
    \/                    )         \/
                        *~
        ___--<***************>--___
       [http://dragon.homelinux.org]
        ~~~--<***************>--~~~
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050731/3c549749/attachment.bin


More information about the antlr-interest mailing list