[antlr-interest] should sempred questions be asked on trailing optional tokens?

Mark Wright markwright at internode.on.net
Thu May 8 05:14:46 PDT 2008


My question is answered by antlr-2008-05-07.18, which now detects
ambiguities in my grammar that were not detected in earlier
pre-releases:

java -Xmx512m -classpath /h/goanna/2/eng/dev/tntdbo/java_src:/h/goanna/2/eng/dev/tntdbo:/h/goanna/2/ts/antlr/antlr-2008-05-07.18/lib/antlr-2008-05-07.18.jar:/h/goanna/2/ts/antlr/antlr-2008-05-07.18/lib/runtime-2008-05-07.18.jar:/h/goanna/2/ts/antlr/antlr-2008-05-07.18/lib/stringtemplate-3.1b1.jar:/h/goanna/2/ts/antlr/antlr-2008-05-07.18/lib/antlr-2.7.7.jar org.antlr.Tool -Xconversiontimeout 1200000 -report Tntdbo.g
ANTLR Parser Generator  Version 3.1b1 (??)  1989-2007
warning(203): Tntdbo.g:903:32: Input such as "INT" is insufficiently covered with predicates at locations: alt 2: line 909:20 at 'int'
Semantic predicates were present but were hidden by actions.
warning(200): Tntdbo.g:903:32: Decision can match input such as "INT" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.

So after fixing these, by splitting the alternatives to eliminate
the trailing optional tokens on this particular rule like (this is
only a fragment of the rule, the grammar is large):

simple_type_specifier
        :   {sa.isUnsigned((TokenStream)input)}?
                'unsigned'
        |   {sa.isUnsignedInt((TokenStream)input)}?
                'unsigned' 'int'
        |   {sa.isSigned((TokenStream)input)}?
                'signed'
        |   {sa.isSignedInt((TokenStream)input)}?
                'signed' 'int'
        |   {sa.isInt((TokenStream)input)}?
                'int'
        ;

Then it works great.

Of course in most situations trailing optional tokens are fine,
and antlr-2008-05-07.18 lets you know with the new error messages
if there are ambiguities.  

Thanks, Mark

-- 


More information about the antlr-interest mailing list