1 Star 0 Fork 0

yihuo / cloxx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

cloxx Build Status

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.

Running cloxx

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.

Setup project

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

Build

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.

Test

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

Directory layout

  • 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.
MIT License Copyright (c) 2021 Chan Ryu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

cloxx is a C++ implementation for the Lox programming language from the book Crafting Interpreters. 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/yihuo0420/cloxx.git
git@gitee.com:yihuo0420/cloxx.git
yihuo0420
cloxx
cloxx
master

搜索帮助