YASL is an acronym for Yet Another Simple Language. It's basically an imperative language with a C-like syntax. It is Turing complete, and will soon have support for lists and functions. It has two different ways of using keywords, which can be intermixed.
The official java-based interpreter for YASL, along with the JavaCC specification and some trivial programs (random hack and 99 bottles of beer) is available in yasl.zip. A quick demo of the 99 bottles of beer program can be seen in 99bottles.yasl. There is also an alternative version of 99bottles2.yasl which shows the alternative syntax of YASL.
The obligatory "Hello, world!" program looks as follows:
print "Hello, world!";A slightly overcomplicated way of writing this 10 times would be:
$msg = "Hello, world!"; $i = 10; while($i != 0;) { print $msg; $i = $i - 1; };
ALL statements and expressions in YASL must end with a semicolon (";"), including conditionals for loops and conditional statements - as well as the conditionals and loops themselves. This is an intended feature, since YASL can be written on a single line if so desired (i.e it ignores whitespace).
YASL is a dynamically typed language, and will automagically translate data types as needed.
YASL supports 6 data types: int, float, string, bool, null and list. The implementation of the list data type is as of yet unfinished (one can create lists and put items in the, but not access the items inside the list).
The following table illustrates the relationship between data types. Please note that "?" is shorthand for "any". Operations which can not be legally performed (i.e return an error if attempted) are not included in this list).
Type 1 | Op | Type 2 | Result type |
---|---|---|---|
int | + | int | int |
int | - | int | int |
int | / | int | int |
int | * | int | float |
int | ? | float | float |
float | ? | float | float |
string | + | ? | string |
string | - | ? | string |
$s1 = "hello"; $s2 = "l"; print $s1-$s2;...will result in:
heo
YASL is dynamically typed, and therefor does not need data type identifiers for it's variables. All variables have to be prefixed with a dollar sign ($). This is to separate them from reservred words. Variables might be declared as such:
$i = 5;
You will probably have deduced some of these already, but here's a list:
Keyword | Usage | Result |
---|---|---|
print Exp(); | Prints Exp() to StdOut, followed by a newline | |
read | read $var | Reads a value from StdIn into the variable $var |
if | if (Exp();) { (Exp();)* }; | Perform the Exp()s within the curly brackets if the Exp() within the paranthesis evaluates to a boolean value of true. |
while | while (Exp();) { (Exp();)* }; | Performs the list of Exp()s within the curly brackets while the Exp() within the paranthesis is true. The value check is performed at the end of each loop. |
YASL has a flexible syntax, and can written in different ways. For example, both these programs are valid YASL programs - and do the same thing:
$a = "abc"; $i = 10; while ($i != 0;) { print $a; $i = $i - 1; };...and...
$a is "abc"; $i is 10; while ($i neq 0;) begin print $a; $i is $i - 1; end;To further clarify this, the following statements are equal:
= is == eq equal != neq notequal { begin } end + plus - minus * times / divideby