Skip to content

A minimalistic programming language built using Scala 3.4 and ANTLR 4.13.

License

Notifications You must be signed in to change notification settings

lrlucena/whilelang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

While Language

Codacy Badge

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:

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

Examples

Below are some example programs:

Hello World

print "Hello World"

Sum of Two Numbers

print "Enter the first number:";
a := read;
print "Enter the second number:";
b := read;
sum := a + b;
print "The sum is: ";
print sum

Fibonacci Sequence

print "Fibonacci Sequence";
a := 0;
b := 1;
while b <= 1000000 do {
  print b;
  b := a + b;
  a := b - a
}

Compiling and Running

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