Skip to content

Commit ae25fb7

Browse files
committed
chore(ast): ast recursive descent method definitions
1 parent 112eaff commit ae25fb7

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

roxas/ast.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ Abstract_Syntax_Tree::Abstract_Syntax_Tree(std::string_view parse_tree)
3535
* @return ast_type the AST data structure
3636
*/
3737

38-
const Abstract_Syntax_Tree::ast_type& Abstract_Syntax_Tree::get_ast()
38+
const Abstract_Syntax_Tree::ast_type&
39+
Abstract_Syntax_Tree::get_ast_definitions() const
3940
{
4041
return ast_;
4142
}

roxas/ast.h

+31-14
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,22 @@ namespace roxas {
3030

3131
namespace ast {
3232

33-
class node;
3433
struct definition;
34+
class node;
35+
class expression_node;
36+
class statement_node;
3537
class lvalue_node;
3638
class rvalue_node;
37-
class expression_node;
39+
40+
enum class literal : int
41+
{
42+
Number,
43+
Constant,
44+
String,
45+
Unknown
46+
};
47+
48+
using literal_node = std::tuple<literal, std::string>;
3849

3950
} // namespace ast
4051

@@ -44,6 +55,9 @@ class expression_node;
4455
* The AST object that holds a representation of a parse tree from
4556
* the ParseTreeModuleLoader object suitable to construct a B program.
4657
*
58+
* Constructs child nodes with recursive descent on ast data types,
59+
* prepares data for future compiler passes.
60+
*
4761
*/
4862
class Abstract_Syntax_Tree
4963
{
@@ -68,7 +82,19 @@ class Abstract_Syntax_Tree
6882
*
6983
* @return ast_type the AST data structure
7084
*/
71-
const ast_type& get_ast();
85+
const ast_type& get_ast_definitions() const;
86+
87+
private:
88+
ast::definition construct_definition_ast_();
89+
ast::statement_node construct_statement_node_();
90+
ast::expression_node construct_expression_node_();
91+
92+
private:
93+
ast::lvalue_node construct_lvalue_node_();
94+
ast::rvalue_node construct_rvalue_node_();
95+
96+
private:
97+
ast::literal_node construct_constant_ast_();
7298

7399
private:
74100
std::string_view parse_tree_;
@@ -86,14 +112,6 @@ struct overload : Ts...
86112
template<class... Ts>
87113
overload(Ts...) -> overload<Ts...>;
88114

89-
enum class literal : int
90-
{
91-
Number,
92-
Constant,
93-
String,
94-
Unknown
95-
};
96-
97115
/**
98116
* @brief A representation of a Definition (vector or function) in the B
99117
* language
@@ -113,8 +131,6 @@ struct definition
113131
std::vector<ptr> children{};
114132
};
115133

116-
using literal_type = std::tuple<literal, std::string>;
117-
118134
/**
119135
* @brief
120136
*
@@ -242,7 +258,7 @@ class statement_node final : public node
242258
public:
243259
using ptr = std::unique_ptr<statement_node>;
244260
using datatype = std::
245-
variant<std::monostate, std::string, expression_node, literal_type>;
261+
variant<std::monostate, std::string, expression_node, literal_node>;
246262
/**
247263
* @brief Construct a new statement node
248264
*
@@ -270,4 +286,5 @@ class statement_node final : public node
270286
};
271287

272288
} // namespace ast
289+
273290
} // namespace roxas

0 commit comments

Comments
 (0)