Skip to content

A brand new Lox interpreter, now in C, still written along with Robert Nystrom's wonderful book "Crafting Interpreters".

Notifications You must be signed in to change notification settings

linewelder/clox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clox

Tests

A brand new Lox interpreter, now in C, still written along with Robert Nystrom's wonderful book "Crafting Interpreters".

The test suite was adapted from the book's repository.

Differences from the original version

The interpreter supports features that were suggested to be added in the Challenges sections. This section only documents the differences that affect the language.

  • Infinite stack capacity

    The stack grows to accomodate all the values pushed to it.

  • Switch statements

    The following code:

    // Prints "Correct!".
    switch (2 + 2) {
        case 4:
            print "Correct!";
        case 5:
            print "Will not run";
            print 1 / 0;
        default:
            print "The default case";
    }

    Is semantically equivalent to this:

    {
        var temp = 2 + 2;
        if (temp == 4) {
            print "Correct!";
        } else if (temp == 5) {
            print "Will not run";
            print 1 / 0;
        } else {
            print "The default case";
        }
    }

    Note: unlike in most other languages, this switch statement allows for any expressions in case clauses, does not allow fallthroughs and thus does not require break;s at the end of each case.

  • Continue statements

    Skips the rest of the loop body, jumping to the condition check for the next iteration.

    // Prints only "4".
    for (var i = 0; i < 10; i = i + 1) {
        if (i != 4) continue;
        print i;
    }
  • Arity checking for native function calls

    The number of arguments passed to a native function is checked.

    print clock("extra argument"); // Error!
  • Several new built-in functions

About

A brand new Lox interpreter, now in C, still written along with Robert Nystrom's wonderful book "Crafting Interpreters".

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published