>>>int('0x', 16)
0
I'm working on a tokenizer and I'm thinking about returning a
MALFORMED_NUMBER token (1.2E, .5E+) 7 1099 Ma************@gmail.com wrote under the subject line "Is this a
bug in int()?":
>>>>int('0x', 16)
0
I think it is a general problem in the tokenizer, not just the 'int'
constructor. The syntax for integers says:
hexinteger ::= "0" ("x" | "X") hexdigit+
but 0x appears to be accepted in source code as an integer.
If I were you, I'd try reporting it as a bug.
I'm working on a tokenizer and I'm thinking about returning a
MALFORMED_NUMBER token (1.2E, .5E+)
Why would you return a token rather than throwing an exception? Ma************@gmail.com wrote:
>>>int('0x', 16)
0
I'm working on a tokenizer and I'm thinking about returning a
MALFORMED_NUMBER token (1.2E, .5E+)
Somewhat surprisingly, "0x" is a valid integer literal in Python:
>>0x
0
</F>
"Duncan Booth" <du**********@invalid.invalidwrote in message
news:Xn*************************@127.0.0.1...
| Ma************@gmail.com wrote under the subject line "Is this a
| bug in int()?":
| >>>>int('0x', 16)
| 0
| >
| I think it is a general problem in the tokenizer, not just the 'int'
| constructor. The syntax for integers says:
|
| hexinteger ::= "0" ("x" | "X") hexdigit+
|
| but 0x appears to be accepted in source code as an integer.
|
| If I were you, I'd try reporting it as a bug.
The mismatch between doc and behavior certainly is a bug.
One should change.
Duncan Booth wrote:
Why would you return a token rather than throwing an exception?
Tokenizers have lots of uses. Colorizing text in an editor, for
example. We've got a MALFORMED_NUMBER when you type '0x'. We've got an
INTEGER when we get your next keystroke (probably).
Tokenizer bug reported.
MartinRineh...@gmail.com wrote:
>>int('0x', 16)
0
I'm working on a tokenizer and I'm thinking about returning a
MALFORMED_NUMBER token (1.2E, .5E+)
Tokenizer accepts "0x" as zero. Spec says its an error not to have at
least one hex digit after "0x".
This is a more serious bug than I had originally thought. Consider
this:
Joe types "security_code = 0x" and then goes off to the Guardian-of-
the-Codes to get the appropriate hex string. Returning to computer,
Joe's boss grabs him. Tells him that effective immediately he's on the
"rescue us from this crisis" team; his other project can wait.
Some hours, days or weeks later Joe returns to the first project. At
this point Joe has a line of code that says "security_code = 0x". I
think Joe would be well-served by a compiler error on that line. As is
now, Joe's program assigns 0 to security_code and compiles without
complaint. I'm pretty sure any line of the form "name = 0x" was a
product of some form of programmer interruptus.
On Dec 22, 5:03 pm, MartinRineh...@gmail.com wrote:
Tokenizer accepts "0x" as zero. Spec says its an error not to have at
least one hex digit after "0x".
This is a more serious bug than I had originally thought. Consider
this:
Joe types "security_code = 0x" and then goes off to the Guardian-of-
the-Codes to get the appropriate hex string. Returning to computer,
Joe's boss grabs him. Tells him that effective immediately he's on the
"rescue us from this crisis" team; his other project can wait.
Some hours, days or weeks later Joe returns to the first project. At
this point Joe has a line of code that says "security_code = 0x". I
think Joe would be well-served by a compiler error on that line. As is
now, Joe's program assigns 0 to security_code and compiles without
complaint. I'm pretty sure any line of the form "name = 0x" was a
product of some form of programmer interruptus.
:-) Are you a fiction writer by any chance ? Nice story but I somehow
doubt that the number of lines of the form "name = 0x" ever written in
Python is greater than a single digit (with zero the most likely one).
George This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: CoolPint |
last post by:
Can anyone clearly explain the difference between constant reference to
pointers and reference to constant pointers?
What is const int * & ?
Is it a constant reference to a pointer to an...
|
by: akickdoe22 |
last post by:
Please help me finish this program. i have completed the addition and
the subtraction parts, but i am stuck on the multiplication and
division. any suggestions, hints, code, anyhting. it's not a...
|
by: Kemal Ozan |
last post by:
Hi,
I am studying K&R book. On the multidimensional Arrays chapter they
say
"int (*daytab)
is a pointer to an array of 13 integers. The parenthesis are necessary
since brackets have higher...
|
by: Andrej Prsa |
last post by:
Hello, everyone!
When a const int * argument is passed to a function, i.e.
int f (const int *var)
{
printf ("%d\n", *var);
}
int main ()
|
by: Jeff K |
last post by:
Can you pass an int array by reference to a function and modify
selective elements?
Here is my code:
#include <stdio.h>
#define COLUMNSIZE 30
#define ASIZE 5...
|
by: Felix |
last post by:
I am a bit confused as to why conversion from float/double to int is
handled in c# in the way that it is. It differs from my implementation
of C and C++ in a suprising way (to me).
Here is a...
|
by: chrisstankevitz |
last post by:
This code does not compile on gcc 3.4.4. Should it?
Thanks for your help,
Chris
//================
#include <set>
int main()
|
by: yang__lee |
last post by:
Hi,
You all know typedef
typedef struct g
{
int a;
int b;
} google;
|
by: Julia |
last post by:
Hi, there,
In C programming, for pointer, I saw two programming styles:
one is connecting '*' with variable, like, 'int *i';
the other is connecting '*' with data type, like, 'int* i'
I...
|
by: beagle197 |
last post by:
Folks,
Attempting to q-sort an array of int pairs, e.g. {{0,1}, {0, 0}, ...}
allocated using malloc/calloc, but the arguments I'm passing to qsort
are producing the incorrect results (see...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |