help-bison
[Top][All Lists]
Advanced

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

Re: ambiguous grammar tokens


From: Tim Van Holder
Subject: Re: ambiguous grammar tokens
Date: 22 Feb 2002 10:52:31 +0100

On Fri, 2002-02-22 at 09:40, babar haq wrote:
> hi ppl
> its me again.
> i am experiencing a problem regarding having correct tokens returned from lex 
> function to yacc function.

This really belongs on a (f)lex mailing list, you know.

> i want two tokens to be returned for following expresions
> 
> -->1*(alpha-numeric) {return ALNUM;} means strings having one or more 
> alpha-numeric characters.
> 
> -->4*(alpha-numeric|"-"|"."){return OTHER} means strings having four or more 
> alphanumeric char or "-" or "." characters.
> 
> the problem is that lex function do not return tokens correctly. it returns 
> ALNUM when i am expecting OTHER to be returned. or vice-versa.
> 
> what should i do??

Well, I don't know about lex, but flex has a {} construct:


...
alnum   [[:alnum:]]
...

%%

...

{alnum} { return ALNUM; }

({alnum}|[-.]){4,}      { return OTHER; }

...

%%



This _should_ do what you want, I think.
The syntax is

  x{n}   -> exactly n occurrences of x
  x{n,m} -> between n and m occurrences of x
  x{n,}  -> n or more occurrences of x





reply via email to

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