help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with Flex input matching


From: sean charles
Subject: Re: Help with Flex input matching
Date: Tue, 12 Apr 2005 11:52:46 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

 <rbejar <at> unizar.es> writes:

> 
> Hi all,
> 
> I don't understand well how flex matches de input when more than two patterns 
> match for some text. According to the Flex 2.5 manual: 
> 
> "... If it finds more than one match, it takes the one matching the most text 
> (for trailing context rules, this includes the length of the trailing part, 
> even though it will then be returned to the input). If it finds two or more 
> matches of the same length, the rule listed first in the flex input file is 
> chosen. "
> 
> According to this, I would expect the next flex program:
> 
>      %%
>      uva {printf("3");}
>      xu {printf("4");}
> 
> with this input:
>      xuva
> 
> to generate this output, because chosing the first rule would match more 
> characters from the input:
>      x3
> 
> but it is generating this output instead:
>      4va
> 
> I am using Flex 2.5.4 on HP-UX. Anyone could help with this?
> 
> Thanks in advance.
> 
>    Ruben Bejar
> 

Ruben,

The output you have is what I would expect anyway. I think you are placing too
much cleverness on flex! The 'xu' rule is satisfied because it is the first
complete match. Let me ask you this; assuming it could match the 'uva' from
those rules, what does it do with the 'x' first? it has to consume the x to find
the start of the match for 'uva' doesn't it, therefore, the 'xu' rule is bound
to match first.

If you gave it the input:

    xuuva

then i think the output might be a little different ie what you were expecting
(I think, going on the top of my head now) so you either have to rethink your
input or your grammar, or both!

Good luck







reply via email to

[Prev in Thread] Current Thread [Next in Thread]