lib/libesp32/berry/README.md
Berry is a ultra-lightweight dynamically typed embedded scripting language. It is designed for lower-performance embedded devices. The Berry interpreter-core's code size is less than 40KiB and can run on less than 4KiB heap (on ARM Cortex M4 CPU, Thumb ISA and ARMCC compiler).
The interpreter of Berry include a one-pass compiler and register-based VM, all the code is written in ANSI C99. In Berry not every type is a class object. Some simple value types, such as int, real, boolean and string are not class object, but list, map and range are class object. This is a consideration about performance. Register-based VM is the same meaning as above.
Berry has the following advantages:
Reference Manual: Wiki
Short Manual (slightly outdated): berry_short_manual.pdf.
Berry's EBNF grammar definition: tools/grammar/berry.ebnf
niltrue and falseint) and Real (real)[1, 2, 3]{ 'a': 1, 2: 3, 'map': {} }0..5=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=<, <=, ==, !=, >, >=&&, ||, !+, -, *, /, %&, |, ~, ^, <<, >>.[]+? :()if-elsewhile and forbreak and continueraise statementInstall the readline library (Windows does not need):
sudo apt install libreadline-dev # Ubuntu
brew install readline # MacOS
Build (The default compiler is GCC):
make
Run:
./berry # Bash or PowerShell
berry # Windows CMD
Install (Only Unix-like):
make install
Visual Studio Code plugin are in this directory: ./tools/plugins/vscode.
After compiling successfully, use the berry command with no parameters to enter the REPL environment:
Berry 0.0.1 (build in Dec 24 2018, 18:12:49)
[GCC 8.2.0] on Linux (default)
>
Now enter this code:
print("Hello world!")
You will see this output:
Hello world!
You can copy this code to the REPL:
def fib(x)
if x <= 1
return x
end
return fib(x - 1) + fib(x - 2)
end
fib(10)
This example code will output the result 55 and you can save the above code to a plain text file (eg test.be) and run this command:
./berry test.be
This will also get the correct output.
Berry is free software distributed under the MIT license.
The Berry interpreter partly referred to Lua's design. View Lua's license here: http://www.lua.org/license.html.