cloxx is a C++ implementation of Lox, the language featured in the book Crafting Interpreters.
cloxx is a purely educational project for myself and thus it won't be vrery useful for building real-world applications. However, if you're another reader of the book and implementing Lox in C++, you may find cloxx an interesting reference. While it's fully C++ish, I tried to make it as close as possible to the book's jlox implementation in terms of identifiers in the code such as class, variable and function names. It should be easy to follow along with the book.
Aside form the techniques explained the book such as Recursive Descent Parsing and Tree-Walk Interpretation, cloxx implements Mark-and-Sweep Garbage Collection.
While I don't want to spend more time on supporting other environments than my MacBook, the following instructions would work for most Posix-compatible environments with minimal (if not none) tweaks where CMake, bash and a decent C++17 compiler are available.
Once you've cloned the repo, you should run the configuration script to setup the project. It will generate Posix-compatible makefiles via CMake.
$ script/configure.sh # pass "--debug" if that's what you want
As well as the source files checked into the repo, you will also need to generate some files to build the project. You won't need to do it again unless you're hacking — i.e., modifying Abstract Syntax Tree — cloxx.
$ script/gen-ast.sh
As mentioned earlier, we use CMake to build the probject. The following command will do that for you:
$ script/build.sh # it's just a convenient wrapper around `cmake --build`
If everthing goes well, you should have an executable cloxx
under the build
directory.
While I didn't put much effort on creating tests, cloxx is fully compatible with jlox. This means I can just reuse jlox's comprehensive test suites. The following Python script runs the full jlox test suites imported from the Crafting Interpreters repo.
$ tool/run-test.py
build/
- Intermediate files and other build output go here. Not committed to Git.gen/
– C++ source files generated by gen-ast.py
. Not committed.src/
– Most of the C++ source files.test/
- Test suite files imported from the Crafting Interpreters repo.tool/
- Mostly, Python scripts for generating files and unit testing.scripts/
- Shell scripts to configure the projects, wrapper of the above Python scripts, and etc.此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。