Skip to content

FrederikTobner/Cellox

Repository files navigation

Cellox

Build Interpreter Build Tools Test Analyze

Compiler based on the book Crafting interpreters for the programming language cellox.

Cellox is a programming language based on lox from Robert Nystrom.

Table of Contents

Overview

Cellox is a dynamically typed, object oriented, high-level scripting language.

It is available under windows, linux and macOS but is currently in an experimental state. Some of the language features that are currently included (especially native functions), might change or not be included in the upcoming versions of the compiler.

Values

In cellox values are grouped into four different types:

  • booleans,
  • numbers,
  • undefiened (null)
  • and cellox objects (e.g. a string or a class instance)

Control structures

The language provides the following control structures:

Operators

Cellox features assignment, binary, logical and unary operators.

Objects

In Cellox everything besides the three base data types is considered to be a cellox object.

Even functions and classes are considered to be a cellox object.

This means that you can for example get the reference to a function and assign it to a variable.

Functions

A Function in Cellox is a group of statements, that together perform a task.

Some functions in Cellox also access the enclosing environment of the function to for example change the value stored in variable in the enclosing environment.

These functions are called closures and the values that are accessible for the functions are called upvalues.

Cellox also offers some native functions that are implemented in C.

Classes

Cellox is a objectoriented language, that features inheritance and methods that are bound to a class instance.

Classes can also extend the functionality of an already existing class by using inheritance.

Strings

A string in cellox is a special type of object.

Strings can contain escape sequences that will be resolved at compile time.

The characters that a string contains can be accessed by the index.

Arrays

Arrays have a variable-size, meaning they can shrink and grow.

There is no tradional array, with a fixed capacity that is specified at allocation.

Slices

A slice is a subset of an already existing array or string.

Slices are created by using the range operator.

The values stored in slice can be altered without affecting the original array.

IDE Integration

There are plugins for vscode, vim and neovim. Another alternative is to use my own text editor YATE that has built in language support.

Vim VSCcode YATE

How it works

The language provides automatic memory management to the programmer using it's own garbage collector, that uses the mark-and-sweep algorithm.

The variables defiened in a cellox program are stored in a hashtable. The variable name is used as the key for the value stored in the hashtable.

The program is converted into bytecode and executed by a stack based virtual machine.

The bytecode can also be stored in a seperate file in order to be executed at a later point in time.

More information about the compiler can be found at the technical documentation.

License

This project is licensed under the GNU General Public License