[antlr-interest] 'match not' not working
Steven Obua
obua at me.com
Tue Aug 4 06:20:46 PDT 2009
On Aug 4, 2009, at 3:08 PM, michael wrote:
> Am Dienstag, 4. August 2009 14:52:40 schrieb Tom:
>> I have a pretty simply grammar to construct; it must find balanced
>> tokens in a stream. For example:
>> aaa %{ bbb }% ccc
>>
>> These may be nested:
>> aaa %{ aaa %{ bbb }% ccc }% ccc
>>
>> or not present at all:
>> aaa
>>
>> or consequtive:
>> aaa %{ bbb }% ccc %{ bbb }% ccc
>>
>> So all a need to do is find the tokens with non-tokens in between.
>> This
>> is the grammar I expected that would do that:
>>
>> /*------------------------------------------------------------------
>> * PARSER RULES
>> *------------------------------------------------------------------*/
>>
>> noloop: (~( LOOPSTART | LOOPEND ))*
>> ;
>
> this combination of scanner rules, negation and parser rule is not
> easy to get
> to work.
>
> Have you tried to add a lexer rule:
>
> NOLOOP: (~( LOOPSTART | LOOPEND ))*;
This probably will not work, as LOOPSTART and LOOPEND consist of two
characters, not only one.
For example, in "%{}%" the first % will match NOLOOP, leaving an
unbalanced string.
I had also problems with not, although I only used lexer rules (see my
post Strange Lexing behavior).
Cheers,
Steven
>
> this should match all other characters, then use this token in your
> parser
> rules...
>
> allthough Ihave not tried it...
>
> cheers
> Michael
>
>
> 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