Skip to content

damwaingames/plox

Repository files navigation

plox

This is a python implemenation of the lox langauge as described in the book Crafting Interpreters by Robert Nystrom. In particular the first version from part 2.

Current state

  • Line comments implemented (// comment)
  • Expressions implemented
    • Assignment (IDENTIFIER = Expr)
    • Binary
      • Addition or Concatenation (Expr + Expr)
      • Subtraction (Expr - Expr)
      • Multiplication (Expr * Expr)
      • Division (Expr / Expr)
      • Comparisons
        • Equality (Expr == Expr)
        • Inequality (Expr != Expr)
        • Greater (Expr > Expr)
        • Greater or Equal (Expr >= Expr)
        • Less (Expr < Expr)
        • Less or Equal (Expr <= Expr)
    • Call (Expr())
    • Get (IDENTIFIER.IDENTIFIER)
    • Groupings ((Expr))
    • Literals (NUMBER, STRING, IDENTIFIER, true, false, "nil")
    • Logical
      • And (Expr and Expr)
      • Or (Expr or Expr)
    • Set (Expr = Expr)
    • Super (super.IDENTIFIER)
    • This (this.IDENTIFIER)
    • Unary
      • Negation (-Expr)
      • Logical Inverse (!Expr)
    • Variable (IDENTIFIER)
  • Statements implemented
    • Block ({Stmt})
    • Class (class IDENTIFIER {Stmt})
    • Expression (Expr;)
    • Function (fun IDENTIFIER {Stmt})
    • If (if (Expr) {Stmt} else {Stmt})
    • Print (print Expr;)
    • Return (return Expr;)
    • Var (var IDENTIFIER;)
    • While (while (Expr) {Stmt})
      • For (for (INITIALIZER;CONDITION;INCREMENT) {Stmt}) (Syntactic sugar around a while loop)
  • Scopes implemented
    • Global
    • Dynamic
    • Local
    • Closure

Usage

plox: a lox interpreter written in python

Usage:

$ plox [OPTIONS] COMMAND [ARGS]...

Options:

  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

  • interpret: Execute a lox script.
  • parse: Parse a lox script and display the...
  • repl: Enter an interactive REPL for lox scripting.
  • tokenize: Tokenize a lox script and display the...

plox interpret

Execute a lox script.

Usage:

$ plox interpret [OPTIONS] FILENAME

Arguments:

  • FILENAME: File containing the lox script to be executed. [required]

Options:

  • --help: Show this message and exit.

plox parse

Parse a lox script and display the abstract syntax tree produced from the parsing pass.

Usage:

$ plox parse [OPTIONS] FILENAME

Arguments:

  • FILENAME: File containing the lox script to be parsed. [required]

Options:

  • --help: Show this message and exit.

plox repl

Enter an interactive REPL for lox scripting.

Usage:

$ plox repl [OPTIONS]

Options:

  • --help: Show this message and exit.

plox tokenize

Tokenize a lox script and display the results of the lexing pass.

Usage:

$ plox tokenize [OPTIONS] FILENAME

Arguments:

  • FILENAME: File containing the lox script to be tokenized. [required]

Options:

  • --help: Show this message and exit.

About

A python implementation of the lox programming language.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages