update
This commit is contained in:
parent
6c808d6e2e
commit
0d4f840154
47
include/AST.hpp
Normal file
47
include/AST.hpp
Normal 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++){
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@ -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){
|
||||
|
@ -3,5 +3,6 @@
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
ztl::isDebug=true;
|
||||
ztl::runCodeFromPath("/root/dev/cpp/TudorLang/tests/main.ztl");
|
||||
}
|
Loading…
Reference in New Issue
Block a user