May literal parsing faults occur in some situations with SLEEP?

3 views
Skip to first unread message

Giorgio

unread,
Nov 25, 2008, 6:31:55 AM11/25/08
to Sleep Developers
Hallo Sleep Developers group,

Can anybody here explains what exactly is happening when SLEEP execute
the following lines?

## simple but faulty literal parsing (??) test
$arr = @();
# this one is an assignment that works
$newsize = (size($arr) - 1);
# this other one raises "Warning: assignment is corrupted, did you
forget a semicolon?"
$newsize = (size($arr) -1);

Best regards, Giorgio.

Raphael Mudge

unread,
Nov 25, 2008, 9:19:27 AM11/25/08
to sleep-de...@googlegroups.com
Hi Giorgio,
I took a look at this.  An interesting command line option in Sleep is -a which dumps the abstract syntax tree for the script.  Its funny I didn't see it on first glance.  The difference is "- 1" vs. "-1".  Sleep requires whitespace between all operations.  Obviously -1 is supported as a literal but its not considered an operation.   The Sleep parser doesn't consider -1 an operation and hence (size($arr) -1) is seen as two literals rather than a binary op.

Why the whitespace requirement?  This one is taken from the manual: Sleep is an extensible language. Sleep extensions (bridges) provide all the operations such as addition and subtraction. The Sleep parser does not know about these operators when it is parsing your script. The only way it knows an operator is an operator is by the context.

I did add support for the concat operator . without the whitespace requirement but this was kind of a dangerous hack (one whose issues were fleshed out long ago).

-- Raphael


[raffi@beardsley ~/sleepdev/sleep]$ java -jar sleep.jar litfault.sl 
Warning: assignment is corrupted, did you forget a semicolon? at litfault.sl:6

[raffi@beardsley ~/sleepdev/sleep]$ java -jar sleep.jar -a litfault.sl 
[Create Frame]
[Create Frame]
[Function Call]: &@
[Assign]:
   [Get Item]: $arr
[Create Frame]
[Create Frame]
[Scalar]: 1
[Create Frame]
[Get Item]: $arr
[Function Call]: &size
[Operator]: -
[Assign]:
   [Get Item]: $newsize
[Create Frame]
[Create Frame]
[Get Item]: $arr
[Function Call]: &size
[Scalar]: -1
[Assign]:
   [Get Item]: $newsize

Giorgio

unread,
Nov 25, 2008, 9:34:08 AM11/25/08
to Sleep Developers
Thank you very much Raphael!

This a great explanation from you (the author of SLEEP language).
Thank to be coerent with SLEEP manual citation, I belive you can close
the BUG# 1227538208136 opened on sleep.dashnine.org by me.

I'm continuing to experiment and play with ideas that exploit SL
functionalities and I'm well impressed about what you can do mixing
scripting and higher level Java programming knowledge.

I'll keep in account "-a" command line option and I'll use it more
oftenly from now on..

Best regards, Giorgio.
Reply all
Reply to author
Forward
0 new messages