[antlr-interest] Suppressing spurious warnings
Steve Bennett
stevagewp at gmail.com
Wed Feb 27 15:57:58 PST 2008
On 2/28/08, Gavin Lambert <antlr at mirality.co.nz> wrote:
> You can suppress the warning by removing PRE_OPEN from the tokens
> block and adding a fragment rule for it instead:
>
> fragment PRE_OPEN: ' ';
Ok, but that's still kind of annoying: I have to add fake code in
order to suppress a warning. Since I want to use this grammar as
documentation for the language, any code that exists just to make
ANTLR shut up while not adding any information about the language is a
Bad Thing.
No chance of an options { suppress_warning_undefined_token; } ?
> At present, the only way to remove these warnings is to rewrite
> your grammar to remove the ambiguity. Note that while ANTLR often
> does the right thing anyway, you can't just assume that. You
> should always either rewrite the grammar or test its behaviour
> thoroughly. Or both.
Why can't I assume that ANTLR will do the correct thing? Is there an
example of somewhere where it does the unexpected thing? I do plan on
testing thoroughly, btw.
Also, when you say "at present", is there a chance of that warning
suppression being added?
> True left-recursion is fatal to ANTLR, so must be corrected.
> I have yet to see a case where ignoring this warning is a good
> idea.
I'm sure you're right, I just can't find the source of it.
I notice also that for my grammar with backtrack=true, I don't get
that warning in ANTL 3.0.1, but in ANTLR 3.1b1 it becomes a fatal
error:
error(10): internal error:
org.antlr.tool.Grammar.createLookaheadDFA(Grammar.java:1138): could
not even do k=1 for decision 20; reason: timed out (>1000ms)
warning(205): mediawiki12.g:885:44: ANTLR could not analyze this
decision in rule bold_and_italics; often this is because of recursive
rule references visible from the left edge of alternatives. ANTLR
will re-analyze the decision with a fixed lookahead of k=1. Consider
using "options {k=1;}" for that decision and possibly adding a
syntactic predicate.
Here's the code:
bold_and_italics options {backtrack=false;}:
{textis("''") && text_italics}? => APOSTROPHES
{text_italics=false; System.out.print("</i>"); } ->
^(I_OFF)
|{textis("''") && !text_italics}? => APOSTROPHES
{text_italics=true; System.out.print("<i>"); } -> ^(I_ON)
|{textis("'''") && text_bold}? => APOSTROPHES {text_bold=false;
System.out.print("</b>"); } -> ^(B_OFF)
|{textis("'''") && !text_bold}? => APOSTROPHES {text_bold=true;
System.out.print("<b>"); } -> ^(B_ON)
|{textis("''''") && text_bold}? => APOSTROPHES {text_bold=false;
System.out.print("'</b>"); } -> APOSTROPHE ^(B_OFF)
|{textis("''''") && !text_bold}? => APOSTROPHES {text_bold=true;
System.out.print("'<b>"); } -> APOSTROPHE ^(B_ON)
|{textis("'''''") && text_bold && text_italics}? => APOSTROPHES
{text_bold=false; text_italics=false; System.out.print("'</b> </i>");}
-> ^(B_OFF) ^(I_OFF)
|{textis("'''''") && text_bold && !text_italics}? => APOSTROPHES
{text_bold=false; text_italics=true; System.out.print("'</b> <i>");}
-> ^(B_OFF) ^(I_ON)
|{textis("'''''") && !text_bold && text_italics}? => APOSTROPHES
{text_bold=true; text_italics=false; System.out.print("'<b> </i>"); }
-> ^(B_ON) ^(I_OFF)
|{textis("'''''") && !text_bold && !text_italics}? =>APOSTROPHES
{text_bold=true; text_italics=true; System.out.print("'<b> <i>");}
-> ^(B_ON) ^(I_ON)
// Hopefully we never get more than 6 or less than 2. The lexer
should take care of that.
;
Steve
More information about the antlr-interest
mailing list