regex for C comments

Tom Stockfisch tps at chem.ucsd.edu
Wed Jul 12 11:07:26 AEST 1989


In article <19365 at paris.ics.uci.edu> schmidt at zola.ics.uci.edu (Doug Schmidt) writes:
>In their book ``Introduction to Compiler Construction with UNIX,''
>Schreiner and Friedman provide the following LEX regular expression
>for recognizing C comments:
>"/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/"

This expression fails on each of the following:

	/*****//hello world */

	/* hello /* /* world */

So, who has the shortest single LEX expression that correctly
matches C comments --
ignoring string and character constants,
and disallowing start conditions?

Mine is

	"/*"\/*([^/]|{[^*/]\/+})*"*/"
-- 

|| Tom Stockfisch, UCSD Chemistry	tps at chem.ucsd.edu



More information about the Comp.lang.c mailing list