<rbejar <at> unizar.es> writes:
[...]
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
[...]
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!