Give me your strings.

William A. Hoffman hoffman at nunki.crd.ge.com
Thu Feb 14 05:52:18 AEST 1991


:...  I'm looking for an executable that knows enough C
:(or Pascal, ...) syntax to isolate string constants, and echo them out
:to a file (possibly stdout).


What about a simple lex program: string.lex

--------------------------------------------------------
string       \"([^"\n]|\\["\n])*\"
%%
{string}	printf("%s\n", yytext); return(1);
\n		;
.		;
%%
main()
	{
	int i;

	while(i= yylex())
		;
	}

yywrap()
	{
	}
------------------------------------------------------------
to run just:
lex string.lex
cc lex.yy.c -o string
string < *.c
[I'd make it a little bit smarter to handle character constants and
comments, but in general that's the right idea. -John]
-- 
Send compilers articles to compilers at iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.



More information about the Comp.unix.programmer mailing list