VŠB-TUO — School project · Programming Languages and Compilers (PJP)
A complete compiler and interpreter for a custom statically-typed programming language, built with ANTLR4. The pipeline covers four stages: parsing, type checking, stack-based code generation, and interpretation.
| Stage | Description |
|---|---|
| Parser | ANTLR4 lexer + parser, reports all syntax errors |
| Type checker | Semantic analysis, validates type compatibility |
| Code generator | Produces 26-instruction stack-based bytecode |
| Interpreter | Executes the generated bytecode |
| Type | Literal | Default |
|---|---|---|
int |
sequence of digits | 0 |
float |
digits with . |
0.0 |
bool |
true / false |
false |
string |
"text" |
"" |
Variables must be declared before use. Repeated declaration is an error. int values automatically promote to float where needed — there is no reverse conversion.
type var1, var2;— variable declarationexpression;— expression statement (assignment has side effects)read var1, var2;— read values from stdinwrite expr1, expr2;— write values to stdout, newline after last{ ... }— blockif (cond) stmt [else stmt]— conditionalwhile (cond) stmt— loop//— single-line comment
| Operator | Signature |
|---|---|
= |
x × x → x (right-assoc) |
|| |
B × B → B |
&& |
B × B → B |
== != |
x × x → B |
< > |
x × x → B (numeric) |
+ - . |
arithmetic / string concat |
* / % |
I × I → I or F × F → F |
! |
B → B |
unary - |
I → I or F → F |
| Instruction | Description |
|---|---|
push T x |
Push value x of type T (I/F/S/B) |
pop |
Discard top of stack |
load id |
Push variable value |
save id |
Pop and store into variable |
add sub mul div mod |
Binary arithmetic |
uminus |
Unary minus |
concat |
String concatenation |
and or not |
Boolean logic |
gt lt eq |
Comparisons |
itof |
Convert int to float |
label n |
Mark jump target |
jmp n |
Unconditional jump |
fjmp n |
Jump if top of stack is false |
print n |
Pop and print n values |
read T |
Read value of type T from stdin |
- Java 21+
- Maven 3.8.1+ (ANTLR 4.9.2 managed automatically)
-
Clone the repository:
git clone https://github.com/Firestone82/ParsingCompiler.git cd ParsingCompiler -
Build:
mvn clean package
-
Run a program:
java -jar target/ParsingCompiler-*.jar path/to/program.lang
Sample programs and error examples are in the src/main/antlr4/Project/ directory.
This project was created as a school assignment at VŠB-TUO.

