Fixed a bug.

This commit is contained in:
Valk Richard Li 2019-11-21 12:21:33 +08:00 committed by GitHub
parent 2e2c4a96cd
commit 4ddb74e4e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 1 deletions

View File

@ -71,6 +71,7 @@ class abstract_syntax_tree
case __number:std::cout<<": "<<number;break;
case __string:std::cout<<": "<<str;break;
case __id:
case __dynamic_id:
case __call_array:
case __call_hash:
case __call_function:std::cout<<": "<<name;break;

View File

@ -92,8 +92,14 @@ class resource_file
totalsource.clear();
return;
}
void clear_lib_code()
{
libsource.clear();
return;
}
void add_lib()
{
libsource.clear();
std::string lib_name;
lib_name="lib/math.nas";
if(access("lib/math.nas",0))

View File

@ -678,7 +678,15 @@ abstract_syntax_tree balloon_parse::func_generate()
temp.set_clear();
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.set_name(this_token.str);
if(this_token.type==__dynamic_id)
{
std::string tempstr="";
for(int i=0;i<this_token.str.length()-3;++i)
tempstr+=this_token.str[i];
temp.set_name(tempstr);
}
else
temp.set_name(this_token.str);
para.add_child(temp);
if(this_token.type==__dynamic_id)
{

View File

@ -40,6 +40,7 @@ int main()
break;
else if(command=="lexer")
{
prog.clear_lib_code(); // avoid print lib code
lex.scanner(prog.get_resource());
lex.print_token_list();
}
@ -51,6 +52,7 @@ int main()
}
else if(command=="parser")
{
prog.clear_lib_code(); // avoid print lib code
lex.scanner(prog.get_resource());
lex.generate_detail_token();
if(!lex.get_error())
@ -67,6 +69,7 @@ int main()
}
else if(command=="ast")
{
prog.clear_lib_code(); // avoid print lib code
lex.scanner(prog.get_resource());
lex.generate_detail_token();
if(!lex.get_error())