You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-18Lines changed: 37 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,18 @@
6
6
## Introduction
7
7
8
8
**MicroJava** is a *high-level programming language*.
9
-
As the name suggests, **MicroJava** is *similar* to **Java** (which you are, probably, already familiar with), but it's *simpler*.
10
-
Similarly to Java, MicroJava source files are compiled to **bytecode**, which is then executed by a **virtual machine** (it's called (as you might have guessed) **MicroJava Virtual Machine**). MicroJava VM is a simple *interpretative emulator* (i.e. it does not have any support for some "fancy" techniques such as, e.g., *Just-In-Time compilation*).
9
+
As the name suggests, **MicroJava** is *similar* to **Java** (which you are, probably, already familiar with), but it's
10
+
*simpler*.
11
+
Similarly to Java, MicroJava source files are compiled to **bytecode**, which is then executed by a **virtual machine**
12
+
(it's called (as you might have guessed) **MicroJava Virtual Machine**). MicroJava VM is a simple
13
+
*interpretative emulator* (i.e. it does not have any support for some "fancy" techniques such as, e.g.,
14
+
*Just-In-Time compilation*).
11
15
12
16

13
17
14
-
The project specification can be found [here](https://1drv.ms/b/s!AuZ7wmWsDfythjkXnkK3T5gJ7NIy) and [here](https://1drv.ms/b/s!AuZ7wmWsDfythjgxu8VErKo9wBa7) (Serbian language only).
15
-
This implementation uses a modern, Gradle-based directory structure rather than the ad-hoc structure suggested in the original project specification.
18
+
This project is based on a university-level compiler construction assignment. However, this implementation has been
19
+
significantly refactored to align with modern industry standards, including a Gradle-based build system, automated
20
+
CI workflow, and a clean, modular directory structure.
16
21
17
22
## Main language features
18
23
@@ -21,7 +26,8 @@ This implementation uses a modern, Gradle-based directory structure rather than
21
26
* The main method of a MicroJava program is always called `main`.
22
27
When MicroJava program is executed, this method is called first (i.e. it's the program's entry point).
23
28
* There are:
24
-
* Value/primitive types (`int`, `char` and `bool`) and reference/structured types (one-dimensional arrays and user-defined classes)
29
+
* Value/primitive types (`int`, `char` and `bool`) and reference/structured types (one-dimensional arrays and
30
+
user-defined classes)
25
31
* Integer, character and boolean constants
26
32
* Global, local and class variables (i.e. fields)
27
33
* Global (static) and class functions (i.e. methods).
@@ -34,14 +40,17 @@ This implementation uses a modern, Gradle-based directory structure rather than
34
40
The act of converting a subclass reference into a superclass reference is called up-casting.
35
41
* Superclass methods can be **overridden** in its subclass.
36
42
Because of that, method binding occurs at run-time, based on the type of the object.
37
-
This is **polymorphism** (also called dynamic binding or late binding or run‐time binding) and it is a key principle of OOP.
38
-
* Within a method, the name of a field refers to the current object's field, assuming that the field isn't hidden by a method parameter.
43
+
This is **polymorphism** (also called dynamic binding or late binding or run‐time binding) and it is a key principle
44
+
of OOP.
45
+
* Within a method, the name of a field refers to the current object's field, assuming that the field isn't hidden by a
46
+
method parameter.
39
47
If it is hidden, we can access it through `this.<field-name>`.
40
48
In the body of a method, `this` represents reference to the object whose method has been invoked.
41
49
* Method overloading is not supported in MicroJava.
42
50
* There is no `Object` class, the top‐most class, the class from which all other classes are implicitly derived.
43
51
* There is no garbage collector (allocated objects are only deallocated when the program ends).
44
-
* Predeclared static methods are `ord` (converts `char` to `int`), `chr` (converts `int` to `char`) and `len` (returns array's length).
52
+
* Predeclared static methods are `ord` (converts `char` to `int`), `chr` (converts `int` to `char`) and `len` (returns
53
+
array's length).
45
54
46
55
## Syntax specification
47
56
@@ -86,21 +95,31 @@ This implementation uses a modern, Gradle-based directory structure rather than
86
95
`charConst` is a sequence starting with `'` followed by a single printable character and ending with `'`.
87
96
`boolConst` is either `true` or `false`.
88
97
89
-
MicroJava's single line comment starts with two forward slashes with no white spaces (`//`) and lasts till the end of line.
98
+
MicroJava's single line comment starts with two forward slashes with no white spaces (`//`) and lasts till the end of
99
+
line.
90
100
91
101
## Building and testing the project
92
102
93
-
To build and test this project you will need [Java 17](https://adoptium.net/temurin/) (the latest LTS release as of February 2023) and [Gradle 7.3](https://docs.gradle.org/current/userguide/userguide.html).
94
-
Open command-line interpreter and type one of the following commands:
95
-
96
-
*`gradlew lexer` (Windows) or `./gradlew lexer` (macOS and Linux) — to generate lexer (tokenizer) implementation (`MJLexer.java`) based on [lexer specification](src/main/resources/mjlexer.flex).
97
-
*`gradlew parser` (Windows) or `./gradlew parser` (macOS and Linux) — to generate parser implementation (`MJParser.java`, `sym.java`) and abstract syntax tree implementation (classes inside `ast` directory), based on [parser specification](src/main/resources/mjparser.cup).
98
-
*`gradlew build` (Windows) or `./gradlew build` (macOS and Linux) — to build the project, test the compiler and run MicroJava VM. MicroJava Compiler will compile the test file [`simple_calculator.mj`](src/test/resources/simple_calculator.mj) and produce `simple_calculator.obj`. Then, the machine code inside `simple_calculator.obj` will be executed by MicroJava VM.
99
-
Note that, for testing purposes, standard input has been substituted with a file named [`input_stream.txt`](src/test/resources/input_stream.txt).
100
-
*`gradlew disassemble` (Windows) or `./gradlew disassemble` (macOS and Linux) — to disassemble `simple_calculator.obj` produced in the previous step, using [`rs.etf.pp1.mj.runtime.disasm`](libs/mj-runtime-1.1.jar).
103
+
To build and test this project you will need [Java 25](https://adoptium.net/temurin/releases?version=25&os=any&arch=any)
104
+
(the latest LTS release as of February 2026) and
105
+
[Gradle 9.3.1](https://services.gradle.org/distributions/gradle-9.3.1-all.zip). Open command-line interpreter and type
106
+
one of the following commands:
107
+
108
+
*`gradlew lexer` (Windows) or `./gradlew lexer` (macOS and Linux) — to generate lexer (tokenizer) implementation
109
+
(`MJLexer.java`) based on [lexer specification](src/main/resources/mjlexer.flex).
110
+
*`gradlew parser` (Windows) or `./gradlew parser` (macOS and Linux) — to generate parser implementation
111
+
(`MJParser.java`, `sym.java`) and abstract syntax tree implementation (classes inside `ast` directory), based on
*`gradlew build` (Windows) or `./gradlew build` (macOS and Linux) — to build the project, test the compiler and run
114
+
MicroJava VM. MicroJava Compiler will compile the test file [`simple_calculator.mj`](src/test/resources/simple_calculator.mj) and produce
115
+
`simple_calculator.obj`. Then, the machine code inside `simple_calculator.obj` will be executed by MicroJava VM. Note
116
+
that, for testing purposes, standard input has been substituted with a file named [`input_stream.txt`](src/test/resources/input_stream.txt).
117
+
*`gradlew disassemble` (Windows) or `./gradlew disassemble` (macOS and Linux) — to disassemble `simple_calculator.obj`
118
+
produced in the previous step, using [`rs.etf.pp1.mj.runtime.disasm`](libs/mj-runtime-1.1.jar).
101
119
102
120
You can always run MicroJava Compiler as a standalone application.
103
-
In order to achieve this, you just have to type `gradlew run <source-file-name> <obj-file-name>` (Windows) or `./gradlew run <source-file-name> <obj-file-name>` (macOS and Linux).
121
+
In order to achieve this, you just have to type `gradlew run <source-file-name> <obj-file-name>` (Windows) or
122
+
`./gradlew run <source-file-name> <obj-file-name>` (macOS and Linux).
104
123
105
124
---
106
125
**If you find this repository useful, please consider starring it! ⭐**
0 commit comments