Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 05 Nov 2001 12:29:40 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Matthew Emmerton <matt@gsicomp.on.ca>
Cc:        David O'Brien <obrien@FreeBSD.ORG>, Poul-Henning Kamp <phk@FreeBSD.ORG>, hackers@FreeBSD.ORG
Subject:   Re: Idea for project:  Make cpp do unifdef service...
Message-ID:  <3BE6F6B4.D9A0D806@mindspring.com>
References:  <Pine.BSF.4.21.0111051429570.81985-100000@xena.gsicomp.on.ca>

next in thread | previous in thread | raw e-mail | index | archive | help
Matthew Emmerton wrote:
> 
> I looked into this over the weekend.  Although it's fairly trivial to make
> it understand things like '#if defined(FOO)', it's somewhat more tricky to
> understand something like '#if ((!defined(FOO) && defined(BAR)) ||
> defined(FUBAR))', which I believe was the functionality that phk wanted,
> and why he requested it of cpp rather than unifdef.

This is a pretty trivial lex/yacc program to write; I admit
that changing the exiting code to handle this would be
difficult (it's trivial code), but the exiting code already
breaks on the "#" not in the first column, and doesn't handle
things like C++ comments, and does bad things with single and
double quote mixing.  It also doesn't handle numeric constants
correctly.

Given the line rules for preprocessor directives, this would
be an easy program to get right.

If someone wants to do something about this, it would be best,
IMO, to:

o	Rewrite it from scratch in lex and yacc.

o	Do _NOT_ jam it into gcc, both because of the cpp
	maybe going away in the future, and because the
	language and tools dependence that would be added.

It's a good job for someone cutting their teeth on lex/yacc
(hint: you can handle all the stateful stuff using start
states, including the expression evaluation).

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3BE6F6B4.D9A0D806>