This is a simple little fun project I am working on to learn more about parsers and the JVM. The idea is to make a tiny but usable language that compiles and emits JVM bytecode (.class file).
The parser is generated using ANTLR . u can find the grammer in the Quark.g4 file . The tree walking is done in java classes while using the ASM library to generate the jvm bytecode .
Open the project in IntelliJ and add all the JARs from the jars folder to the classpath. Then run the code while passing the filepath to the .quark file . Here we use test.quark.
Remember IntelliJ runs the code from the root path so make sure the file path is correct . It will generate a filename.class file in the root folder itself , run it with the JVM. ($ java filename)
See the test.quark file for examples
add the std library as class path in your .bashrc or .zashrc
For eg
export CLASSPATH=".:/home/tervicke/IdeaProjects/Quark/std:$CLASSPATH"
compile and create the build directory
make all
run the file
make run input=examples/structs.quark
run the binary
cd examples
java structs
see more examples
The tests are stored in the json file , u can run the tests by running the python file file.
python3 run_tests.py
- Integer literals (
INT) - Double literals (
DOUBLE) - Boolean literals (
true,false) - String literals (
"...") - Parenthesized expressions
(expr)
- Basic types:
int,string,bool,double - Variable declaration with type (e.g.,
int x = 5) - Variable declaration without type (type inference)
- Variable reassignment (
x = expr) - Typed function parameters
- Optional return type for functions (
-> TYPE) - Const or immutable variables (e.g.,
const x = 10)
- Arithmetic operators:
+,-,*,/,% - Comparison operators:
<,>,<=,>= - Equality operators:
==,!= - Field access:
obj.field - Logical operators:
&&,||,! - Unary minus / plus (
-a,+a) - Ternary expressions (
cond ? a : b)
- If statements (
if (cond) { ... }) - If-else blocks
- While loops (
while (cond) { ... }) - Nested blocks
{ ... } - For loops
- Break & continue statements
- Switch / match expression
- Function definition (
fn name(args) { ... }) - Function call (
foo(1, 2)) - Return statement (
return expr) - Optional return type (
-> int) - Function call from module (
mod.func()) - Recursive functions
- Lambdas or anonymous functions
- Struct definition (
struct Name { ... }) - Struct fields with types
- Struct instantiation (
Point(1, 2)) - Field access (
p.x) - Nested structs
- Struct methods
- Print statement (
print(...)) - Input from user
- String formatting
- Basic standard library (e.g.,
len(string), math functions)
- Import statement (
import module) - Importing specific functions or structs
- Export keywords for public APIs