From: "David Thompson" <david.thompson1@worldnet.att.net>
Subject: Re: Ada -> C or C++ translator
Date: Sat, 13 Jul 2002 22:55:38 GMT
Date: 2002-07-13T22:55:38+00:00 [thread overview]
Message-ID: <Kd2Y8.100252$UT.6457445@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 3D2315CA.7050807@attbi.com
Robert I. Eachus <rieachus@attbi.com> wrote :
...
> There was a project many years ago that had us all laughing when we
> found out what was going on. You could probably use the same technique...
> [emacs and C macros to take subset-Ada and make it work as C]
...
> I know it sounds hard, but once they got started, the #defines were easy:
>
> #define begin {
> #define end } \/\/
> (Did I get that right? It has been so long since I did "clever" things
> in cpp. The intent of course is to make everything following the end
> keyword a comment.)
>
I doubt it, or at least not portably.
At least in any standard-conforming (post 89) implementation,
comments become logical whitespace _before_ macro substitution,
which can't legally "construct" a comment, although many implemenations
generate preprocessor output as text and re-parse it (which is not required,
but often convenient) and support deferring comments to the latter stage
to make the preprocessed output more informative.
Plus double-slash comments didn't exist in original/traditional C or C89;
they were (re)introduced in C++ in the early 1990's and migrated back to C,
standardized only in C99.
But most important, backslash+slash is outright illegal. Backslash
escapes are legal only in character and string literals, where they are
interpreted only during compilation proper (translation phase 7) after
preprocessing is completed; and inside comments they are ignored.
Backslashes are NOT handled differently in preprocessing directives,
or macros. Line splicing using backslash+physical-end-of-line is a
separate though similar looking case, technically not an escape, and
is equally legal everywhere -- though it is generally only needed, and
hence used, on preprocessor directives. (And in C++98 and C99 UCNs,
basically Unicode escapes, are also legal in/as an identifier for
alphanumeric-ish characters only.)
Although a compiler, or possibly preprocessor, could use \/ for some
kind of extension, I have never heard of one doing so, and certainly
not turning it into a comment-introducing token as you want here.
The closest you can rely on is a "function-like" (parameterized) macro
that ignores/discards its argument, but usage is not transparent:
#define end(x) }
... begin /*foo*/ ... end(foo) ...
--
- David.Thompson 1 now at worldnet.att.net
next prev parent reply other threads:[~2002-07-13 22:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-17 12:26 Ada -> C or C++ translator David Rasmussen
2002-06-17 12:51 ` Martin Dowie
2002-06-17 12:59 ` David Rasmussen
2002-06-17 14:21 ` Larry Kilgallen
2002-06-17 14:19 ` David Rasmussen
2002-06-28 18:40 ` pontius
2002-06-29 1:47 ` tmoran
2002-07-01 14:30 ` pontius
2002-07-03 15:16 ` Robert I. Eachus
2002-07-13 22:55 ` David Thompson [this message]
2002-06-18 23:41 ` Robert A Duff
2002-06-19 0:21 ` exceptions and C functions (was Re: Ada -> C or C++ translator) Dale Stanbrough
2002-06-19 1:44 ` Robert A Duff
2002-06-19 14:32 ` Wes Groleau
2002-06-19 17:33 ` Robert A Duff
2002-06-19 17:58 ` Wes Groleau
2002-06-19 19:17 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox