-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ast): initial ast and node definitions
- Loading branch information
1 parent
af835f9
commit 5ed004a
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
#include <roxas/ast.h> | ||
|
||
namespace roxas { | ||
|
||
namespace ast { | ||
|
||
node::node(std::string const& type) | ||
: type_(std::move(type)) | ||
, literal_({ literal::UNKNOWN, "unknown" }) | ||
, children_({}) | ||
{ | ||
} | ||
|
||
void node::print() | ||
{ | ||
std::cout << "node type: " << type_; | ||
} | ||
|
||
} // namespace ast | ||
|
||
} // namespace roxas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <string> | ||
#include <tuple> | ||
#include <vector> | ||
|
||
namespace roxas { | ||
|
||
namespace ast { | ||
|
||
class node; | ||
struct definition; | ||
|
||
} // namespace ast | ||
|
||
using AST = std::vector<ast::definition>; | ||
|
||
AST parse_tree_to_ast(std::string const& parse_tree); | ||
|
||
namespace ast { | ||
|
||
enum class literal : int | ||
{ | ||
NUMBER, | ||
CONSTANT, | ||
STRING, | ||
UNKNOWN | ||
}; | ||
|
||
using literal_datatype = std::tuple<literal, std::string>; | ||
|
||
struct definition | ||
{ | ||
enum class type : int | ||
{ | ||
FUNCTION, | ||
VECTOR | ||
}; | ||
|
||
type type{ type::FUNCTION }; | ||
std::vector<node> children{}; | ||
}; | ||
|
||
class node | ||
{ | ||
public: | ||
node(node const&) = delete; | ||
node& operator=(node const&) = delete; | ||
|
||
explicit node(std::string const& type); | ||
void print(); | ||
|
||
private: | ||
std::string type_; | ||
std::optional<literal_datatype> literal_; | ||
std::optional<std::vector<node>> children_; | ||
}; | ||
|
||
} // namespace ast | ||
} // namespace roxas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters