llvm-journey

LLVM Journey
git clone git://0xff.ir/g/llvm-journey.git
Log | Files | Refs | README | LICENSE

commit 6661dca50043e1a52adb48db45cb0c6ef7c6afa8
parent 2f9f2455aaeb0ab7acd1717676e078196d135e76
Author: Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
Date:   Thu, 17 Sep 2020 06:34:04 +0430

README.md: Add description for kal::ASTNode

Diffstat:
MREADME.md | 35+++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -178,3 +178,38 @@ Token{ /*str*/ "", } ``` + +## Chapter 2: Kaleidoscope: Implementing a Parser and AST + +- **Implementation** `kaleidoscope_ast.hpp`, `kaleidoscope_ast.cpp` +- **Test** `tests/kaleidoscope_ast.test.cpp` + +Each node of AST (Abstract Syntax Tree) can be saved in `ASTNode` class. It's a +polymorphic type that accepts an instance of type `T` that satisfies the +following requirements: + +- `T` is a + [SemiRegular type](https://en.cppreference.com/w/cpp/concepts/semiregular) +- The following functions are defined: + - `std::string to_string(const T&);` + - `kal::NodeType node_type(cons T&);` + +`kal::NodeType` is an `enum class`: + +```c++ +enum class NodeType +{ + None = -1, + Number, + Variable, + BinaryOp, + Call, + Prototype, + Function, +}; +``` + +For more information about implementation details of this polymorphic type and +the benefits of this design, you can watch +[this great talk by Sean Parent](https://youtu.be/QGcVXgEVMJg). +If you're impatient you can go directly to time `49:13`.