@@ -30,11 +30,22 @@ namespace roxas {
30
30
31
31
namespace ast {
32
32
33
- class node ;
34
33
struct definition ;
34
+ class node ;
35
+ class expression_node ;
36
+ class statement_node ;
35
37
class lvalue_node ;
36
38
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>;
38
49
39
50
} // namespace ast
40
51
@@ -44,6 +55,9 @@ class expression_node;
44
55
* The AST object that holds a representation of a parse tree from
45
56
* the ParseTreeModuleLoader object suitable to construct a B program.
46
57
*
58
+ * Constructs child nodes with recursive descent on ast data types,
59
+ * prepares data for future compiler passes.
60
+ *
47
61
*/
48
62
class Abstract_Syntax_Tree
49
63
{
@@ -68,7 +82,19 @@ class Abstract_Syntax_Tree
68
82
*
69
83
* @return ast_type the AST data structure
70
84
*/
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_ ();
72
98
73
99
private:
74
100
std::string_view parse_tree_;
@@ -86,14 +112,6 @@ struct overload : Ts...
86
112
template <class ... Ts>
87
113
overload (Ts...) -> overload<Ts...>;
88
114
89
- enum class literal : int
90
- {
91
- Number,
92
- Constant,
93
- String,
94
- Unknown
95
- };
96
-
97
115
/* *
98
116
* @brief A representation of a Definition (vector or function) in the B
99
117
* language
@@ -113,8 +131,6 @@ struct definition
113
131
std::vector<ptr> children{};
114
132
};
115
133
116
- using literal_type = std::tuple<literal, std::string>;
117
-
118
134
/* *
119
135
* @brief
120
136
*
@@ -242,7 +258,7 @@ class statement_node final : public node
242
258
public:
243
259
using ptr = std::unique_ptr<statement_node>;
244
260
using datatype = std::
245
- variant<std::monostate, std::string, expression_node, literal_type >;
261
+ variant<std::monostate, std::string, expression_node, literal_node >;
246
262
/* *
247
263
* @brief Construct a new statement node
248
264
*
@@ -270,4 +286,5 @@ class statement_node final : public node
270
286
};
271
287
272
288
} // namespace ast
289
+
273
290
} // namespace roxas
0 commit comments