Need help lexing string literal (Jay Doane)
31 Jul 1996 19:32:29 -0400

          From comp.compilers

Related articles
Need help lexing string literal (1996-07-31)
Re: Need help lexing string literal (Ruud Mulder RAF448 85606) (1996-08-01)
Re: Need help lexing string literal (1996-08-04)
Re: Need help lexing string literal (Henry Spencer) (1996-08-04)
| List of all articles for this month |

From: (Jay Doane)
Newsgroups: comp.compilers
Date: 31 Jul 1996 19:32:29 -0400
Organization: Them Productions
Keywords: lex, question

Hi all,

I'm attempting to parse a string literal, and having no luck. Said
string is delimited by double quotes, but can contain double quotes if
they are escaped with a backslash. A backslash must also be escaped
with a backslash. The following are legal strings:


although these are not:


The lexer/parser (Visual Parse++) that I have to use (in order to use
the same rule file for both C and Delphi -- it's a long story)
maintains a stack of expression lists. I tried something like this:

%expression Main
'\"' StringStart, 'STRINGstart', %push StringLiteral;

%expression StringLiteral
'([^\n"]*(\\\")?[^\n"]*)+' String,'STRINGliteral';
'\"' StringEnd, 'STRINGend', %pop;

Though this fails on "text\".

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.



Jay Doane | | Them Productions, San Francisco | (415) 621-1305

Post a followup to this message

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