[antlr-interest] Mismatched Character, expecting set null
Jim Idle
jimi at temporal-wave.com
Fri Aug 6 09:22:44 PDT 2010
On Aug 6, 2010, at 9:07, "Kevin J. Cummings" <cummings at kjchome.homeip.net> wrote:
> 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 ;
Unless there is a rule that has detail 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.
No. That would DIGIT and INTEGER ambiguous.
>
>>> 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).
It is hiding, not skipping so you would get a hidden token for every whitespace character. Performance says use skip() and + not HIDDEN
>
> --
> 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)
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list