Unixworld competition - SOLUTIONS

andre andre at targon.UUCP
Wed Apr 17 21:08:10 AEST 1991


In article <1991Apr2.012639.25454 at cbnewsh.att.com> gls at corona.ATT.COM (Col. G. L. Sicherman) writes:
>As I promised, here are the bugs in the prize-winning comment-
 [ removed other two programs ]

Now the lex program:

>%}
><STRING>([^\\]\")|(\\\\\")	|
><CHAR>([^.\\]\')|(\\\\\')	|
><CPLUS>\n	{ ECHO; BEGIN CODE; }
><CCOM>"*/"	{ two_space(); BEGIN CODE; }
><CCOM,CPLUS>.	{ output(*yytext=='\t'?'\t':' ');} 
><CODE>"/*"	{ two_space(); BEGIN CCOM ; }
><CODE>"//"	{ two_space(); BEGIN CPLUS ;}
><CODE>\"	{ ECHO; BEGIN STRING; }
><CODE>\'	{ ECHO; BEGIN CHAR; }
><STRING,CODE>.	{ ECHO; }
>%%
>
>This one doesn't handle multiple backslashes, though lex has the power
>to do so easily.  A program like this will break it:
>
>	main()
>	{
>	    char *str = "This string has everything \\\" /* and more!\n";
>
>	    printf(str);
>	}

Oke oke you win, I made a mistake (blush) how about with the following ?
This should fix it no?

Just change the first three lines of the lex part to:

<STRING,TEXT,CHAR>\\.	{ ECHO; }
<STRING>\"	|
<CHAR>\'	|
<CPLUS>\n      { ECHO; BEGIN CODE; }

	happy lexing...

-- 
The mail|    AAA         DDDD  It's not the kill, but the thrill of the chase.
demon...|   AA AAvv   vvDD  DD        Ketchup is a vegetable.
hits!.@&|  AAAAAAAvv vvDD  DD                    {nixbur|nixtor}!adalen.via
--more--| AAA   AAAvvvDDDDDD    Andre van Dalen, uunet!hp4nl!targon!andre



More information about the Comp.lang.c mailing list