Skip to content

Latest commit

 

History

History
87 lines (64 loc) · 1.45 KB

README.md

File metadata and controls

87 lines (64 loc) · 1.45 KB

jlox

A Lox interpreter made along with Robert Nystrom's wonderful book "Crafting Interpreters".

Differences from the original version

The interpreter supports features that were suggested to be added in the Challenges sections.

  • Dividing by zero is an error

    1 / 0; // Error!
  • Accessing an uninitialized variable is an error

    var a;
    print a; // Error!
  • Not using a local variable is an error

    {
        var a = "unused";
        // Error!
    }
  • C-style comments

    /* This is a comment. */
  • The ternary operator

    print 2 == 3 ? "How?" : "Nice"; // Prints "Nice".
  • Concatenating strings with other types

    print "Hello " + 123; // Prints "Hello 123".
  • The REPL accepts raw expressions and prints their values

    > 2 + 3
    5
  • Break statements

    // Prints "4".
    for (var i = 0; i < 10; i = i + 1) {
        if (i * i == 16) {
            print i;
            break;
        }
    }
  • Anonymous functions

    var hello = fun() {
        print "Hello";
    };
    hello(); // Prints "Hello".
  • Class methods

    class Test {
        class greet() {
            print "Hello!";
        }
    }
    Test.greet(); // Prints "Hello!".