help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Flex help anyone ?


From: Marco Draijer
Subject: RE: Flex help anyone ?
Date: Thu, 15 Jan 2004 08:05:33 +0100

Mike,

\"([^"]|\"\")*\"
should do the trick, I guess.

However, I usually define exclusive start states for this:

%x SQSTRING DQSTRING
%%
\'  {BEGIN(SQSTRING); strBuf="";}
\"  {BEGIN(DQSTRING); strBuf="";}
<SQSTRING>\'\'  {strBuf+="'";}
<DQSTRING>\"\"  {strBuf+="\"";}
<SQSTRING>\'    {BEGIN(INITIAL); return(STRING);}
<DQSTRING>\"    {BEGIN(INITIAL); return(STRING);}
<SQSTRING,DQSTRING>. {strBuf+=yytext;}

Perhaps you don't need single and double quotes split in two flows, but usually it comes in handy. strBuf is a variable that can be retrieved from yacc when it receives a STRING token.

Note that you should know how to process a newline token: Is it part of the string?
But I know that exclusive start states have their drawbacks, although I have forgotten which ones exactly.


>>> "Ning Cao" <address@hidden> 01/15/04 07:28 AM >>>
Hi,

"Hello " will be matched by the first rule
"World" will be matched by the first rule
and " would be ok" will be also matched by the first rule.

this the reason why you got three strings.


-----Original Message-----
From: address@hidden [mailto:address@hidden]On Behalf Of Mike Aubury (by way of Hans Aberg)

Sent: Thursday, January 15, 2004 1:54 AM
To: Flex Help
Subject: Flex help anyone ?


Yes - I know this is a bison list - but someone might know...


I've got to detect strings so I have matches for :

\"[^\"]+\"    {  return CHAR_VALUE;}
\"\" { return CHAR_VALUE;}




in my flex definition file (or similar at least)
(The first for a string, the second for an empty string)



In the language I'm trying to parse - its permissible to embed quotes within a
string if you double up..

so :

        "Hello ""World"" would be ok"

Obviously - I'm getting this back as three strings ("Hello " , "World"  &
"would be ok") which is messing up the parser...


Any ideas ?



_______________________________________________
address@hidden http://mail.gnu.org/mailman/listinfo/help-bison




_______________________________________________
Help-flex mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/help-flex


--
****************************************************************************
This message contains information that may be privileged or confidential and
is the property of the Cap Gemini Ernst & Young Group. It is only intended
for the person to whom it is addressed. If you are not the intended
recipient, you are not authorized to read, print, retain, copy disseminate,
distribute, or use this message or any part thereof. If you receive this
message in error, please notify the sender immediately and delete all copies
of this message.
****************************************************************************


reply via email to

[Prev in Thread] Current Thread [Next in Thread]