home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ukma!asuvax!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.unix.programmer
- Subject: Re: FLEX question
- Message-ID: <1992Nov16.185206.28741@organpipe.uug.arizona.edu>
- Date: 16 Nov 92 18:52:06 GMT
- References: <1992Nov16.171445.26227@tc.cornell.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 41
- In-Reply-To: elan@tasha.cheme.cornell.edu (Elan Feingold)
-
- In article <1992Nov16.171445.26227@tc.cornell.edu>, elan@tasha (Elan Feingold) writes:
- >How does one match things regardless of case? i.e If I want to match
- >the keyword COOKIE, and I don't care what combination of upper and lower
- >letters the person used...
- >
- >Anything but
- >
- >COOKIE CreateCookie();
- >cOOKIE CreateCookie();
-
- There are two approaches you can take:
-
- 1: Brute force
-
- (C|c)(O|o)(O|o)(K|k)(I|i)(E|e) { CreateCookie(); }
-
- 2: 2-level recognition
-
- Letter [a-zA-Z]
- Word {Letter}+
- %%
- {Word} { if( is_cookie(yytext) ) CreateCookie() ;
- else /* whatever */ ;
- }
- %%
- int is_cookie( char *s ) {
- char *t = "cookie" ;
-
- /* this may not work if you have a brain-damaged tolower() */
- while( *s != '\0' && tolower(*s) == *t ) { s++ ; t++ }
- return *s == *t ;
- }
-
- I think #2 is almost always preferrable, since it makes for smaller lex
- tables, and it's easily extendable to other keywords.
-
- --
- You unlock this door with the key of imagination. Beyond it is another
- dimension: a dimension of sound, a dimension of sight, a dimension of mind.
- You're moving into a land of both shadow and substance, of things and ideas.
- You've just crossed over into... the Twilight Zone.
-