[antlr-interest] Mismatched Character, expecting set null

Kevin J. Cummings cummings at kjchome.homeip.net
Fri Aug 6 09:07:41 PDT 2010


On 08/06/2010 07:33 AM, John B. Brodie wrote:
> Greetings!
> 
> On Fri, 2010-08-06 at 02:16 -0400, Ken Klose wrote:
>> Hello,
>>
>> I'm writing my first grammar and have started with something painfully
>> simple but yet cannot figure out why I am receiving errors.   At this point
>> I expect my grammar to recognize a whitespace delimited list of integers.
>> Any help is appreciated.

>> detail: ( integer );
>
> this rule recognizes just one integer! not a list....
> 
> detail : INTEGER + ;

Shouldn't it also end with an EOF?

detail : INTEGER+ EOF ;

>> integer: ( DIGIT )+;
> 
> should probably be a lexer rule
> 
> INTEGER : ( DIGIT )+ ;

INTEGER : DIGIT+ ;

No need to the ()'s.
Also, then he doesn't need to remove the "fragment" from the DIGIT rule.

>> fragment DIGIT: '0'..'9';
>> fragment LETTER : ('a'..'z' | 'A'..'Z');
>>
>> WS: (' ' | '\t' | '\n' | '\r' | '\f') {$channel = HIDDEN;};
> 
> this rule recognizes (and then ignores) just a single white-space
> character. would be more efficient as
> 
> WS : ( ' ' | '\t' | '\n' | '\r' | '\f' )+ {$channel=HIDDEN;} ;

Maybe, but doesn't it ignore *every* single WS character?
No need to use the + in that case (unless the performance benefit is
significant).

-- 
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list