Related articles |
---|
Need help lexing string literal doane@them.com (1996-07-31) |
Re: Need help lexing string literal mulder@dce.philips.nl (Ruud Mulder RAF448 85606) (1996-08-01) |
Re: Need help lexing string literal kanze@lts.sel.alcatel.de (1996-08-04) |
Re: Need help lexing string literal henry@zoo.toronto.edu (Henry Spencer) (1996-08-04) |
From: | Henry Spencer <henry@zoo.toronto.edu> |
Newsgroups: | comp.compilers |
Date: | 4 Aug 1996 00:34:15 -0400 |
Organization: | SP Systems, Toronto |
References: | 96-07-213 |
Keywords: | lex |
doane@them.com (Jay Doane) writes:
>I'm no expert with regexps, so if someone can give me some pointers,
>the correct regexp for which I'm looking, or someplace that has lots
>of different examples, where I might better educate myself, I'd be
>most appreciative.
The right way to handle this is to think of a string as an opening quote,
some "string elements", and a closing quote. A string element is normally
a single character, but can be a multi-character sequence started by a
backslash. So here's an RE for C strings, with white space inserted for
clarity, and with all backslashes standing for themselves:
" ( [^"\] | \[\abfnrtv"] | \[0-7][0-7]?[0-7]? )* "
This does assume that all backslash-newline processing has been done first,
and that the RE is being matched against a single line (that being the way
my experimental C parser, from which the above is taken, did things).
--
| Henry Spencer
| henry@zoo.toronto.edu
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.