to run:
cd lang2
./compile.sh example.txt
Change example.txt
to any file that you want to run from.
Place the file inside the same folder as the index.js
file
The code is compiled into GNU GAS assembly, and is ran standalone on a virtual machine. requires:
- Grub CLI
- Xorriso
- GNU bintutils
- Qemu
See here for quick Ex.
- Variables are defined with labels like so:
name:
- After defining a variable, give it a type:
(type)
- For now, you can use
int
orchar
Int
is a 32 bit number
- For now, you can use
- Give it a value (optional):
123
- If you want to assign it to a string or array, allocate memory for it
- This is done like so:
(type:size)
- Lengths can be auto-assigned with a
?
- Lengths can be auto-assigned with a
- It's value is then defined after it
- Arrays are split by
|
- This is done like so:
- Examples:
jon: (int*) (int:5) 1|2|3|4|5
jon
is an array of 5
foo: (char*) (char:?) "hello"
foo
is a string holding the address ofh
- Strings automatically contain the null character
bob: (int) 123
bob
holds the value123
- The library for stdio must be imported like so
#include libs/stdio.s
- standard out
- The print function is rather simple
print(%type, value)
printLn(%type, value)
- Examples:
print(%i, 123)
print(%c, 'A')
print(%s, foo)
print(%s, (char:?) "yo")
- The print function is rather simple
- standard in
- Getting the most recent KP
getKeyboardInput()
- reading that value
if(keyboard_out == KEY_A)
- Getting the most recent KP
- loops
repeat(variable, end)
...end @repeat
- Translates to
for(; variable < end;;) {...}
- Translates to
- if/elif//else/endif
if(a comp b)
elif( a comp b)
else
endif()
- Only should be used at the end of the entire conditional
- Ex.
if
...elif
...else
...endif()
function <name> <return type> (<parameter type> <parameter name>...)
- you can also return
void
if you wish
- you can also return
return <value>
end @function
- FUNCTION ARE AUTOEXECUTED
- To avoid this add a
start main
before your function definitions - And then add a
main:
after your functions
- To avoid this add a
++* <var>
- Inc. value in pointer
* <var>
- Calls pointer
& <var>
- base address of a pointer
&<var>
- base address variable, function, label
- note the lack of a space inbetween
- *=
- pointer = pointer
- not
x = x * y
<var>[<addr>]
- index
- All statements to be evaluates must be
- surrounded in
{...}
- or
evaluate(...)
DEPRECATED
- surrounded in
- Supports:
+,-,x,/,>>,<<,|
- Note, the times symbol must be an
x
- Note, the times symbol must be an
- Important
- The equation
x *= y
does not mean times-equal, instead it meansx = y
, where both varibales are pointers
- The equation