GithubHelp home page GithubHelp logo

racket-lox's Introduction

racket-lox

racket-lox is an implementation of the Lox language from Robert Nystrom's book Crafting Interpreters in Typed Racket.

This interpreter is based on the tree-walking Java interpreter described in part II of the book, meaning it largely follows the book's imperative style, rather than the functional programming that is more common in Racket. However, there are a few differences in the implementation:

  • Rather than using classes and inheritance to model the AST nodes, we instead model the tree as a union type of structs. This means that we use pattern matching rather than the Visitor pattern in the evaluator and the resolver.
  • As such, there is no need for the metaprogramming described in chapter 5 to create classes for the AST nodes.
  • Callable is implemented as a union type of Function, NativeFunction and Class. Because of annoyances surrounding cyclic imports, the Callable-related code lives in interpreter.rkt rather than in a separate file.
  • Error related functions are placed in a separate file, error.rkt rather than with the top-level program interface, which lives in main.rkt.

Despite the differences, racket-lox passes all of the tests provided by Nystrom.

Running the interpreter

To run the interpreter, simply use racket src/main.rkt, passing a .lox file as an argument to run a script. Note that because of the use of typed racket, the interpreter is very slow when run uncompiled. Therefore it's best to use raco make src/main.rkt before executing.

To build an executable (e.g. to use with the test runner), use raco exe -o dist/main src/main.rkt.

racket-lox's People

Contributors

micahcantor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.