Zealot is a Tree-Walking Interpreter designed for simplicity, efficiency, and ease of use which I developed while learning. It aims to provide a clean and concise syntax while offering powerful features for developing a wide range of applications.
Before running Zealot, ensure that you have the following installed on your system:
- Java Development Kit (JDK): You can download and install JDK from the official Oracle website.
Zealot supports text files with zlt
file extension.
example: main.zlt
A simple hello world program in Zealot:
print "Hello, World!";
Semi-colons at the end of every line is mandatory in Zealot.
Zealot has following datatypes
These can number literals which can be both integers and floating point numbers.
examples: 1
, 2.5
, 9
These are string literals defined inside "
examples: "Zealot"
, "Strings are easy"
These are boolean literals which can be either true
or false
.
examples: true
, false
Zealot has nulls, the trillion dollar mistale. It can be defined using the nill
keyword. All uninitialized variables are given the value of nill
.
examples: nill
Zealot has following operators:
=
- equals
-
- Unary negation
and
- logical AND
or
- logical OR
!
- logical NOT
+
- sum
-
- difference
*
- product
/
- division
%
- mod
==
- is equals
!=
- is not equals
>
- is less than
>=
- is less than or equals
>
- is greater than
>=
- is greater than or equals
Zealot support both single line and multi line comment.
- Single line comment
// This is a comment.
// The Lexer completely ignores any line starting with
// The Whole line is ignored.
- Multiline comment
/*This is a mulit line comment similar to C syntax.*/
var x = 15; // number
var name = "your name"; // string
var yes = true; // booleans
var no = false; // booleans
var nullable = nil;
!true; // false.
!false; // true.
true and false; // false.
true and true; // true.
false or false; // false.
true or false; // true.
var x = 15;
if(x > 0){
print "x > 0";
}else {
print "x <= 0";
}
var i = 0;
while(i < 10){
print i;
i = i + 1;
}
for(var j=0; j<5; j = j + 1){
print j;
}
fun greetings(name){
print "hello " + name;
}
greetings("piscan");
fun addPair(a, b) {
return a + b;
}
fun identity(a) {
return a;
}
print identity(addPair)(1, 2); // Prints "3".
fun makeCounter(){
var c = 0;
fun counter(){
c = c + 1;
print c;
}
return counter;
}
var counter1 = makeCounter();
var counter2 = makeCounter();
counter1(); // 1
counter2(); // 1
To run Zealot, First clone Zealot Repository and navigate to the Zealot
directory in your terminal and execute the following command:
git clone https://github.com/kmr-ankitt/Zealot
cd Zealot
For Linux and macOS:
source .bashrc
- Repl Mode
zealot
- Zelaot file
zealot FILE_DIRECTORY
For Windows:
- Repl Mode
./zealot.bat
- Zealot File
./zealot.bat FILE_DIRECTORY
Or Using Make
For Linux and MacOS :
- Repl mode
make compile
make repl
- Zealot file
make run INPUT="FILE_DIRECTORY"
After running Zealot, you may want to clean up compiled files. Use the following commands:
For Linux and macOS:
make clean
For Windows:
Get-ChildItem -Path .\com\piscan\zealot -Filter *.class -Recurse | Remove-Item -Force
These commands will remove all compiled .class
files, ensuring a clean environment