add lexer, parser, and ast tree
This commit is contained in:
34
src/ast/call_expression_ast.h
Normal file
34
src/ast/call_expression_ast.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef OBELISK_AST_CALL_EXPRESSION_AST_H
|
||||
#define OBELISK_AST_CALL_EXPRESSION_AST_H
|
||||
|
||||
#include "ast/expression_ast.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
class CallExpressionAST : public ExpressionAST
|
||||
{
|
||||
private:
|
||||
std::string callee_;
|
||||
std::vector<std::unique_ptr<ExpressionAST>> args_;
|
||||
|
||||
std::string getCallee();
|
||||
void setCallee(std::string callee);
|
||||
|
||||
std::vector<std::unique_ptr<ExpressionAST>> getArgs();
|
||||
void setArgs(std::vector<std::unique_ptr<ExpressionAST>> args);
|
||||
|
||||
public:
|
||||
CallExpressionAST(const std::string &callee,
|
||||
std::vector<std::unique_ptr<ExpressionAST>> args) :
|
||||
callee_(callee),
|
||||
args_(std::move(args))
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
13
src/ast/expression_ast.h
Normal file
13
src/ast/expression_ast.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef OBELISK_AST_EXPRESSION_AST_H
|
||||
#define OBELISK_AST_EXPRESSION_AST_H
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
class ExpressionAST
|
||||
{
|
||||
public:
|
||||
virtual ~ExpressionAST() = default;
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
30
src/ast/function_ast.h
Normal file
30
src/ast/function_ast.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef OBELISK_AST_FUNCTION_AST_H
|
||||
#define OBELISK_AST_FUNCTION_AST_H
|
||||
|
||||
#include "ast/expression_ast.h"
|
||||
#include "ast/prototype_ast.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
class FunctionAST
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<PrototypeAST> prototype_;
|
||||
std::unique_ptr<ExpressionAST> body_;
|
||||
|
||||
std::unique_ptr<PrototypeAST> getPrototype();
|
||||
void setPrototype(std::unique_ptr<PrototypeAST> prototype);
|
||||
|
||||
public:
|
||||
FunctionAST(std::unique_ptr<PrototypeAST> prototype,
|
||||
std::unique_ptr<ExpressionAST> body) :
|
||||
prototype_(std::move(prototype)),
|
||||
body_(std::move(body))
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
8
src/ast/meson.build
Normal file
8
src/ast/meson.build
Normal file
@@ -0,0 +1,8 @@
|
||||
obelisk_ast_sources = files(
|
||||
'call_expression_ast.h',
|
||||
'expression_ast.h',
|
||||
'function_ast.h',
|
||||
'number_expression_ast.h',
|
||||
'prototype_ast.h',
|
||||
'variable_expression_ast.h'
|
||||
)
|
24
src/ast/number_expression_ast.h
Normal file
24
src/ast/number_expression_ast.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef OBELISK_AST_NUMBER_EXPRESSION_AST_H
|
||||
#define OBELISK_AST_NUMBER_EXPRESSION_AST_H
|
||||
|
||||
#include "ast/expression_ast.h"
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
class NumberExpressionAST : public ExpressionAST
|
||||
{
|
||||
private:
|
||||
double number_;
|
||||
|
||||
double getNumber();
|
||||
void setNumber(double number);
|
||||
|
||||
public:
|
||||
NumberExpressionAST(double number) :
|
||||
number_(number)
|
||||
{
|
||||
}
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
34
src/ast/prototype_ast.h
Normal file
34
src/ast/prototype_ast.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef OBELISK_AST_PROTOTYPE_AST_H
|
||||
#define OBELISK_AST_PROTOTYPE_AST_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
class PrototypeAST
|
||||
{
|
||||
private:
|
||||
std::string name_;
|
||||
std::vector<std::string> args_;
|
||||
|
||||
void setName(const std::string& name);
|
||||
std::vector<std::string> getArgs();
|
||||
void setArgs(std::vector<std::string> args);
|
||||
|
||||
public:
|
||||
PrototypeAST(const std::string& name,
|
||||
std::vector<std::string> args) :
|
||||
name_(name),
|
||||
args_(std::move(args))
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
};
|
||||
} //namespace obelisk
|
||||
|
||||
#endif
|
25
src/ast/variable_expression_ast.h
Normal file
25
src/ast/variable_expression_ast.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef OBELISK_AST_VARIABLE_EXPRESSION_AST_H
|
||||
#define OBELISK_AST_VARIABLE_EXPRESSION_AST_H
|
||||
|
||||
#include "ast/expression_ast.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
class VariableExpressionAST : public ExpressionAST
|
||||
{
|
||||
private:
|
||||
std::string name_;
|
||||
std::string getName();
|
||||
void setName(const std::string name);
|
||||
|
||||
public:
|
||||
VariableExpressionAST(const std::string &name) :
|
||||
name_(name)
|
||||
{
|
||||
}
|
||||
};
|
||||
} //namespace obelisk
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user