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: | doane@them.com (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:
""
"text"
"te\"xt"
"te\\xt"
"te\"xt\\"
although these are not:
"
"\"
"tex"t"
"tex\t"
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.
Thanks,
Jay
--
Jay Doane | doane@them.com | Them Productions, San Francisco | (415) 621-1305
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.