Re: (f)lex string with double quotes

"J.H.Jongejan" <jjan@cs.rug.nl>
27 Sep 2003 14:00:00 -0400

          From comp.compilers

Related articles
(f)lex string with double quotes gkokmdam@zonnet.nl (Joop) (2003-09-23)
Re: (f)lex string with double quotes jjan@cs.rug.nl (J.H.Jongejan) (2003-09-27)
| List of all articles for this month |
From: "J.H.Jongejan" <jjan@cs.rug.nl>
Newsgroups: comp.compilers
Date: 27 Sep 2003 14:00:00 -0400
Organization: RuG
References: 03-09-076
Keywords: lex
Posted-Date: 27 Sep 2003 14:00:00 EDT

Joop wrote:
> Hi all,
> could anyone help me to a lex regular expression that will pick-up a
> string of the format:
> "Any text and a double quote like this "" and this too"
> This is what some silly language uses and I need to read it with my
> (f)lex program. I just don't know how to go about it.
> wkr,
> Gerke
> [There's a bunch of ways to do it. The simplest is something like this:
>
> \"([^")|\"\")*\"
>
> but since strings can be long, I'd rather use start states to go into
> a string scanning state and then back out. -John]


I use this one as an example in manipulating regular expressions.
If 'q' stands for a quote and 'a' for anything not equal to a quote,
a '|' stands for choice and '*' for a repetition of zero or more,
then a regular expression for strings looks like:
        q(a|qq)*q
This looks like a problem when a 'q' is the next input.
However, this is equivalent to:
        qa*q(qa*q)*
which is much easier to convert into an accepting automaton (program).


My $0.02


Jan Jongejan
Dept. Comp.Sci.,
Univ. of Groningen,
Netherlands.
email: jjan@cs.rug.nl


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.