Update
This commit is contained in:
parent
ed8a26494d
commit
bf2929d71f
|
@ -43,20 +43,25 @@ class ast_tree_node
|
||||||
{
|
{
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
virtual void print_all_tree()
|
virtual void print_all_tree(int tabnum=0)
|
||||||
{
|
{
|
||||||
|
for(int i=0;i<tabnum;++i)
|
||||||
|
std::cout<<" ";
|
||||||
if(type==__number)
|
if(type==__number)
|
||||||
{
|
{
|
||||||
std::cout<<"( num )";
|
std::cout<<"[ number ]"<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cout<<"( ";
|
std::cout<<"{ ";
|
||||||
print_token(type);
|
print_token(type);
|
||||||
|
std::cout<<std::endl;
|
||||||
for(std::list<ast_tree_node>::iterator i=children.begin();i!=children.end();++i)
|
for(std::list<ast_tree_node>::iterator i=children.begin();i!=children.end();++i)
|
||||||
{
|
{
|
||||||
i->print_all_tree();
|
i->print_all_tree(tabnum+1);
|
||||||
}
|
}
|
||||||
std::cout<<" )";
|
for(int i=0;i<tabnum;++i)
|
||||||
|
std::cout<<" ";
|
||||||
|
std::cout<<"}"<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,6 +62,8 @@ class code_generator
|
||||||
}
|
}
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
root.return_list().clear();
|
||||||
|
bool iserror=false;
|
||||||
while(!parse.empty())
|
while(!parse.empty())
|
||||||
{
|
{
|
||||||
switch(parse.top().type)
|
switch(parse.top().type)
|
||||||
|
@ -69,7 +71,7 @@ class code_generator
|
||||||
case __number:number_generator();break;
|
case __number:number_generator();break;
|
||||||
case __add_operator:operator_generator();break;
|
case __add_operator:operator_generator();break;
|
||||||
case __sub_operator:operator_generator();break;
|
case __sub_operator:operator_generator();break;
|
||||||
default:std::cout<<">>[Error] line "<<parse.top().line<<" parse error.\n";break;
|
default:std::cout<<">>[Error] line "<<parse.top().line<<" parse error.\n";iserror=true;break;
|
||||||
}
|
}
|
||||||
parse.pop();
|
parse.pop();
|
||||||
}
|
}
|
||||||
|
@ -78,6 +80,8 @@ class code_generator
|
||||||
root.return_list().push_back(node_stack.top());
|
root.return_list().push_back(node_stack.top());
|
||||||
node_stack.pop();
|
node_stack.pop();
|
||||||
}
|
}
|
||||||
|
if(iserror)
|
||||||
|
return;
|
||||||
std::cout<<">>[Parse] 0 error(s)."<<std::endl;
|
std::cout<<">>[Parse] 0 error(s)."<<std::endl;
|
||||||
std::cout<<">>[Parse] Complete checking."<<std::endl;
|
std::cout<<">>[Parse] Complete checking."<<std::endl;
|
||||||
root.print_all_tree();
|
root.print_all_tree();
|
||||||
|
|
|
@ -18,6 +18,8 @@ class nasal_parser
|
||||||
public:
|
public:
|
||||||
void print_parser_stack()
|
void print_parser_stack()
|
||||||
{
|
{
|
||||||
|
if(parser.empty())
|
||||||
|
return;
|
||||||
int line=0;
|
int line=0;
|
||||||
std::stack<parse_unit> temp;
|
std::stack<parse_unit> temp;
|
||||||
while(!parser.empty())
|
while(!parser.empty())
|
||||||
|
|
Loading…
Reference in New Issue