473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Preprocessing numbers

Ron
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. 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.

Jul 19 '05 #1
2 4785
"Ron" <no@spam.com> wrote...
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.
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.
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.
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.
Why the production rule allow to construct almost anything,
including senseless tokens?


Because putting too much onto preprocessor would make it very
complicated.

Victor
Jul 19 '05 #2
Ron wrote:
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

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ron | last post by:
Please, consider the following code: const int a = 1; #if a == 1 #define VAR 200 #else #define VAR 100 #endif int main() {
1
by: Alex Sedow | last post by:
Where to get/buy tool for partial preprocessing? 1. What I mean by partial macro preprocessing. This is mode in which almost sources (>99%) is not preprocessed. But some macros (setted by...
12
by: Francois Grieu | last post by:
Can #include safely use a preprocessing token, as in #define HEADERFILE "stdio.h" #include HEADERFILE int main(void) {return printf("Hello, world\n")*0;} TIA, François Grieu
1
by: Xiangliang Meng | last post by:
Hi, all. Recently, I find there is a way in our project to maintain a global set in many files by using preprocessing directives. I'm wondering if we could find a better method for this. Many...
3
by: Frodo Baggins | last post by:
Hi All, I have a piece of code (not written by me) that is failing on compile with the error: pasting "xdr_ndmp_connect_open_request" and "," does not give a valid preprocessing token The...
5
by: cody | last post by:
the following leads to an error (note that TEST is not defined): #if TEST string s = @" #"; // <-- the error is "preprocessing directive expected" #endif also, here we get the same error: ...
4
by: Henrik Goldman | last post by:
I have an application which compiles on a number of different platforms. Now I'm trying to incorporate an external library which is only available to a subset of the platforms that my application...
5
by: Francois Grieu | last post by:
One of the C compiler that I use <OT>(Keil's CX51)</OTbarks at #define a(b) b int main(void){return a( #if 0 #endif 0);} More generally, this compiler seems confused by any preprocessing...
40
by: Bill Cunningham | last post by:
I have been thinking about hiding headers from my compiler's preprocessor and allowing others to be shown. I want to use the most used and add others is necessary. Would this be how it is properly...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.