Skip to content

SSinghNet/jlox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lox Language Interpreter

Written in Java

Lox is a object oriented, dynamically typed language. Jlox is an interpreter written for the Lox language in Java. It uses the JVM as the backbone to the interpreter and implements it with a "tree-walk" interpeter. The interpreter works by first scanning the code for tokens, which is fed into the parser to be turned into a list of statements, and then is given to the resolver to run the code.

Interpeter Usage:

java -jar Lox.jar [filename]

Lox Examples

Lines are teriminated with semicolons.

The var keyword is used to initialize variables.
Example:

var a = 4;
print a; // 4

Loops should look familar.
Example:

fun fib(n){ // gets up to n of the fibonacci sequence
    var a = 0;
    var b = 1;
    var c = 0;
    while (c < n){
        c = a + b;
        print c;
        a = b;
        b = c;
    }
}

The fun keyword is used to define functions.
Example:

fun factorial(n){
    if (n < 1){
        return 1;
    }
    return n * factorial(n-1);
}

The class keywords is used to define classes and < is used for inheritance of a superclass.
Example:

class Animal {
    init(age, name){
        this.age = age;
        this.name = name;
    }

    getSound(){
        return "generic sound";
    }
}

class Lion < Animal {
    init(age, name, weight){
        super.init(age, name);
        this.weight = weight;
    }

    getSound(){
        return "roar";
    }

    eat(){
        return "ate";
    }
}

var gabe = Lion(22, "Gabe", 140);
print gabe.weight;
print gabe.getSound();
print gabe.eat();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages