- Bytecode
- Configuration
- Comments
#
- Conditions
if
else
end
- Constants
true
false
HIGH
LOW
INPUT
OUTPUT
- Cycles
for
while
next
break
continue
- Functions
function
locals
return
- Macros
macro
- Numeric variables
@
@[]
- Operators
+
-
*
/
%
==
!=
>
>=
<
<=
&&
||
&
|
^
>>
<<
++
--
~
not
- Strings
:
:[]
- System functions
adc read
args
char
cursor
delay
file close
file open
file read
file write
include
index
input
io open
io read
io write
jump
label
mem
millis
number
numeric
print
random
restart
serial open
serial read
serial write
size
stop
string
system
- Unary operators
++
--
Using the adc
keyword along with read
, write
, open
and close
it is possible to fully handle the ADC (Analog to Digital Converter).
adc read [number or variable]
It receives a single parameter. Reads an analog pin and returns a value between 0 and 1023.
print adc read A0 // Prints a value between 0 and 1023
Using the args
keyword it is possible to access to arguments that have been passed to the program.
print args[0] // Prints the first argument passed to the program
cursor [number or variable], [number or variable]
It receives two parameters. Moves the cursor to the coordinates received.
cursor 0, 0 // Moves the cursor to x 0, y 0
delay [number or variable]
It receives a single parameter. Pauses the execution of the program for a given amount of milliseconds.
delay 1000 // Pauses the execution of the program for 1 second
Using the file
keyword along with read
, write
, open
and close
it is possible to fully handle files.
file open [string or string literal], [number or variable]
It receives two parameters, the file path and the mode. It returns the pointer to the file.
@f = file open "test.txt", 0 // Opens the test.txt file in reading mode
file close [pointer to file]
It receives a single parameter, the pointer to file. It closes the file.
file close @f // Closes test.txt file
file read [pointer to file], [variable or number]
It receives two parameters, the file pointer and the mode; It returns one character.
@c = file read @f, 0 // Reads one character from test.txt using read mode
Available modes:
0
: read (r)1
: read binary (rb)2
: read write (r+)3
: read write binary (rb+)4
: write (w)5
: write binary (wb)6
: write read (w+)7
: write read binary (wb+)8
: append (a)9
: append binary (ab)10
: append read write (a+)11
: append binary read write (ab+)
file write [pointer to file], [string, string literal, variable or number]
It receives two parameters, the file pointer and the value to be written in the file.
file write @f, "Hello world!" // Writes Hello world! test.txt
With the include
keyword it is possible to add at the end of the program the content of a .bpl
file.
include [string literal]
The include
statement receives a string literal that must contain the path, file name and extension of the file to be included. In the example below hello_world.bpl
that contains the line function hello_world() print "Hello World!" return 0
is included in the program. When executed the program prints "Hello World!" and stops.
include "hello_world.bpl"
hello_world()
stop
index [variable or string]
Receives a single parameter of type variable or string. Returns the position in the buffer of the parameter received.
@roll = 125
@yaw = 150
print index @roll // Prints 0
The user's input source can be configured when the BIPLAN_Interpreter
is instantiated
input
Returns the user's input, it blocks the execution until a carriage return is detected and it returns one character from the user's input.
@i = input
if @i >= 0 print char @i end // Prints user's input
input read
Returns one character from the user's input immediately or -1 if no input is received. The user's input source can be configured when the BIPLAN_Interpreter
is instantiated.
@i = input read
if @i >= 0 print char @i end // Prints user's input
Using the io
keyword along with read
, write
, open
and close
it is possible to fully handle IO (Input Output) ports.
io read [number or variable]
It receives a single parameter. Reads a digital pin, it returns 0 or 1.
print io read 12 // Prints either 0 or 1
io write [number or variable], [number or variable]
It receives two parameters, the pin number and the state (0 or LOW, 1 or HIGH). Sets the state of a digital pin.
io write 12, HIGH // Sets the state of pin 12 to HIGH
io open [number or variable], [number or variable]
It receives two parameters, the pin number and the mode (0 or INPUT, 1 or OUTPUT). Sets the mode of a digital pin.
io open 12, OUTPUT // Sets pin 12 mode as output
jump [variable]
The jump
statement transfers control to the location specified by the label
. It receives a single parameter of type variable.
label @loop
print "Hello world \n"
jump @loop // Prints Hello word cyclically
label [variable]
Saves the position in the program in a variable to be used by jump
later. Receives a single parameter of type variable.
label @loop
print "Hello world \n"
jump @loop // Prints Hello word cyclically
mem[number or variable]
mem[number or variable] = variable or character constant
Can read or write one byte of memory.
mem[0] = 2024
print mem[0] // Prints 2024
millis
Returns the amount of milliseconds elapsed since the program's execution started.
print millis // Prints time elapsed since start up
number [string or string literal or argument]
Converts a string, string literal or argument to an integer and returns its value.
:test = "123"
print number :test + 1 // Prints 124
numeric [variable or number]
Returns true if the input value is a numeric character, false if it is not a numeric character.
@num = '1'
@chr = 'A'
print numeric @num, " ", numeric @chr // Prints true false
print [comma separated parameter list]
Receives a comma separated parameter list of type number, variable or string. It prints the parameters received. char
can be used within print to convert numbers to characters.
print "Hello world!"
To clear the screen, if supported by your physical machine, use the restart
keyword as shown below.
print restart
random [variable or number]
It receives a single parameter, the exclusive maximum value. Returns a randomly generated number.
print random 10 // Prints a number between 0 and 9
restart
Restarts the execution of the program.
restart // Restarts the program
Using the serial
keyword along with read
, write
, open
and close
it is possible to fully handle serial communication.
serial write [variable, number, string or string literal]
Receives a single parameter of type number or variable or string. Transmits via serial the parameter's value.
serial write "CIAO" // Transmits CIAO via serial
serial read
Returns the value received via serial or -1 if no value is received.
print serial read // Prints what is received via serial
serial open [string or string literal], [variable or number]
Returns 1 if the serial port was correctly initialized, -1 if initialization failed.
serial open "COM1", 9600 // Opens serial COM1 at 9600Bd
size [variable or number or string or string literal]
Receives a single parameter of type variable or string. Returns the length of the parameter received.
@v = 0
print size @v // Prints 4
:s = "Hello world!"
print size :s // Prints 12
stop
Halts the execution of the program.
stop //Stops the program's execution
string [variable or number], [string], [variable or number]
Converts a variable or a number to a string. It receives the number to be converted, the string where to save the conversion and optionally the position where to start writing.
@test = 123
string @test, :str
print :str // Prints 123
system [string or string literal]
Passes a command or program name to the host environment, returns after the command has been completed.
system "ls" // On Linux prints list of files and directories