[comp.bugs.4bsd] Bug in lex?!?

siegel@hc.DSPO.GOV (josh Siegel) (09/13/88)

(I have only tested this under SunOS 4.0 and BSD4.3)

The following code makes lex produce C code with a syntax error in it:
-----
W	[ \t]+	
%%
^{W}%	{ }
%%



same for:
-----
W	[ \t]+	
%%
^{W}\%	{ }
%%


but not for:
-----
%%
^[ \t]+%	{ }
%%

Comments?
			--Josh Siegel
-- 
Josh Siegel		(siegel@hc.dspo.gov)
I like using a C-47A "puff dragon" to go shooting beer cans with.

ejp@ausmelb.oz (Esmond Pitt) (09/14/88)

In article <14373@hc.DSPO.GOV> siegel@hc.DSPO.GOV (josh Siegel) writes:
> (I have only tested this under SunOS 4.0 and BSD4.3)
>
> The following code makes lex produce C code with a syntax error in it:
> -----
> W	[ \t]+	
> %%
> ^{W}%	{ }
> %%

This also happens on a Pyramid under both att & bsd universes (i.e.
both lex's), probably because '%' is a special character to lex.
^{W}"%" also fails.

However the example works correctly & is in somewhat better (safer)
style if the definition of W is written as:

	W	([ \t]+)

Lex definitions should _always_ be parenthesised, for the same reason
that #defines which yield expressions should always parenthesise them:
to ensure that the apparent and real precedences are the same.

-- 
Esmond Pitt, Austec International Ltd
...!uunet.UU.NET!munnari!ausmelb!ejp,ejp@ausmelb.oz