This commit is contained in:
Valk Richard Li 2019-09-09 12:52:55 +08:00 committed by GitHub
parent ed8a26494d
commit bf2929d71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -43,20 +43,25 @@ class ast_tree_node
{
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)
{
std::cout<<"( num )";
std::cout<<"[ number ]"<<std::endl;
return;
}
std::cout<<"( ";
std::cout<<"{ ";
print_token(type);
std::cout<<std::endl;
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;
}
};

View File

@ -62,6 +62,8 @@ class code_generator
}
void run()
{
root.return_list().clear();
bool iserror=false;
while(!parse.empty())
{
switch(parse.top().type)
@ -69,7 +71,7 @@ class code_generator
case __number:number_generator();break;
case __add_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();
}
@ -78,6 +80,8 @@ class code_generator
root.return_list().push_back(node_stack.top());
node_stack.pop();
}
if(iserror)
return;
std::cout<<">>[Parse] 0 error(s)."<<std::endl;
std::cout<<">>[Parse] Complete checking."<<std::endl;
root.print_all_tree();

View File

@ -18,6 +18,8 @@ class nasal_parser
public:
void print_parser_stack()
{
if(parser.empty())
return;
int line=0;
std::stack<parse_unit> temp;
while(!parser.empty())