zlang
is a custom programming language developed as an exploratory project around programming language development. This project aims to implement a complete language utilizing LLVM as a backend. The compiler will compile zlang
code to LLVM Intermediate Representation (IR) Code, which LLVM can take to further optimize and build binaries on multiple architectures.
The goal is to build an interpretor for the language in the future as well.
Here is the grammar that I aim to implement.
program -> fn main() scope EOF
scope -> {stmts}
stmts -> stmt stmts
stmts -> ϵ
stmt -> func_decl
stmt -> scope
stmt -> while_stmt
stmt -> if_stmt
stmt -> let id = expr;
stmt -> return expr;
stmt -> expr;
stmt -> ;
stmt -> ϵ
func_decl -> fn id(args) scope
while_stmt -> while (conditions) scope
if_stmt -> if (conditions) scope if_tail
if_tail -> elsif (conditions) scope if_tail
if_tail -> else scope
if_tail -> ϵ
expr -> mult_expr '+' expr
expr -> mult_expr '-' expr
expr -> mult_expr
mult_expr -> term_expr '*' mult_expr
mult_expr -> term_expr '/' mult_expr
mult_expr -> term_expr
term_expr -> number
term_expr -> id term_expr_tail
term_expr_tail -> ϵ
term_expr_tail -> (params)
term_expr -> (expr)
conditions -> condition conditions_tail
conditions -> (conditions)
conditions_tail -> lop conditions
conditions_tail -> ϵ
condition -> expr cmp expr
condition -> (condition)
args -> id args_tail
args -> ϵ
args_tail -> , id args_tail
args_tail -> ϵ
params -> expr params_tail
params -> ϵ
params -> , expr params_tail
params_tail -> ϵ
op -> '+' | '-' | '*' | '/'
lop -> '||' | '&&'
cmp -> '<' | '>' | '<=' | '>=' | '==' | '!='
Currently, I have completed the tokenizing and lexical analysis phase of the zlang
development. I am now focusing on the semantic analysis and building the Abstract Syntax Tree (AST) for the language.
Semantic Productions Implemented:
- Program
- Statements
- Function Declarations
- Function Calls
- While Loops
- If Statements
- Expressions
- Conditions
- Arguments
- Algebra/Comparison/Logic Operators
The roadmap for the zlang
project includes the following milestones:
- Tokenizing
zlang
scripts and performing lexical analysis. - Implementing the parser to generate the AST.
- [Current] Constructing the Abstract Syntax Tree (AST)
- Decorating AST with LLVM IR Code.
- Generating Binary through
llvm
- Testing and debugging the language implementation to ensure correctness and reliability.
- Documenting the language specification, usage, and examples.