Icon of a tree Crafting Interpreters

A simple interpreter that runs in your browser. Powered by Rust
Reference

Builtin Types

  • Number - 64 bit float
  • Str
  • Bool
  • Array
  • Function
  • Nil

Native Functions

In case of errors or invalid arguments, a global error variable named "errString" is set with the error message and the function returns nil. Otherwise, the global error variable is set to nil.
  1. clock() -> Number

    Returns the current epoch in milliseconds.
  2. print(Str)

    Prints the given string to the output.
  3. printf(String format, ...) -> Nil

    Prints a formatted string with support for placeholders. Placeholders can be numeric indices like {0}, {1}, or variable names like {name}.
  4. input(String) -> Str

    Reads a string from the input, displaying the optional given string as a prompt.
  5. import "path" as alias;

    Imports another Lox file and namespaces its functions and variables under `alias` (e.g. `alias.method()`).
  6. typeof(Any) -> String

    Returns the type of the given value.
  7. str(Any) -> String

    Converts the given value to a string.
  8. int(Any) -> Number

    Converts the given value (number, bool, or string) to an integer.
  9. float(Any) -> Number

    Converts the given value (number, bool, or string) to a float.
  10. bool(Any) -> Bool

    Converts the given value to a boolean following pythonic truthiness rules.
  11. stringat(String, Number) -> String

    Returns the character at the given index in the string.
  12. len(Str/Array) -> Number

    Returns the length of the given string or array.
  13. ceil(Number) -> Number

    Returns the smallest integer greater than or equal to the given number.
  14. floor(Number) -> Number

    Returns the largest integer less than or equal to the given number.
  15. abs(Number) -> Number

    Returns the absolute value of the given number.
  16. rand() -> Number

    Returns a 32-bit unsigned integer (as Number).
  17. sort(Array)

    Sorts an array of numbers in ascending order. If the array has non-numbers, it's an error.
  18. indexof(Array, Any) -> Number

    Returns the index of the given value in the array. If the value is not found, returns the length of the array.
  19. clear() -> Nil

    Clears the output. On CLI, emits ANSI escape codes to clear the terminal screen. On the web, clears the output box.
  20. sin(Number) -> Number

    Returns the sine of the given value (in radians).
  21. sleep(Number)

    Sleep for given milliseconds.
  22. cos(Number) -> Number

    Returns the cosine of the given value (in radians).
  23. sqrt(Number) -> Number

    Returns the square root of the given number.
  24. pow(Number, Number) -> Number

    Returns the first argument raised to the power of the second argument.
  25. pi() -> Number

    Returns the mathematical constant π (3.14159…).

Try a sample:

Output



Ready

Source Code | Inspired by The Crafting Interpreters Book | Terraria icon by Icons8