[antlr-interest] Antlr grammar for xml like grammar
Raphael Reitzig
r_reitzi at cs.uni-kl.de
Mon Aug 25 01:02:59 PDT 2008
Hi!
Lexer rules are greedy and tried top-down. So, first ANTLR tries to
match your input against TOK_TEXT. This works perfectly for ML
comments as well, thus a token TOK_TEXT is created.
To get the behaviour you want, there are two possibilities:
1. change the order of your rules in such a way that they are
occurring in an order of increasing generality.
2. use predicates. this can even be necessary if 1. fails, exspecially
when there is no order as described.
There may be a solution including turning of greedy mode for some
rules, but I have no experience with this.
Regards
Raphael
Ymo <ymo.mail at gmail.com> wrote (Mon Aug 25 05:50:08 2008):
> Hi.
>
> I am trying to write a lexer for an xml like grammar. I am pulling my hear
> for i don't understand why it is not working.
>
> The grammar goes like this :
>
> TOK_TEXT
> <% ... %>
> TOK_TEXT
> <%@ .... %>
> <%-- COMMENT --%>
>
>
> I can't figure why my ml comments are getting eaten by the TOK_TEXT token
> always.
>
> YOur help is greatly appreciated !
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: PGP Digital Signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080825/f1afe5e3/attachment.bin
More information about the antlr-interest
mailing list