The "lse64" command starts LSE64:

[Kitsune:~] jpd% lse64

$Id: boot.lse,v 1.13 2004/12/23 21:11:52 jpd Exp $
LSE>


At the prompt, you may type commands or definitions:

LSE> 6 7 * ,
42
LSE>

This means "push 6 on the stack, push 7 on the stack, multiply, print the result".

Programs in LSE64 are sequences of "words" separated by white space. A word may be any sequence of characters not containing white space:

this-is-one-word
this is four words
*word>

彡字辞

The last two lines each represent one word. As the last line shows (at least if you're viewing this through properly configured software), you may use a very wide range of characters. The only requirement is that your character coding must have ASCII as a subset (most common codes have this property).

The default prompt displays the stack contents. Here's the previous example as a series of separate commands, with stack state displayed at each step:

LSE> 6

6 LSE> 7

6 7 LSE> *

42 LSE> ,
42
LSE>


The common integer arithmetic operators are present:

LSE> 5 4 3 2 1 + / - * ,
15
LSE>


(this is a good example to try line by line if you're puzzled).

LSE64 also supports floating point numbers. Unlike many other programming languages, operators are not overloaded. To do floating point arithmetic, you must use floating point operators:

LSE> 1. 2. 3. 4. 5. +. /. -. *. ,.
1.66667
LSE>

You may define your own words using special "defining words". The definining word :variable defines a variable. The word representing a variable yields the address of the variable when executed. The word ! stores a value at that address, while @ fetches the value:

LSE> x :variable

LSE> 42 x !

LSE> x

33607032 LSE> @
,
42
LSE>


The number "33607032" that x pushed on the stack is the address of the cell that LSE64 allocated for its data. When you run this example you'll probably get a different address here.

If you wish to define several variables at once, variables: is a useful alternative:

LSE> variables: x y z

LSE>


The word :constant defines a constant, getting its value from the stack:

LSE> 20 3 * three-score :constant

LSE> three-score ,
60
LSE>

You can define more complex words in terms of simpler words. Here, I define a new word 2* that will multiply the top cell on the stack by 2:

LSE> 2* : 2 *

LSE> 33 2* ,
66
LSE>


The word iterate executes the preceeding word multiple times. The top stack element is the number of iterations. The following starts with one, doubles it sixteen times, and prints the result:

LSE> 1 16 2* iterate ,
65536
LSE>

The word swap exchanges the two top stack items:

LSE> 1 2 swap

2 1 LSE>


The following raises 2 to a power by multiplying 1 by 2 iteratively. I need to provide the 1, but I then need the power to be at the stack top for iterate, so I push 1 and then swap:

LSE> 2^n : 1 swap 2* iterate

LSE> 12 2^n ,
4096
LSE>

The word " begins a text string, which continues up to the next " in the input. You must follow the first " by white space: if you forget, the parser won't recognize it as a word. ,t prints a text string.

LSE>
" Don't panic!" ,t
Don't panic!
LSE>

To make an unbounded loop, use repeat. It jumps back to the start of a word. This example also shows off usec, which suspends execution for a given number of microseconds, and nl, which prints a newline. Control-c stops execution, and gets you back to the command prompt:

LSE> " Tick" ,t nl 1000000 usec repeat
Tick
Tick
Tick
Tick
Tick
Tick
Tick
Tick
^C
LSE>

That's all for now: go look at the reference manual for all of the words I didn't mention here. Give them a try.