Guido Krüger's Web Service

LScript Short Reference


Lexical tokens

The scanner recognizes the following symbols:

Token Regular expression
whole number [0-9]+
floating point as defined in java.lang.Double
string ".*" (must not contain " itself)
lparen (
rparen )
quote ['~]
comment ;.*[$;]
whitespace [\t\r\n ]
delimiter [()\t\r\n ] (note: not ['";])

To simplify inclusion of LScript code into the arguments of an APPLET tag, the following additions to usual LISP syntax have been made:

Terms

There are four kinds of terms the expression evaluator understands:

Term Example Evaluation
number 12 or 3.14 Evaluates to itself
string "hello" Evaluates to itself
symbol add1 The value of the variable of this name
list (add1 5) A call to function with the name of the first element in the list. The other list elements are passed as arguments to the function.

The interpreter simply works by fetching and evaluating the next term from the input until EOF is reached or an error occured. If a function argument is quoted, it is not evaluated before being passed to the function. Some functions don't require quoting for certain arguments which are used unchanged (i.e. setq). Any term is allowed for predicate functions. As usual, the empty list is considered false, all other values true. The return value of boolean function is either the empty list (false) or the symbol T (true). Literals are NIL and T, respectively.

Argument notation

CharacterMeaning
N Number
S String
Y Symbol
L List
? Any
* Zero or more of the preceeding

The CorePlugin

func nameargumentsPurpose
eval ?evaluates the argument
identity ?returns the argument unchanged
progn ?*block of statements
cond (P ?)*conditional statement
while Pwhile loop
print ?*Console output
println ?*Console output with newline
quit  Terminates program
break  Terminates enclosing loop

The NumberPlugin

func nameargumentsPurpose
+ N*Addition
- N*Subtraction
* N*Multiplication
/ N*Division
% N*Remainder
add1 NAdd 1
sub1 NSubtract 1
abs NAbsolute value
sqrt NSquare root
int NWhole number part
frac NFractional part
pow NNPower
inv NInverse value
round NRounded to the nearest integer
sin NSin
cos NCos
tan NTan
asin NArcSin
acos NArcCos
atan NArcTan
randomN or NNRandom number
log NLogarithm to base e
exp NExponential function to base e
max N*Maximum element
min N*Minimum element
variablePurpose
PIpi
Ee (base of natural log)

The StringPlugin

func nameargumentsPurpose
left SNleft substring
right SNright substring
substr SNNmid substring
len Slength
concat S*Concatentation
indexof SSIndex of first occurrence of substring
tostring?String representation of term

The PredicatePlugin

func nameargumentsPurpose
< NN or SSless than
<= NN or SSless than or equal
> NN or SSgreater than
>= NN or SSgreater than or equal
= NN or SSequal to
!= NN or SSnot equal to
not ?true if term is empty list, false otherwise
and ?*true if all arguments are true
or ?*true if any argument is true

The GraphicPlugin

func nameargumentsPurpose
setcolor NNNforeground color (RGB value)
setbackgroundNNNbackground color (RGB value)
drawline NNNNdraw line from x1,y1 to x2,y2
drawstring SNNdraw string at x,y
drawrect NNNNdraw rect at x,y of size w,h
fillrect NNNNfilled rect
drawoval NNNNdraw oval at x,y of size w,h
filloval NNNNfilled oval
drawarc NNNNNNlike oval, plus start and size angle
fillarc NNNNNNfilled oval
setfont SNNset font family, style and size

© 1995-2004 Guido Krüger - Last updated 31 Dec 2003 - Back to top-level page