/orzo

Java compiler written in Java

Primary LanguageJavaGNU General Public License v2.0GPL-2.0

Progress

Orzo

Orzo is a Java-based language for the JVM.

It's named after my beverage of choice while coding it.

Features

✨ Orzo-only features (not available in Java)

Types

Operators

  • assignment =
  • parallel assignment
  • parallel declarations, e.g. int a,b,c,d,e,f = 1,2,3
  • repeat
  • arithmetic +, -, *, /, %
  • ** power operator ✨, e.g. int b = a ** 5
  • sqrt operator ✨, e.g. double x = √n + √(n+1)
  • parenthesis ( ,)
  • unary post/pre-increment and decrement ++, --
  • compound assignments +=, -=, *=, /=, %=, <<=, >>=, >>>=, &=, ^=, |=
  • relational <, <=, >=, >
  • equality ==, !=,
  • bit &, ^, |, <<, >>, >>>
  • unary minus -
  • casting () (partially supported)
  • object creation new (partially supported)
  • logical &&, ||
  • unary logical !
  • unary bitwise ~
  • unary plus +
  • instanceof
  • String and char concatenation +
  • ternary ?:

Control strcutures

Notes

  • array defintions must be of the form int[] a, int a[] is not supported
  • Orzo creates class files with major version 50 (Java 6). Newer versions would require implementation of the StackMapTable attribute.
  • fields and variables share the same namespace

Example

Calculating π using the Gauss-Legendre algorithm:

public double pi(int n) {
  double a, b, t, p, x = 1, 1/√2, 1/4, 1;
  repeat n
  {
    x, a, b  =  a, (a + b) / 2, √(x*b);
    t, p     =  t - p * ((x-a) ** 2), 2 * p;
  }
  return ((a+b) ** 2) / (4 * t);
}

More examples can be found here.

Build

with mvn

mvn package

with javac and jar

javac $(find ./src/main/java -name "*.java") -d bin && jar cfe orzo.jar io.github.martinschneider.orzo.Orzo -C bin .

Usage

java -jar target/orzo.jar inputFiles -d outputFolder