https://github.com/andreimoraru123/clox
Lox compiler
https://github.com/andreimoraru123/clox
bytecode compiler crafting-interpreters programming-language vm
Last synced: 7 months ago
JSON representation
Lox compiler
- Host: GitHub
- URL: https://github.com/andreimoraru123/clox
- Owner: AndreiMoraru123
- Created: 2024-03-01T08:25:06.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-13T07:39:38.000Z (over 1 year ago)
- Last Synced: 2025-06-20T05:04:33.422Z (7 months ago)
- Topics: bytecode, compiler, crafting-interpreters, programming-language, vm
- Language: C
- Homepage: https://craftinginterpreters.com/
- Size: 133 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Lox (programming language implementation)
This is the C implementation of the bytecode compiler and virtual machine from the book.
Each branch (other than `master`) represents an addition to the language, encompassing all the challenges proposed by the author for each chapter (or at least a whole bunch of them).
Here are some sample Lox programs:
```js
fun fib(n) {
if (n < 2) return n;
return fib(n - 2) + fib(n - 1);
}
var start = clock(); // built-in native function call
print fib(10);
print clock() - start;
```
```js
// OOP support via class representation
class Cake {
init(adjective) {
this.adjective = adjective;
}
taste() {
print "The " + this.flavor + " cake is " + this.adjective + "!";
}
}
var cake = Cake("delicious");
cake.flavor = "German chocolate";
cake.taste();
```
```js
class Doughnut {
cook() {
print "Fry until golden brown.";
}
}
// Support for single inheritance
class BostonCream < Doughnut {
cook() {
super.cook();
print "Pipe full of custard and coat with chocolate.";
}
}
BostonCream().cook();
```