Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #2936
| From | gah4 <gah4@u.washington.edu> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: What stage should entities be resolved? |
| Date | 2022-03-17 17:06 -0700 |
| Organization | Compilers Central |
| Message-ID | <22-03-034@comp.compilers> (permalink) |
| References | <22-03-019@comp.compilers> <22-03-025@comp.compilers> <22-03-032@comp.compilers> |
On Thursday, March 17, 2022 at 11:41:47 AM UTC-7, Roger L Costello wrote:
(snip)
> For instance, as I understand it a C preprocessor goes through a C program and replaces macros. With this:
> #define PI 3.14
> the preprocessor will convert this:
> area = PI * radius * radius;
> to this:
> area = 3.14 * radius * radius;
> But if PI is inside a quoted string:
> "Today is PI day"
(You missed by a few days.)
> then the preprocessor does not replace PI.
As well as I know it, the early preprocessor, used by K&R C, did
substitute in strings. The current standard version does not, but some
versions have the --traditional option which might allow it.
It is not unusual to use the C preprocessor with --traditional for
Fortran programs, and some compilers will automate this. Some of the
processing done by the current C standard version messes up Fortran
programs too much.
Note, though, that the C preprocessor is pretty good at ignoring
almost anything, including mismatched quotes, between
#if 0
and the matching
#endif
The text doesn't need to look much like C at all, and can even have
mismatched quotes. It does have to properly process nested #if though.
The PL/I preprocessor isn't quite as forgiving.
At least in the early compilers, like early C compilers, it was
implemented as a separate pass, with intermediate disk file. I suspect
you can't put quite as much garbage between
%IF 0 %THEN %DO
and
%END
and especially likely not unmatched quotes. (PL/I uses apostrophes
for character constants, in both the language itself and the preprocessor.)
Java, on the other hand, does not have a preprocessor. The compiler is
supposed to know enough not to compile statements between
if(0) {
and
}
but I suspect that they need to look a lot like Java statements.
(You can also use a static final variable in such an if statement,
which the compiler knows how to evaluate at compile time.)
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
What stage should entities be resolved? Lexical analysis stage? Syntax analysis stage? Semantic analysis stage? Roger L Costello <costello@mitre.org> - 2022-03-09 17:22 +0000
Re: What stage should entities be resolved? Lexical analysis stage? Syntax analysis stage? Semantic analysis stage? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-10 09:48 +0100
Re: What stage should entities be resolved? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-12 14:11 +0200
Re: What stage should entities be resolved? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-14 19:43 +0100
Re: What stage should entities be resolved? Roger L Costello <costello@mitre.org> - 2022-03-15 11:49 +0000
Re: What stage should entities be resolved? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-18 00:31 +0100
Re: What stage should entities be resolved? gah4 <gah4@u.washington.edu> - 2022-03-17 17:06 -0700
Re: What stage should entities be resolved? Kaz Kylheku <480-992-1380@kylheku.com> - 2022-03-18 17:50 +0000
Re: What stage should entities be resolved? gah4 <gah4@u.washington.edu> - 2022-03-18 14:08 -0700
Re: What stage should entities be resolved? Martin Ward <martin@gkc.org.uk> - 2022-03-19 18:17 +0000
Re: What stage should entities be resolved? "matt.ti...@gmail.com" <matt.timmermans@gmail.com> - 2022-03-20 07:32 -0700
RE: What stage should entities be resolved? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-10 12:54 +0200
Re: What stage should entities be resolved? Lexical analysis stage? Syntax analysis stage? Semantic analysis stage? matt.timmermans@gmail.com - 2022-03-12 05:12 -0800
csiph-web