From 0d4f840154f4178c33ae5a00e280e3b2bfcba30d Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sat, 19 Jul 2025 12:00:56 +0800 Subject: [PATCH] update --- include/AST.hpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ include/Lexer.hpp | 2 +- tests/test.cpp | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 include/AST.hpp diff --git a/include/AST.hpp b/include/AST.hpp new file mode 100644 index 0000000..6ac3829 --- /dev/null +++ b/include/AST.hpp @@ -0,0 +1,47 @@ +#pragma once + +#include "Lexer.hpp" +#include +#include +#include +#include +#include +#include + +namespace ztl{ + struct AST{ + struct Literal{ + using LiteralType = std::variant; + LiteralType value; + }; + struct Identifier{ + std::string name; + }; + struct BinaryExpression{ + enum OperatorType{ + One, + Add + }; + OperatorType Operator; + using LRType = std::variant< + Identifier, + std::unique_ptr + >; + LRType left; + LRType right; + }; + struct VariableDeclaration{ + Identifier id; + BinaryExpression init; + }; + struct BlockStatement{ + using BodyType = std::vector>; + BodyType body; + }; + AST(const std::vector &tokens){ + for(size_t i=0;i keywords = {"int","print"}; + const static std::vector keywords = {"int"}; bool isKeywords = false; for(const std::string&k:keywords){ if(nstr==k){ diff --git a/tests/test.cpp b/tests/test.cpp index 295ac66..d4dc5dd 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -3,5 +3,6 @@ int main(int argc,char *argv[]){ + ztl::isDebug=true; ztl::runCodeFromPath("/root/dev/cpp/TudorLang/tests/main.ztl"); } \ No newline at end of file