Strict Syntax Checking for Scripts
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: Strict Syntax Checking for Scripts
Admittedly, it's not really a syntax error but any chance this feature could detect and warn when the variables within a while's expression are not updated within the while block? 
-
admin
- Site Admin
- Posts: 66324
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Strict Syntax Checking for Scripts
To pamper a coder...TheQwerty wrote:Admittedly, it's not really a syntax error but any chance this feature could detect and warn when the variables within a while's expression are not updated within the while block?
FAQ | XY News RSS | XY X
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: Strict Syntax Checking for Scripts
I'm embarrassed to admit the number of times I've lost code entered into Run Script because I've made this error and had to eventually kill XY.admin wrote:To pamper a coder...TheQwerty wrote:Admittedly, it's not really a syntax error but any chance this feature could detect and warn when the variables within a while's expression are not updated within the while block?... come on...
EDIT: Of course it's happened so much I can't keep count anyhow. /edit.
There's a lot of lessons to learn there, but if experience has taught me anything it's that I'm never going to learn.
-
admin
- Site Admin
- Posts: 66324
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Strict Syntax Checking for Scripts
That's a good one.TheQwerty wrote:... but if experience has taught me anything it's that I'm never going to learn.
FAQ | XY News RSS | XY X
-
Filehero
- Posts: 2731
- Joined: 27 Feb 2012 18:50
- Location: Windows 11@100%
Re: Strict Syntax Checking for Scripts
Oh yes, the camouflage while(true) lock.admin wrote:That's a good one.
-
bdeshi
- Posts: 4256
- Joined: 12 Mar 2014 17:27
- Location: Asteroid B-612
- Contact:
Re: Strict Syntax Checking for Scripts
I've learnt a great trick from [ed.]somebody here Ken , it's a lifesaver! 
Code: Select all
$c = 10; while ($c-- >= 0) {echo $c;}Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
PeterH
- Posts: 2827
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Strict Syntax Checking for Scripts
Hm - what do you want to show with this? I don't understand...SammaySarkar wrote:Oh sure, found 35 cases where eval() usage will cause syntax hiccups.admin wrote:You have a non-weird use of Eval() where any quotes should be added? I doubt it.
Here's one example:most cases have similar eval() usage, used to build and obtain a dynamic variable value.Code: Select all
$varBaseName_1 = 'value1'; $DynamicPart = '1'; eval($varBaseName_$DynamicPart);
btw, about that auto-quoting: if this is introduced, maybe it should be restricted to in places like this where running-as-is will cause fatal abortion.Code: Select all
$d = <xypath>; eval($d);
Both examples are simply illegal syntax!
In first example:
eval($varBaseName_$DynamicPart);
the operand for eval is "a kind of" list of 2 variables, without an operator between them, like . or +, so illegal.
And the first of it's 2 variables even isn't initialized - it's $varBaseName_ so non-resolved by it's value, but just by it's name.
In Don's mod with double quotes it's a string, with variables "simply resolved". Again the 1st is resolved by it's name, the 2nd by it's value, and both concatenated. Happens to look quite nice, but try a modification: add a line
Code: Select all
$varBaseName_1 = 'value1'; $DynamicPart = '1';
$varBaseName_ = 'strange';
Echo eval($varBaseName_$DynamicPart);Echo eval('$varBaseName'."_$DynamicPart");
(I don't see how XY could auto-add these quotes and the dot in a correct way.)
The 2nd example resolves to something like:
$d = c:\prog\xydir;
You know that \ is the operator for integer division? Hm.
Try: Echo 20\3;
Or: Echo "20\3";
Or: Echo Eval("20\3");
-
bdeshi
- Posts: 4256
- Joined: 12 Mar 2014 17:27
- Location: Asteroid B-612
- Contact:
Re: Strict Syntax Checking for Scripts
in 1st example eval is used to get a variable dynamically. Say these are all set: $var_1, $var_2, ...,$var34. & $Dyn = 1; Just by changing $Dyn, eval($var$Dyn) can return any of those vars by a single stmt.
It's not a question of it being a bad syntax, I just saw a lot of examples, and I was getting so many dubious errors.
2nd example: I know it will be bad. But if the string didn't have \,/ etc, it would've returned right. But my example will cause overflow. So I suggested XY might add quotes in these cases.
It's not a question of it being a bad syntax, I just saw a lot of examples, and I was getting so many dubious errors.
2nd example: I know it will be bad. But if the string didn't have \,/ etc, it would've returned right. But my example will cause overflow. So I suggested XY might add quotes in these cases.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
PeterH
- Posts: 2827
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Strict Syntax Checking for Scripts
Did you try to understand what I have written?
You want to refer to a dynamic variable like $name_##.
For the created name of that variable $name_ is *constant*, while ## is *variable*.
If you write eval($varBaseName_$DynamicPart), you want the first part to be a constant string, but $varBaseName_ is a variable! (Note: the trailing _ is part of the name!!!) *If* you have never filled it, *then* it's undefined, and as such *happens to* return it's name as it's "contents". So, for what you want, this part *must* be in single quotes to be meant as constant. (Especially the $, otherwise saying it's a variable!)
The 2nd part is meant to be variable - so it *may not* be in single quotes. There are different versions how to do - the 1st example seems the best to me:
Echo eval('$varBaseName_ ' . $DynamicPart );
Echo eval('$varBaseName_' . "$DynamicPart");
Echo eval('$varBaseName' . "_$DynamicPart");
Echo eval('$' . "varBaseName_$DynamicPart");
So could you tell me, how XY could have guessed that you meant this?
The result: syntax is there to regulate how you tell the XY interpreter what you want it to do.
You want to refer to a dynamic variable like $name_##.
For the created name of that variable $name_ is *constant*, while ## is *variable*.
If you write eval($varBaseName_$DynamicPart), you want the first part to be a constant string, but $varBaseName_ is a variable! (Note: the trailing _ is part of the name!!!) *If* you have never filled it, *then* it's undefined, and as such *happens to* return it's name as it's "contents". So, for what you want, this part *must* be in single quotes to be meant as constant. (Especially the $, otherwise saying it's a variable!)
The 2nd part is meant to be variable - so it *may not* be in single quotes. There are different versions how to do - the 1st example seems the best to me:
Echo eval('$varBaseName_ ' . $DynamicPart );
Echo eval('$varBaseName_' . "$DynamicPart");
Echo eval('$varBaseName' . "_$DynamicPart");
Echo eval('$' . "varBaseName_$DynamicPart");
So could you tell me, how XY could have guessed that you meant this?
The result: syntax is there to regulate how you tell the XY interpreter what you want it to do.
-
bdeshi
- Posts: 4256
- Joined: 12 Mar 2014 17:27
- Location: Asteroid B-612
- Contact:
Re: Strict Syntax Checking for Scripts
I agree with you, but there was a misunderstanding somewhere. But let's just forget the whole matter.
I know it's bad syntax, and I'm not suggesting anyone should be using it.
I know it's bad syntax, and I'm not suggesting anyone should be using it.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
XYplorer Beta Club