A minimalistic programming language built using Scala 3.6 and ANTLR 4.13.
This simple programming language features a single loop construct (while
) and supports only integer types.
The language is implemented in two distinct ways:
- As an interpreter
- As a transpiler (source-to-source compiler) targeting Scala.
Interpreter | Transpiler (Compiler) | |
---|---|---|
Grammar | Grammar (29 lines) | |
Abstract Syntax | Abstract Syntax (23 lines) | |
Semantics | Semantics (35 lines) | Semantics (34 lines) |
Parser Rules | Listener (56 lines) | |
Main | Main (4 lines) | Main (4 lines) |
Utility Classes |
Walker (20 lines) Runner (14 lines) ContextValue (13 lines) |
|
Total | 194 lines | 193 lines |
Below are some example programs:
print "Hello World"
print "Enter the first number:";
a := read;
print "Enter the second number:";
b := read;
sum := a + b;
print "The sum is: ";
print sum
print "Fibonacci Sequence";
a := 0;
b := 1;
while b <= 1000000 do {
print b;
b := a + b;
a := b - a
}
To compile the project, you'll need to install sbt. The easiest installation method is via SDKMAN! (Linux) or Scoop (Windows).
$ sbt
sbt> clean
sbt> compile
# Run the interpreter
sbt> runMain whilelang.interpreter.main sum.while
# Run the transpiler
sbt> runMain whilelang.compiler.main sum.while