This commit is contained in:
Valk Richard Li 2020-02-15 17:25:14 +08:00 committed by GitHub
parent e169ffc5ee
commit e9e5e1a3fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 6 deletions

View File

@ -106,7 +106,7 @@ void abstract_syntax_tree::print_tree_block(const int n)
for(int i=0;i<n;++i) for(int i=0;i<n;++i)
__str+="| "; __str+="| ";
std::cout<<__str; std::cout<<__str;
print_parse_token(node_type); print_ast_type(node_type);
switch(node_type) switch(node_type)
{ {
case __number: std::cout<<": "<<var_number;break; case __number: std::cout<<": "<<var_number;break;

View File

@ -22,7 +22,8 @@ void print_lexer_token(int type)
return; return;
} }
enum parse_token_type // parse_gen_type include enums for parser and ast
enum parse_gen_type
{ {
__stack_end=1, __stack_end=1,
__cmp_equal,__cmp_not_equal,__cmp_less,__cmp_less_or_equal,__cmp_more,__cmp_more_or_equal, __cmp_equal,__cmp_not_equal,__cmp_less,__cmp_less_or_equal,__cmp_more,__cmp_more_or_equal,
@ -125,6 +126,60 @@ void print_parse_token(int type)
case __number: context="num"; break; case __number: context="num"; break;
case __string: context="str"; break; case __string: context="str"; break;
default: context="undefined"; break;
}
std::cout<<context;
return;
}
void print_ast_type(int type)
{
std::string context="";
switch(type)
{
case __cmp_equal: context=" == "; break;
case __cmp_not_equal: context=" != "; break;
case __cmp_less: context=" < "; break;
case __cmp_less_or_equal: context=" <= "; break;
case __cmp_more: context=" > "; break;
case __cmp_more_or_equal: context=" >= "; break;
case __and_operator: context=" and ";break;
case __or_operator: context=" or "; break;
case __nor_operator: context=" ! "; break;
case __add_operator: context=" + "; break;
case __sub_operator: context=" - "; break;
case __mul_operator: context=" * "; break;
case __div_operator: context=" / "; break;
case __link_operator: context=" ~ "; break;
case __equal: context=" = "; break;
case __add_equal: context=" += "; break;
case __sub_equal: context=" -= "; break;
case __mul_equal: context=" *= "; break;
case __div_equal: context=" /= "; break;
case __link_equal: context=" ~= "; break;
case __ques_mark: context="?"; break;
case __var: context="var "; break;
case __func: context="func "; break;
case __continue: context="continue"; break;
case __break: context="break"; break;
case __for: context="for"; break;
case __forindex: context="forindex"; break;
case __foreach: context="foreach "; break;
case __while: context="while"; break;
case __if: context="if "; break;
case __elsif: context="elsif "; break;
case __else: context="else "; break;
case __return: context="return "; break;
case __nil: context="nil"; break;
case __id: context="id"; break;
case __dynamic_id: context="id..."; break;
case __number: context="num"; break;
case __string: context="str"; break;
case __root: context="root"; break; case __root: context="root"; break;
case __null_type: context="null_type"; break; case __null_type: context="null_type"; break;
case __multi_id: context="ids"; break; case __multi_id: context="ids"; break;
@ -323,8 +378,8 @@ void print_parse_error(int error_type,int line,int error_token_type=__stack_end)
enum scalar_type enum scalar_type
{ {
scalar_nil, scalar_nil=0,
scalar_number=1, scalar_number,
scalar_string, scalar_string,
scalar_vector, scalar_vector,
scalar_hash, scalar_hash,
@ -345,5 +400,4 @@ void print_scalar_type(const int type)
return; return;
} }
#endif #endif

View File

@ -102,7 +102,6 @@ void nasal_parse::print_detail_token()
std::cout<<std::endl<<line<<"\t"<<indent; std::cout<<std::endl<<line<<"\t"<<indent;
} }
print_parse_token(tmp.top().type); print_parse_token(tmp.top().type);
if(tmp.top().type==__left_brace) if(tmp.top().type==__left_brace)
indent+=' '; indent+=' ';
tmp.pop(); tmp.pop();

View File

@ -25,6 +25,7 @@ class sym_hash_map
for(std::map<std::string,int>::iterator i=sym_map.begin();i!=sym_map.end();++i) for(std::map<std::string,int>::iterator i=sym_map.begin();i!=sym_map.end();++i)
nasal_gc.reference_delete(i->second); nasal_gc.reference_delete(i->second);
sym_map.clear(); sym_map.clear();
nasal_gc.gc_scanner();
return; return;
} }
void set_clear() void set_clear()