Fortob

Fortob is the second language of the For series, first being Forobj. It shares many aspects of it's predecessor, the main difference is it's lexical structure, as it is based on tokens and not characters. The name is play of "forobj" and "token".

Readcom
The language is based on a thing called readcom. Readcom is a processor that reads tokens from the input stream and interprets them. Unlike in Forobj Interpreter, readcom can be called from the program itself, making recursice command parsing possible.

For example, the  command calls readcom to parse the right operand. As readcom parses imperative code, the operand may be empty, in which case the value will be taked from the stack.

Operators
All operators are infix. There is no operator precedence. All operators are right-associative.

Hello world
"Hello world!".println;

Print numbers from 0 to 9
$i = '0\; [$i < '1 0].while: [ $i = $i + '1\\; $i p; ]\;

Print statement
@print[$!.readcom.println;$\.push:'\;]\; print "Hello world!"\;

Custom variable manipulation command
@£[    $name=$!.nextString\; $!.seekString="="\.if: [ $!.accept:"="\; $\.put:$name,$val=$!.readcom\\; $\.push:$val\;' ], [        $\.push:$\.get:$name\\;' ]\; ]\;

Example usage:

£var='4\; ""+£var\.println;

Infix expression parser
Supports precedence and parentheses.

@expr[ $expr=[ $!=\;       %a=$!$term.apply:\\; [$!.seekString="+"\.if:['='],[$!.seekString="-"\.if:['=']]].while: [ $a=$!.nextString="+"\.if:[ $a+$!$term.apply: ], [               $a-$!$term.apply: ]\\;       ]\;        $a ]\;   $term=[ $!=\;       %b=$!$prim.apply:\\; [$!.seekString="*"\.if:['='],[$!.seekString="/"\.if:['=']]].while: [ $b=$!.nextString="*"\.if:[ $b*$!$prim.apply: ], [               $b/$!$prim.apply: ]\\;       ]\;        $b ]\;   $prim=[ $!=\;       $!.seekString="("\.if: [            $!.accept:"("\; $expr.apply:$!\ $!.accept:")"\;       ], [            $!.nextNumber        ]    ]\;    $\.push:$expr.apply:$!\\; ]\;

Example usage:

""+expr 2*(3+4)\.println;

99 bottles of beer
$f=[ %i=\; ['=$i].if: [ "No more bottles of beer on the wall".println; "no more bottles of beer".println; "take one down, pass it around".println; "99 bottles of beer".println;' ], [       ""+$i\+_\+"bottle"\+['1=$i].if:[""],["s"]\\+_\+"of beer on the wall"\.println; ""+$i\+_\+"bottle"\+['1=$i].if:[""],["s"]\\+_\+" of beer"\.println; "take one down, pass it around".println; ""+$i-'1\\+_\+"bottle"\+['1=$i-'1].if:[""],["s"]\\+_\+" of beer"\.println; "".println; $f.proceed:$i-'1\\;' ]\;' ]\; $f.proceed:'9 9\;

External resources

 * The reference implementation in Java 8