Borsch Interpreter
Features
- The code is very similar to PHP
- Written in C++ with STL, clear OOP
- No external library dependencies
- Bool, int, float and string data types
- Global and local variables
- C/C++ like evaluation of expressions
- If-else, for, while statements
- Buildin and user defined functions
- Return, break and continue structured jumps
- Preprocessor file includes
- Colored errors/warnings output
- Development dumps to the XML format
License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Code example
[woq@plecka ~/borsch]$ cat scripts/factorial_inc.txt function factorial($number) { if($number < 2) return 1; else return $number * factorial($number - 1); } [woq@plecka ~/borsch]$ cat scripts/factorial.txt include("scripts/factorial_inc.txt"); echo("Factorial of numbers from 0 to 9:\n"); echo("==================================\n"); for($i = 0; $i <= 9; $i++) echo("Factorial of " + $i + " is " + factorial($i) + "\n"); [woq@plecka ~/borsch]$ ./borsch Usage: ./borsch [--lex-dump] [--call-tree-dump] <filename> [woq@plecka ~/borsch]$ ./borsch scripts/factorial.txt Factorial of numbers from 0 to 9: ================================== Factorial of 0 is 1 Factorial of 1 is 1 Factorial of 2 is 2 Factorial of 3 is 6 Factorial of 4 is 24 Factorial of 5 is 120 Factorial of 6 is 720 Factorial of 7 is 5040 Factorial of 8 is 40320 Factorial of 9 is 362880 [woq@plecka ~/borsch]$
Notes
This interpreter was created as a semestral project to the Programming Languages and Compilers (X36PJP) at Czech Technical University in Prague, Faculty of Electrical Engineering. Special thanks to Ladislav Vagner.