Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Oct 28, 2007 2:26 am   

[2.09] Expression reserved word problem
 
I know yes, no, on, off, true, and false are considered reserved words for expression. I am having a problem with a particular expression that is part of a script. The portion of the script that I traced it to is "#IF (@DirQueue) {". Probably this is the only script that will have this problem, but some how "n" became a reserved word for false

#IF ("n") {#SHOW Yes} {#SHOW No}
Now displays No. It should be displaying yes.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Oct 28, 2007 6:23 am   
 
I did some further testing with this, and it looks like on and off got remove from the reserved which is good.

The bad news is that is that f works as short for false. Also the reserved words work in a few variations where we wouldn't want them to.
#IF (%concat("n","o")) {#SHOW Yes} {#SHOW No}
#IF ("f") {#SHOW Yes} {#SHOW No}
#IF ("no") {#SHOW Yes} {#SHOW No}
#IF (%char(70)) {#SHOW Yes} {#SHOW No}

So a simple fix really won't work here, those words shouldn't even work when in quotes, contained by a variable, or assembled through insane manipulations. This is a parsing problem that might have to be put off, but it would be good to fix the single letters so they are right for now.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sun Oct 28, 2007 6:57 am   
 
Confirmed. Vijilante I've got to admire your bug hunting skills. I know you know the product almost as well as Zugg but half of these issues I couldn't even imagine until you do them.
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Oct 29, 2007 10:10 pm   
 
Excellent testing!

Should Yes/No even be allowed as reserved words anymore?

The bug applies to True/False also, however, and I agree that this needs to be fixed.
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Mon Oct 29, 2007 11:04 pm   
 
It occurs to me that this is more an order-of-operations bug than a problem with the list of reserved words. In other words, the bug is that the check for reserved words is happening AFTER the evaluation of the condition in the %if statement, and it should only happen BEFORE the evaluation of the condition (during parsing, for instance). If that were the case, all the concats and other manipulations wouldn't cause any problems (even if you assembled the word "false"), because the check for reserved words wouldn't get called at that point.

Or is there some reason I'm missing for the re-parsing step?

That said, I agree that 'n' and 'f', etc. should NOT be reserved words. And I wouldn't mind seeing 'yes' and 'no' go either. If you want the syntactic candy, throw in built-in %yes and %no, or whatever.
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Tue Oct 30, 2007 1:09 am   
 
I won't miss 'yes' and 'no'. If True and False are too long to type, one can just use 1 and 0. I would not have expected any abbreviations for them to be possible.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Oct 30, 2007 1:44 am   
 
No, actually the problem *is* happening in the parser. When checking for True/False it is actually allowing the values within a string instead of just within an expression. This is somewhat left over from zMUD since zMUD didn't have any distinction between a string with or without the quotes. It's just one of those "weirdnesses" left over from zMUD that didn't get fixed.
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Tue Oct 30, 2007 4:10 am   
 
For once I think this should be like other compilers. True/False should be reserved, and of course any non-zero value should return a TRUE.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Oct 30, 2007 5:15 am   
 
I agree only TRUE and FALSE should be reserved. I could even live without them, in fact I can't recall ever using them. I also can't recall anyone ever mentioning them unless it was a Guru explaining why a script wasn't working.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
mr_kent
Enchanter


Joined: 10 Oct 2000
Posts: 698

PostPosted: Tue Oct 30, 2007 6:18 am   
 
Heh! I use TRUE and False in some of my zMud scripts but it's easy enough to get around their use. Stay or go - makes no difference. From a practical standpoint, I just want my scripts to work and my triggers to match. The reserved word stuff is mostly just extra fluff and another chance for introducing errors IMHO.
Reply with quote
Tarn
GURU


Joined: 10 Oct 2000
Posts: 873
Location: USA

PostPosted: Tue Oct 30, 2007 7:00 pm   
 
Vijilante wrote:
I agree only TRUE and FALSE should be reserved. I could even live without them, in fact I can't recall ever using them. I also can't recall anyone ever mentioning them unless it was a Guru explaining why a script wasn't working.


The only way I recall using them directly as final values is to "comment" things out: #IF (false) { ... }
and then they would by preference not be strings (eg, the reserved word False, not a string which happens to contain "False").

I can't think of a good use for automatic type coercion of strings to booleans: it's always better to have an explicit check for "", or "False" or whatever you really mean.

In a scripting language which lets a program add or modify its own code, though, I'd have to think about the syntax consequences for creating new code based on string input- I haven't been following the evolving syntax discussion here quite so closely as I should.

-Tarn
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Tue Oct 30, 2007 8:35 pm   
 
Being reserved doesn't just imply it is used like a command, especially when you are considering true and false. They are reserved due to their use in boolean variables. Using zero and non-zero for true and false, as far as I know, doesn't change the interpretation as FALSE/TRUE.
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Tue Oct 30, 2007 11:18 pm   
 
Zugg wrote:
No, actually the problem *is* happening in the parser. When checking for True/False it is actually allowing the values within a string instead of just within an expression. This is somewhat left over from zMUD since zMUD didn't have any distinction between a string with or without the quotes. It's just one of those "weirdnesses" left over from zMUD that didn't get fixed.


So you're saying that the parser does NOT called again after the expression is evaluated? If that's the case, then I fail to see how the %concat("n","o") example or the %char(70) example could cause this problem (in the parser), since the reserved word doesn't appear until after evaluation. SOMETHING is replacing the string literal with the boolean value, and that something is getting called after (or during) evaluation of the expression (and probably shouldn't be - the parsing step should be over by then).

However, I agree that the parser should prevent quoted words from being checked against the reserved-word list, especially now that the language IS making a distinction between quoted and unquoted strings.

Tarn wrote:
I can't think of a good use for automatic type coercion of strings to booleans: it's always better to have an explicit check for "", or "False" or whatever you really mean.


Recall that CMUD actually allows you to specify whether type-binding of variables is early or late (using %vartype). The late-binding of the default "Autotype" mimics loose typing in a variety of string-processing languages, where strings can be coerced to integers or booleans depending on context.

So, for a variable of type "Autotype", it makes some sense to do automatic type conversion to boolean, integer, or whatever type the context demands. And I'd hazard a guess that function return values (say, from %concat) and literal values (e.g. "no") are treated as type "Autotype" under the hood.

In other words, the problem isn't that CMUD is converting strings to booleans - lots of languages do that - its that it converts them using the wrong rules: a non-empty string should always evaluate to a 'true' boolean, even if the string in question is the word "no".
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Oct 31, 2007 7:45 pm   
 
Yeah, this bug was nasty. In CMUD, results are returned as special class objects that can contain different value types (sort of like Variants). This is my own class that I have been using for a long time. One of the class properties is "AsBoolean" which returns the result as a true/false value. Obviously if there is a number stored, then it returns false if zero, and true if non-zero. But when there is a string value stored, I discovered that it is actually checking for "false", "f", "no", "n", "true", "t", "yes", "y" strings and handling them specially.

So, it wasn't a parser issue after all. jquilici was correct that it was happening post-parser by the routine that was checking the result.

Dealing with 0/1 is also a bit tricky when dealing with AutoType values. I've modified it so that putting a 0 or 1 within a literal string like "0" and "1" will always be true (non-null strings). Otherwise, if it's not a literal string, but the result of a function expansion, like %concat("0"), then it will actually return false in that special case. This is because the result of a function is AutoTyped, so the "0" string value gets converted to a 0 numeric value, which returns false. Hope that makes sense.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net