NITLang is a small educational programming language developed as part of the Programming Language Design course.
It evolves step-by-step from arithmetic expressions to recursion, scoping, references, types, objects, lambdas, and a virtual machine backend.
AST.py
Tokenizer.py
Parser.py
SemanticAnalysis.py
CodeGenerator.py
tsvm.py
test.txt
README.md
flowchart LR
A[Source Code TXT] --> B[Lexer Tokenizer]
B --> C[Parser]
C --> D[AST Tree]
D --> E[Semantic Analysis]
E --> F[Code Generator]
F --> G[TSVM Assembly]
G --> H[TSVM Virtual Machine]
All node types that define the structure of NITLang programs are implemented in
AST.py.
Includes node classes for:
- Program, Functions, Classes
- Binary / Unary operations
- Assignments, Variables
- If / While / Block statements
- Vectors, Indexing
- Object creation, Methods, Field access
- Lambda nodes
Implemented in Tokenizer.py using PLY.
Supports:
- Keywords:
let,func,class,if,while,ref,lambda,map, … - Operators:
+ - * / == != <= >= := -> && || - Literals: integers, strings, booleans, multi-line strings
- Comments: single-line and nested
Implemented in Parser.py.
Builds the AST using PLY YACC.
The parser handles:
- Expressions
- Conditionals / Loops
- Functions & recursion
- Types
- Classes & objects
- Lambdas
- Vectors
Implemented in SemanticAnalysis.py.
Checks:
- Type correctness
- Scope (global, local, params)
- Object field rules (private, must use
this) - Lambda typing
- Reference rules (
ref,:=)
Implemented in CodeGenerator.py.
Produces stack-based TSVM assembly.
Handles:
- Arithmetic, logic, comparisons
- Stack frames & calling conventions
- Methods & constructors
- Object layout (field offsets)
- Vectors & indexing
- References
- Memory allocation
Implemented in tsvm.py.
Supports:
- Registers (
r0,r1, …,fp,sp) - Stack (0–9000), Globals (10000+), Heap (20000+)
- Instructions:
mov,ld,st,add,sub,mul,div,
cmp,push,pop,br,bz,bnz,call,ret
pip install ply
python Parser.py
Output:
✔ Semantic validation
✔ Generated assembly → output.tsvm
python tsvm.py output.tsvm
flowchart TB
subgraph Compiler
L[Lexer] --> P[Parser]
P --> AST[AST Tree]
AST --> S[Semantic Analyzer]
S --> CG[Code Generator]
end
subgraph Runtime
CG --> ASM[output.tsvm]
ASM --> VM[TSVM Virtual Machine]
end
VM --> OUT[Program Output]
Covers all features:
- Arithmetic
- Recursion (
fact) - Scope
- References
- Types
- Classes & methods
- Lambdas & map