[antlr-interest] Unexpected breakage of code

Steve Bennett stevagewp at gmail.com
Mon Dec 3 06:40:52 PST 2007


[I'm sending this as a "something very unexpected happened to poor
naive newbie, he's ok now, but thought you should know"]

A very small change to a lexer rule caused a very obscure error message:

In the following code:
----
RFC_LINK:
  ((RFC_LINK_ACTUAL) => RFC_LINK_ACTUAL
  | LETTER { $type=LETTERS; }
  );

fragment
RFC_LINK_ACTUAL:
    'RFC'
    ' '+
    ('0'..'9')+;
----

If '0'..'9' is replaced by DIGIT (which is defined and used
elsewhere), then the generated code seems to be very different, and
use a "specialStateTransition" method in a class which derives from
DFA. That caused a string of errors of this type:

[01:24:44] \tmp\antlrworks\headerline8Lexer.java:4304: cannot find symbol
[01:24:44] symbol  : variable in_foo
[01:24:44] location: class headerline8Lexer.DFA24
[01:24:44]                                 !this.in_foo &&
[01:24:44]                                  ^

This happens because *that*, totally unrelated, code is no longer in a
method on the lexer class, but has been moved away to this new DFA
class. So you have one apparently insignificant change in one place
causing an obscure message to eminate from an apparently unrelated
place...

Perhaps this is a known issue, but for me it was extremely surprising,
so perhaps there is a way to reduce the impact of it, or something?
Getting Java compile errors is always so disconcerting...

Steve


More information about the antlr-interest mailing list