[antlr-interest] ANTLR 3.3 Bug?

David Beckedorff david.beckedorff at gmail.com
Sun Jan 2 09:41:31 PST 2011


Sorry for the delay in responding ... was at Stowe, VT for a ski week & lost
focus on ANTLR   :>)   Not much snow there though -- the big Nor'Easter hit
further south.

Sam, thank you! thank you!  But, of course, an unclosed string! For some
reason, it never occurred to me to check for that -- I just assumed ANTLR
knew what it was doing when it said the error was on a specific line number.

I installed the ANTLR syntax definitions for TextPad & immediately located
the problem.

And Sam & Kyle, many thanks to both of you for your good advice and quick
responses! That will allow me to move on rapidly to the AST tree grammar
from my current development stage.

One follow-on question ...  how does one turn or some sort of debugging mode
for grammar analysis? If I could have looked at the last token collected, I
would have seen that it spanned several lines & the problem would have been
obvious. It looks like there was such a flag in ANTLR 2.7 but I don't see it
in 3.x.

Happy New Year,
David




On Fri, Dec 31, 2010 at 11:39 AM, Kyle Ferrio <kferrio at gmail.com> wrote:

>
> David,
>
> Sam's advice is wise.  BOth the ANTLR IDE and ANTLRWorks rely on antlr
> itself for many diagnostics, which may take some time to interpret. (I say
> this as someone who tends to understand error messages after the error is
> fixed.)  I just happen to have the ANTLR IDE 2.1.1 open right now, so I did
> this, without needing to know more about your grammar:
>
> *grammar DB;
>
> program : declaration* ;
>
> declaration
>     : tickSpec
>     | location
>     ;
>
> tickSpec
>     : 'TICK' '=' INTEGER
>
>     ;
>
> location
>     : 'LOC' '=' '(' numericalRange ',' numericalRange ')'
>     | '$TITLE'
>     | '$LEGEND'
>     ;
>
> // This is a total guess.
> numericalRange
>     : INTEGER '..' INTEGER
>     ;
>
> // This is a pretty good guess.
> INTEGER : '0'..'9'+ ;
>
> WS : (' '|'\t'|'\r'|'\n'|'\f')+ {$channel=HIDDEN;};*
>
> ANTLR IDE saves this grammar with no errors, and the following input parses
> exactly as expected in the interpreter:
>
> *TICK = 11
> LOC = (1..4,7..11)
> *
> A couple suggestions from experience:  Like Sam's advice about apostrophes,
> be very careful about ANTLR's own rule-delimiting tokens: semicolons, colons
> and vbars (|'s). (Syntax highlighting in ANTLR IDE will not help you here.)
> The usual divide-and-conquer approach to debugging applies. Since your
> grammar worked fine for me with just a little glue, it may be that problems
> are being detected some "distance" away from inception.  And as always make
> sure you have a suitable whitespace rule and that its not left on the
> default channel unless whitespace is actually semantic in your language (not
> recommended).
>
> Good Luck!
>
> Kyle
>
>
> On Thu, Dec 30, 2010 at 8:37 PM, David Beckedorff <
> david.beckedorff at gmail.com> wrote:
>
>> Antlr-interest List,
>>
>> I'm trying to build a parser with the ANTLR IDE 2.1.1 Eclipse plugin and
>> the
>> ANTLR 3.3 library. I'm getting a bunch of cryptic error messages for some
>> of
>> my parser rules.
>>
>> For example, for this rule:
>>
>> tickSpec
>>    :   'TICK' '=' INTEGER
>>    ;
>>
>> I get:
>>
>> error(100): /EZM Project 01/src/com/dlb/ezm/ezm01/Ezm01.g:174:14: syntax
>> error: antlr: unexpected token: ' '
>>  |---> :   'TICK' '=' INTEGER
>>
>>
>> and for the rule:
>>
>> location
>>    :   ( 'LOC' '=' '(' numericalRange ',' numericalRange ')' )
>>    |   '$TITLE'
>>    |   '$LEGEND'
>>    ;
>>
>> I get:
>>
>> error(100): /EZM Project 01/src/com/dlb/ezm/ezm01/Ezm01.g:182:15: syntax
>> error: antlr: unexpected token: ' '
>>  |---> :   ( 'LOC' '=' '(' numericalRange ',' numericalRange ')' )
>>
>> error(100): /EZM Project 01/src/com/dlb/ezm/ezm01/Ezm01.g:182:23: syntax
>> error: antlr: unexpected token: ' numericalRange '
>>  |---> :   ( 'LOC' '=' '(' numericalRange ',' numericalRange ')' )
>>
>>
>>
>> Why do I get an unexpected token ' ' error message for the whitespace
>> between tokens like 'TICK' or 'LOC' and '=' ? Why doesn't ANTLR just
>> absorb
>> the whitespace and move on to the '=' token??
>>
>> I have a whitespace rule in effect, namely:
>>
>> WS : (' '|'\t'|'\n'|'\r'|'\f')+ { $channel = HIDDEN; } ;
>>
>>
>> -David Beckedorff
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>


-- 

David Beckedorff
57 Emerson Rd.
Wellesley, MA  02481

Home:  (781) 235-0061
Cell:  (781) 820-0567


More information about the antlr-interest mailing list