This commit is contained in:
Zengtudor 2025-07-19 12:00:56 +08:00
parent 6c808d6e2e
commit 0d4f840154
3 changed files with 49 additions and 1 deletions

47
include/AST.hpp Normal file
View File

@ -0,0 +1,47 @@
#pragma once
#include "Lexer.hpp"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <variant>
#include <vector>
namespace ztl{
struct AST{
struct Literal{
using LiteralType = std::variant<int64_t>;
LiteralType value;
};
struct Identifier{
std::string name;
};
struct BinaryExpression{
enum OperatorType{
One,
Add
};
OperatorType Operator;
using LRType = std::variant<
Identifier,
std::unique_ptr<BinaryExpression>
>;
LRType left;
LRType right;
};
struct VariableDeclaration{
Identifier id;
BinaryExpression init;
};
struct BlockStatement{
using BodyType = std::vector<std::variant<VariableDeclaration>>;
BodyType body;
};
AST(const std::vector<Token> &tokens){
for(size_t i=0;i<tokens.size();i++){
}
}
};
}

View File

@ -75,7 +75,7 @@ namespace ztl{
}
size_t end = i+1;
std::string nstr = s.substr(begin,end-begin);
const static std::vector<std::string> keywords = {"int","print"};
const static std::vector<std::string> keywords = {"int"};
bool isKeywords = false;
for(const std::string&k:keywords){
if(nstr==k){

View File

@ -3,5 +3,6 @@
int main(int argc,char *argv[]){
ztl::isDebug=true;
ztl::runCodeFromPath("/root/dev/cpp/TudorLang/tests/main.ztl");
}