slang-users mailing list

[2014 Date Index] [2014 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] parser confuses floating point literals and RPN_TOKENs

Hi John & S-Lang users,

I've noticed that it should probably be forbidden to omit the leading 0
in floating point literals when placed in the beginning of a code line,
such as:
> variable a=
> .5;

It seems that the current (v2.3.0) S-Lang parser considers this '.' as
an RPN_TOKEN -- which leads, in some cases such as in the example above,
to a SyntaxError, or in others to the '.' effectively being ignored:
> eval(".5"); variable a=(); print(a);

With a leading blank (or a leading 0, of course), my floating point
values are recognized correctly from within an S-Lang script.

On the interactive slsh, however, there are slightly other effects due
to `slsh_interactive_massage_hook', which firstly `strtrim's whitespace
and prefixes a space in certain cases, causing the following to work as
naïvely expected:

slsh> .5;
slsh> .5*2;

But it currently doesn't recognize the following "correctly":

slsh> 	.5^2;
slsh> 	.5==.5;

Since I know almost nothing about S-Lang's RPN features (maybe because I
started with S-Lang 2.x?), I'm wondering whether RPN is just a left-over
from early versions of S-Lang that might eventually be removed, or
whether it's an essential component of parsed S-Lang tokens.

If RPN is to stay, one might consider improving
slsh_interactive_massage_hook in a way similar to the following patch:

> --- a/slsh/lib/
> +++ b/slsh/lib/
> @@ -240,13 +240,13 @@ public define slsh_interactive_massage_hook (input)
>     else
>       {
>         %  line begins with "."
> -       variable type = _slang_guess_type (strtok (input, "-+*/<>&|; \t")[0]);
> +       variable type = _slang_guess_type (strtok (input, "-+*/^<=>&|; \t")[0]);
>         if (type != String_Type)
>           {
>              % Do not allow the line to be parsed as RPN.  So prefix
>              % with a space.
>              return strcat (" ", maybe_append_semicolon (input));
>           }


For list information, visit <>.

[2014 date index] [2014 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]