Page 1 of 2

Strange...

Posted: Wed Nov 09, 2005 2:23 pm
by Polo
Don't know if it's supposed to be normal or not, but this code :

Code: Select all

3thing=0
Gives "Not a valid decimal number" :shock: Everytime I use a variable name starting with a number it says that ! How come I can't do that ??

Posted: Wed Nov 09, 2005 2:36 pm
by benny
@Polo:

I guess it's just the definition of the purebasic parser. In the help it says that
variables shouldn't start with a number.

So, when the parser parses a new word which starts with a numeric value it
assumes that it is a decimal number and not a variable.

That's all ...

Posted: Wed Nov 09, 2005 2:37 pm
by Chris
A variable can't begin by a number.

Posted: Wed Nov 09, 2005 3:11 pm
by Polo
All right, I still find this weird, anyway...

Posted: Wed Nov 09, 2005 4:05 pm
by Trond
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?

Posted: Wed Nov 09, 2005 4:27 pm
by Polo
Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
But then, if the compiler could catch the error, it could also make the variable working, so that's why I posted it here, I think it's possible :)

Posted: Wed Nov 09, 2005 5:23 pm
by Trond
Polo wrote:
Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
But then, if the compiler could catch the error, it could also make the variable working, so that's why I posted it here, I think it's possible :)
Whether variables can start with a number or not is not a question of possible/not possible, it's a question of language design.

Posted: Wed Nov 09, 2005 7:48 pm
by Pupil
Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
The error is correct as it is, because "3thing" is not a valid decimal number, or do you dissagree? ;)

Posted: Wed Nov 09, 2005 8:41 pm
by Trond
Pupil wrote:
Trond wrote:
Chris wrote:A variable can't begin by a number.
So then it should give the error "not a valid variable" and not "not a valid decimal number", shouldn't it?
The error is correct as it is, because "3thing" is not a valid decimal number, or do you dissagree? ;)
The error message doesn't say _what_ isn't a valid decimal number.

Posted: Wed Nov 09, 2005 8:52 pm
by Polo
3thing=128
128 is a "valid decimal number"
so "3thing" is the "not valid decimal number", but here it's a variable, so something's wrong somewhere.

Posted: Wed Nov 09, 2005 8:59 pm
by Pupil
Trond wrote:The error message doesn't say _what_ isn't a valid decimal number.
Well, it's fairly obvious, isn't it? :)

However i agree that it would help if the compiler was a tad more explicit. An error message like the one below would've been more helpfull in pinpointing the problem:
"'3thing' is not a vaild decimal number."

Posted: Wed Nov 09, 2005 9:01 pm
by Trond
Pupil wrote:
Trond wrote:The error message doesn't say _what_ isn't a valid decimal number.
Well, it's fairly obvious, isn't it? :)
Try to type in 3thing on a line by itself. :wink: Also, "=" isn't a valid decimal number.

The thing is: It reports that it got something which wasn't a valid decimal number at a place where it shouldn't expect a valid decimal number.

Posted: Wed Nov 09, 2005 9:15 pm
by Pupil
Polo wrote:
3thing=128
128 is a "valid decimal number"
so "3thing" is the "not valid decimal number", but here it's a variable, so something's wrong somewhere.
Well it isn't a variable, is it! Why, because it doesn't follow PB's naming convention for variables.

Everything that starts with a number is considered to be a decimal of some sort by the compiler. if a non-numerical character(except operators and whitespace) is encountered in a character stream that starts with a numerical it's considered a non-valid number. That you perceive things differently can't be blamed on the compiler (Fred hasn't implemented the mind-reading code into the compiler yet). ;)

Posted: Wed Nov 09, 2005 9:26 pm
by Pupil
Trond wrote:Try to type in 3thing on a line by itself. :wink: Also, "=" isn't a valid decimal number.
Already tried that, your point being?

Yes '=' isn't a valid decimal number, however it's a valid operator, but hopefully you already knew that.. ;)
The thing is: It reports that it got something which wasn't a valid decimal number at a place where it shouldn't expect a valid decimal number.
Exactly why shouldn't it expect a decimal number here?

Posted: Wed Nov 09, 2005 9:37 pm
by Polo
well, sorry, but "3thing" should be reported as a wrong variable name, then :)
I just think it's not supported because Fred hasn't made the parser accept it, I think in other language using "3thing" is possible, come on, Fred, it's not that this is a really big feature we want, but it would make the language better ;)