 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Victor Bazarov Guest
|
Posted: Wed Oct 29, 2003 9:34 pm Post subject: Re: Preprocessing numbers |
|
|
"Ron" <no (AT) spam (DOT) com> wrote...
| Quote: | The C++ standard ISO/IEC 14882 specifies pp-numbers as follow:
pp-number:
digit
.digit
pp-number digit
pp-number nondigit
pp-number e sign
pp-number E sign
pp-number .
To me this definition appears too liberal, for example following this
production rule and using left recursion i can even write:
pp-number
=> pp-number E sign
=> pp-number e sign E sign
=> pp-number . e sign E sign
=> .digit . e sign E sign
that, if i'm right, doesn't mean anything.
|
Yes, it would constitute a syntax error. However, the syntax is
checked _after_ the text is converted into preprocessing tokens,
one of which is a pp-number.
| Quote: | Now my question is, what exactly
are these pp-numbers?
|
It's a PreProcessing token that will be treated as a Number after
all source code is converted into tokens. Yes, there can be some
sequences that will not really represent a number, once the compiler
gets to it and analyses it. However, it's not a concern of the
preprocessor.
| Quote: | Please, can you show me a concrete example?
|
int main() {
return 1e1e1;
}
will be split into these pp-tokens:
<identifier 'int'>
<identifier 'main'>
<pp-op-or-punc '('>
<pp-op-or-punc ')'>
<pp-op-or-punc '{'>
<identifier 'return'>
<pp-number '1e1e1'>
<pp-op-or-punc ';'>
<pp-op-or-punc '}'>
Now, once the compiler sees the "number" '1e1e1', it will try
to figure out what it is, and will fail.
| Quote: | What are
they used for?
|
The preprocessor needs to separate the text into tokens so it
can substitute macros with what they expand into. Without
parsing the text such substitution would be impossible.
| Quote: | Why the production rule allow to construct almost anything,
including senseless tokens?
|
Because putting too much onto preprocessor would make it very
complicated.
Victor
|
|
| Back to top |
|
 |
Mike Spencer Guest
|
Posted: Thu Oct 30, 2003 5:11 am Post subject: Re: Preprocessing numbers |
|
|
Ron wrote:
| Quote: | that, if i'm right, doesn't mean anything. Now my question is, what exactly
are these pp-numbers? Please, can you show me a concrete example? What are
they used for? Why the production rule allow to construct almost anything,
including senseless tokens?
Greetings.
|
A pp-number does not have to turn into an integer or floating point
number. For example:
#define str(X) #X
#define concat(X,Y) X##Y
char const * s = str (2.3.4);
int concat (ABC, 1e23e45);
float i = concat (1e,10);
I think this rule makes sense. Take the pp-number
2.3.4
You could say instead this should be an error, or maybe two separate
tokens:
2.3 .4
The pp-number may not turn into a real number, so it's probably not a
good idea to say it's an error. And it doesn't make sense to consider
it two separate tokens either, as nowhere in C++ is it legal to have
one number follow another.
Though you could argue that
234xyz
should be the two tokens 234 and xyz; if xyz is a macro to an operator
this could be legal C++. But what about
234i64
You don't want this to be one pp-number on one machine (because of the
i64 integer suffix) and two pp-numbers on another, do you? As it is
now, the preprocessor doesn't need to worry about suffixes.
Mike
--
Lzz: The Lazy C++ Programmer's Tool
http://www.lazycplusplus.com
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|