How to handle special strings in lex.

"Frank B. Pound" <fpound@fau.campus.mci.net>
24 Sep 1997 00:08:28 -0400

          From comp.compilers

Related articles
How to handle special strings in lex. fpound@fau.campus.mci.net (Frank B. Pound) (1997-09-24)
| List of all articles for this month |
From: "Frank B. Pound" <fpound@fau.campus.mci.net>
Newsgroups: comp.compilers
Date: 24 Sep 1997 00:08:28 -0400
Organization: Florida Atlantic University
Keywords: lex, question, comment

How would I handle the following cases for a string.
Where a string begins and ends with quotes and is zero or more pintable
characters, spaces or escape sequences.
Allowing the following escape sequences and all others being illegal.


\n
\t
\^c
\ddd <ascii code ddd>
\"
\\
\f___f\ where f___f stands for a sequence of one or more formatting
characters (including space,tab,newline,formfeed)


Would this work?


\"[^\"]*\" {yylval.sval=strdup(yytext[yyleng]); return STRING;}


I'm very very new to lex and programming in general. So I may have made
some mistake here in my regular expressions.
Thanks
Frank B. Pound
fpound@fau.campus.mci.net
http://www.cse.fau.edu/~fpound
[Rather than try to write incredibly complex regular expressions, I'd
read the string, then make a pass over it to squeeze out the escape
sequences. -John]
--


Post a followup to this message

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