forked from xxq250/Nasal-Interpreter
Add one-operator +-! & add new element in ast_node
This commit is contained in:
+42
-1
@@ -6,6 +6,7 @@ class abstract_syntax_tree
|
||||
protected:
|
||||
int ast_node_type;
|
||||
std::list<abstract_syntax_tree> statement_list;
|
||||
std::list<abstract_syntax_tree> children;
|
||||
double var_number;
|
||||
std::string var_string;
|
||||
public:
|
||||
@@ -13,25 +14,65 @@ class abstract_syntax_tree
|
||||
{
|
||||
ast_node_type=__root;
|
||||
statement_list.clear();
|
||||
children.clear();
|
||||
var_number=0;
|
||||
var_string="";
|
||||
}
|
||||
abstract_syntax_tree(const abstract_syntax_tree& temp)
|
||||
{
|
||||
ast_node_type=temp.ast_node_type;
|
||||
statement_list=temp.statement_list;
|
||||
if(temp.statement_list.empty())
|
||||
statement_list.clear();
|
||||
else
|
||||
statement_list=temp.statement_list;
|
||||
if(temp.children.empty())
|
||||
children.clear();
|
||||
else
|
||||
children=temp.children;
|
||||
var_number=temp.var_number;
|
||||
var_string=temp.var_string;
|
||||
}
|
||||
// for statement block
|
||||
void set_block()
|
||||
{
|
||||
ast_node_type=__block;
|
||||
return;
|
||||
}
|
||||
void add_statement(abstract_syntax_tree statement_head)
|
||||
{
|
||||
statement_list.push_back(statement_head);
|
||||
return;
|
||||
}
|
||||
// for sub-tree node operator
|
||||
void set_two_operator(const int operator_type,abstract_syntax_tree f_child,abstract_syntax_tree s_child)
|
||||
{
|
||||
ast_node_type=operator_type;
|
||||
children.push_back(f_child);
|
||||
children.push_back(s_child);
|
||||
return;
|
||||
}
|
||||
void set_one_operator(const int operator_type,abstract_syntax_tree f_child)
|
||||
{
|
||||
ast_node_type=operator_type;
|
||||
children.push_back(f_child);
|
||||
return;
|
||||
}
|
||||
// for leaf node string
|
||||
void set_node_to_string(std::string& str)
|
||||
{
|
||||
ast_node_type=__string;
|
||||
var_string=str;
|
||||
return;
|
||||
}
|
||||
// for leaf node number
|
||||
void set_node_to_number(std::string& str)
|
||||
{
|
||||
ast_node_type=__number;
|
||||
if(str=="nil")
|
||||
{
|
||||
var_number=0;
|
||||
return;
|
||||
}
|
||||
if((int)str.length()>2 && (str[1]=='x' || str[1]=='o'))
|
||||
{
|
||||
if(str[1]=='x')
|
||||
|
||||
Reference in New Issue
Block a user