[antlr-interest] Re: Match until "<@"

praveen_c praveen_c at yahoo.com
Sun May 12 16:26:50 PDT 2002


Thanks for the reply.

In your previous mail you mentioned that this kind of problem is 
hard for a lexer. Suppose I have tokens T1, T2 and T3 that my 
lexer can recognize. I want all the REMAINING text that is not part 
of T1, T2 and T3 to be another token T4( assume that T1, T2 and T3 
can occur in any order ). Is there an easy way to specify this in 
the grammar? I think I can come up with a long semantic predicate 
that is negation of T1, T2 and T3. But like you said that doesn't 
sound very clean.

So here is my question, is this a limitation of Parser Generators? 
or is this specific to antlr. Am I better off using another Parser 
Generator like JavaCC?

Before somebody flames at my post, please note that I'm just 
about Parser Generators and I donot have a CS degree.

Thanks for your time,

--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
> On Wednesday, May 8, 2002, at 01:33  PM, praveen_c wrote:
> > Hi all,
> >
> > Just wondering what is wrong with the following Lexer rule. I'm
> > trying to match all characters until reach the combination "<@"
> > including white space, new lines...everything.
> >
> > MULTI_LINE_TEXT: ( options { greedy=false; } : .)* (~("<@"));
> >
> > It gives me wierd errors. Is this the right way to specify when I
> > want to have something matched until I see a combination. If you
> > think there is a better way, please let me know.
> What is the k value?  Has to be 2 at least.  Also, note that you 
> asked it to match anything until it sees NOT <@.  If you don't 
> the <@ in this token, you have a problem that is hard for a lexer 
> any token can follow MULTI_LINE_TEXT in principle.  You should 
> use a semantic predicate that tells it how to break out:
> MLT : ( {!(LA(1)=='<'&&LA(2)=='@')}? . ) ;
> That will work, but I dislike syntax checks in semantic 
> Seems this "break out of the loop" issue came up before...might 
> the archives.
> Ter


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 

More information about the antlr-interest mailing list