Forobj

Forobj is an object oriented programming language created by User:Fergusq. It is designed to be easily extendable and almost impossible to parse without interpreting.

Overview
Forobj is a stack-based language. A program is a list of commands and values. Values are pushed to the stack as commands are executed. Techically, values are commands.

"This is a string value and is pushed to the stack." d "'d' is a command which pops and prints a string." d

The interpreter parses and executes at the same time. Command syntaxes can be edited runtime. Control flow is done by editing input queue.

Forobj is statically typed, which means that a variable can have only one type. Whitespace is not allowed between command arguments.

Input queue
Forobj code is translated into an input queue at the begin of interpretation. The input queue contains characters. The interpreter reads those characters and creates tokens from them following command syntax. A string, for example, is a token.

When a function is called, interpreter creates a new input queue from function's code and executes it.

Editing input queue
There are two commands used to modify the input queue. \ appends code to it, and ; removes it.

A loop can be done using these commands.

[, code condition;\],._%

First, a function (a string) is pushed to the stack and duplicated. Then it is called and intepreteted in the same stack (_). In the function, the function itself is first duplicated (,). At the end of the function, an input queue is conditionally cleared if a condition is true (clearing input queue exits from the function). If condition is false, the code of the function is appended to the input queue (\).

Control Flow
Basic if: [ 	then ][ 	else ]condition?

While loop, code must not leave elements to the stack. [, 	code condition;\],._%

Functions
Defining a function: [>argI >argII >argIII code ]>name

For example: [>name "Hello, "d $name d "!\n"d ]>sayHello

Calling a function: $name.argument_count

Example: "John" $sayHello.1

Classes and objects
Creating a class: ~car<$speed> [>self "Driving... Speed: "d $self:$speed d "\n"d ] ~car

Fields do not need to be declared, but they should, as if not, they are initiated with an undefined value and throw an error if are being accessed.

Using class: ^car >mycar $mycar:drive

Fields can be used to create a hash map:

[ ""@+ ]#s_ [>self>value>name $value\ [$self:>a]\ $name s\] ~map [>self>name [$self:$a]\ $name s\] ~map ^map >m "value" "key" $m:set "key" $m:get d

Commands
Characters c (character), i</tt> (identifier) and n</tt> (number) represent command arguments. Commands can have many syntaxes.

Variables
Variables are similar to fields. Variables belong to a stack. If a new stack is created (when function is called), it contains it's own variable scope.

Input Queue
Every string has it's own input queue. When the program starts, the whole program loaded into an input queue. When a string is executed as a function, it is loaded into a new input queue.

Hello world
"Hello World\n"d

Fibonacci sequence
["\n"d]#l_ '0 >a '1 >b '0 >c '10 >i [, 	$a $b +	>c $b >a $c >b '11$i-d	":"d $a dl 	$i '1 - >i $i!; \ ],._%

Short version:

',>a>c'1>b'10>i[,$b,$a+,>c$b>a>b$a d"\n"d$i'1-,>i!; \],._%

Truth-machine
n>n["0"d][[,"1"d\],[]$n"1"=?]$n"0"=?

Command example
["\n"d]#l_ [ 	&lt;n>id &lt;s &lt;a- &lt;s &lt;i>name "&lt;b>§"d $id d "</b> - &lt;i>"d $name d "&lt;/i>"dl ]#§0 §1 - Introduction §2 - Body §3 - FinalWords

Outputs: &lt;b>§1</b> - &lt;i>Introduction</i> &lt;b>§2</b> - &lt;i>Body</i> &lt;b>§3</b> - &lt;i>FinalWords</i>

Deadfish interpreter
">> "d'>i[,n>c[$i'1+>i][[$i'1->i][[$i,*>i][[$i d"\n"d][">> "d]$c"o"=?]$c"s"=?]$c"d"=?]$c"i"=?['>i][]$i'256=$i'=|?\],._

Brainfuck interpreter
Brainfuck program is appended to the end of the interpreter. Output command is p</tt>, input is not supported. Loop is %bf[ code ]o</tt>.

["\n"d]#l_ " type conversion commands "% [ ""@+ ]#s_ [ "'"\\ ]#i_ "Class tape"% [@>self@>value@>name $value\ [$self:>a]\ $name s\] ~tape<set:2> [@>self@>name [$self:$a]\ $name s\] ~tape<get:1> "Class bf"% ~bf<$i> ~bf<$tape> ^bf >bf ^tape, $bf:>tape >tape " tape initialization "% '1000 $bf:>i [, 	'0 $bf:$i $tape:set $bf:$i '1 -$bf:>i $bf:$i!; \],._% '1 $bf:>i [$bf:$i $bf:$tape:get '1 @+ $bf:$i $bf:$tape:set]#+_ [$bf:$i $bf:$tape:get '1 @- $bf:$i $bf:$tape:set]#-_ [$bf:$i '1 @- $bf:>i ]#<_ [$bf:$i '1 @+ $bf:>i ]#>_ [@>bf @>loop [, $bf:$i $bf:$tape:get !; $loop._ \],._% ]#o2 [$bf:$i $bf:$tape:get dl]#p_ " bf hello world "% ++++++++$bf[>++++$bf[>++>+++>+++>+<<<<-]o>+>+>->>+$bf[<]o<-]o>>p>---p+++++++pp+++p>>p<-p<p+++p--pp>>+p>++p