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:
- The quote sign may be either ' or ~
- Comments are started with ; and terminated at the end of the line
or after the next ; (whatever occurs first).
- Note that there are very few delimiters in the language. This allows
for characters like '+' or '-' in function names but sometimes
requries additional whitespace for delimiting.
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
| Character | Meaning
|
|---|
| N | Number
|
| S | String
|
| Y | Symbol
|
| L | List
|
| ? | Any
|
| * | Zero or more of the preceeding
|
The CorePlugin
| func name | arguments | Purpose
|
|---|
| eval | ? | evaluates the argument
|
| identity | ? | returns the argument unchanged
|
| progn | ?* | block of statements
|
| cond | (P ?)* | conditional statement
|
| while | P | while loop
|
| print | ?* | Console output
|
| println | ?* | Console output with newline
|
| quit | | Terminates program
|
| break | | Terminates enclosing loop
|
The NumberPlugin
| func name | arguments | Purpose
|
|---|
| + | N* | Addition
|
| - | N* | Subtraction
|
| * | N* | Multiplication
|
| / | N* | Division
|
| % | N* | Remainder
|
| add1 | N | Add 1
|
| sub1 | N | Subtract 1
|
| abs | N | Absolute value
|
| sqrt | N | Square root
|
| int | N | Whole number part
|
| frac | N | Fractional part
|
| pow | NN | Power
|
| inv | N | Inverse value
|
| round | N | Rounded to the nearest integer
|
| sin | N | Sin
|
| cos | N | Cos
|
| tan | N | Tan
|
| asin | N | ArcSin
|
| acos | N | ArcCos
|
| atan | N | ArcTan
|
| random | N or NN | Random number
|
| log | N | Logarithm to base e
|
| exp | N | Exponential function to base e
|
| max | N* | Maximum element
|
| min | N* | Minimum element
|
| variable | Purpose
|
|---|
| PI | pi
|
| E | e (base of natural log)
|
The StringPlugin
| func name | arguments | Purpose
|
|---|
| left | SN | left substring
|
| right | SN | right substring
|
| substr | SNN | mid substring
|
| len | S | length
|
| concat | S* | Concatentation
|
| indexof | SS | Index of first occurrence of substring
|
| tostring | ? | String representation of term
|
The PredicatePlugin
| func name | arguments | Purpose
|
|---|
| < | NN or SS | less than
|
| <= | NN or SS | less than or equal
|
| > | NN or SS | greater than
|
| >= | NN or SS | greater than or equal
|
| = | NN or SS | equal to
|
| != | NN or SS | not 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 name | arguments | Purpose
|
|---|
| setcolor | NNN | foreground color (RGB value)
|
| setbackground | NNN | background color (RGB value)
|
| drawline | NNNN | draw line from x1,y1 to x2,y2
|
| drawstring | SNN | draw string at x,y
|
| drawrect | NNNN | draw rect at x,y of size w,h
|
| fillrect | NNNN | filled rect
|
| drawoval | NNNN | draw oval at x,y of size w,h
|
| filloval | NNNN | filled oval
|
| drawarc | NNNNNN | like oval, plus start and size angle
|
| fillarc | NNNNNN | filled oval
|
| setfont | SNN | set font family, style and size
|
© 1995-2004 Guido Krüger - Last updated 31 Dec 2003 -
Back to top-level page