help-flex
[Top][All Lists]
Advanced

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

Re: Flex query


From: Tim Van Holder
Subject: Re: Flex query
Date: Wed, 24 Mar 2004 08:26:53 +0100
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

Karen Loughran wrote:
[snip]

@ { printf("@ received\n"); } [[:alnum:][:punct:address@hidden { printf("ALNUMFIELD received\n"); }

> [snip]

However, as the rule which identifies an ALUMFIELD contains an "*" to
indicate 0 or more occurrences of the characters are allowed I would
expected the output for the following to be the same.

address@hidden

But it decides to treat the first "a" and second "a" as two separate
ALNUMFIELD's and I'm can't understand why.

ALNUMFIELD received
ALNUMFIELD received
@ received
ALNUMFIELD received


Please can you provide an explanation as to why it doesn't treat "aa" to
be one ALNUMFIELD in this case ?
I want to define a rule which accepts any number of alphanumeric and
punctuation characters (except for "@") as one token.

My guess is that it's your ALNUMFIELD rule.  I expect that if you just
use [[:alnum:][:punct:]]* it will work.
There are basically 2 things wrong with the rule you have.  Your intent
seems to be to allow alphanumeric characters or punctuation, but not an @ (which would otherwise be accepted by the [:punct:]. However you
cannot exclude a character once you allow it, so you'll have to spell
out which punctuation characters you DO allow. This does not contribute
directly to the behaviour you see though.
The actual problem seems to be that you got confused by the use of
character classes, which have extra [] inside a character range; the []
around the ^@ however do not have any special meaning.  So my guess is
that flex interpretes that rule as:
  [[:alnum:][:punct:address@hidden followed by ]*
In other words, alphanumeric characters, punctuation or one of '[', '^',
or '@', followed by 0 or more ']'.  To confirm this, move the ALNUMFIELD
rule above the '@' rule - I believe the lexer will then only see
ALNUMFIELD entries.  What you probably want is something like
  [[:alnum:],.;]*






reply via email to

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