[antlr-interest] please help on lexer rules antlr v3
Michiel Vermandel
Michiel_Vermandel at axi.be
Thu Sep 28 00:32:59 PDT 2006
Hi Ter,
I tried your solution but unfortunatly still the wrong rule is used...
I stripped down the grammar to it's smallest in order to test (see blow).
I'm using AntlrWorks 1b3 together with the Antlr version delivered with
AntlWorks.
My test string is:
-- axi.reject
followed by a single CRLF
Any idea why the -- axi.reject is still consumed as a comment (on
channel 99) ?
Thanks!
Michiel
---------------------------- grammar --------------------------
grammar TestParser;
options {k=2; backtrack=true; memoize=true;}
statement: (directive )+ EOF;
directive: DIRECTIVE;
LF : '\n' { channel=99; };
CRLF : '\r' ('\n')? { channel=99; };
TAB : '\t' { channel=99; };
SPACE : ' ' { channel=99; };
fragment
ANYTHING_2_EOL: (~('\n'|'\r' ))* ('\n'|'\r'('\n')?);
fragment
DIRECTIVE: (SPACE | TAB )* ('axi.locate' | 'axi.reject');
// Single-line comment
SL_COMMENT: '--' ( DIRECTIVE | ( ANYTHING_2_EOL { channel=99;} ) );
WS : ( TAB | SPACE | CRLF | LF )+ { channel=99; };
--------------------------------------------------------------------------------------------------------------------
On Sep 27, 2006, at 6:50 AM, Michiel Vermandel wrote:
>
> Hi,
>
> I have the following two rules in my lexer.
>
> DIRECTIVE: '--' (TAB | SPACE)* ('axi.locate' | 'axi.reject');
>
> // Single-line comments
> SL_COMMENT: '--' (~('\n'|'\r'))* ('\n'|'\r'('\n')?) { channel=99; };
>
> the general idea is that
>
> -- axi.locate
> -- axi.reject
>
> are compiler directives,
>
> -- followed by anything else
>
> is a comment.
>
> now (obviously :-/ ) everything starting with -- is consumed by the
> SL_COMMENT rule.
LL(*) should handle this, but if not, then just do
SL_COMMENT : '--' DIRECTIVE | ... ;
fragment DIRECTIVE : ... (TAB | SPACE)* ('axi.locate' | 'axi.reject') ;
Ter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060928/31ff18c4/attachment.html
More information about the antlr-interest
mailing list