finish value search

This commit is contained in:
Valk Richard Li 2019-11-13 23:37:32 +08:00 committed by GitHub
parent d3d162a83f
commit 0fe904deeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 153 additions and 40 deletions

View File

@ -27,6 +27,22 @@ var abstract_syntax_tree::calculation()
temp=this->call_identifier();
return temp;
}
else if(this->type==__array)
{
temp=this->array_generation();
return temp;
}
else if(this->type==__hash)
{
temp=this->hash_generation();
return temp;
}
else if(this->type==__function)
{
temp.set_type(__function);
temp.set_function(*this);
return temp;
}
if(this->type==__nor_operator)
{
temp.set_type(__var_number);
@ -34,7 +50,7 @@ var abstract_syntax_tree::calculation()
if(temp.get_type()!=__var_number)
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to use \'!\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to use \'!\' but use \'";
print_scalar(temp.get_type());
std::cout<<"\'."<<std::endl;
}
@ -57,7 +73,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to use \'+\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to use \'+\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -77,7 +93,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to use \'-\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to use \'-\' but use \'";
print_scalar(temp.get_type());
std::cout<<"\'."<<std::endl;
}
@ -91,7 +107,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to use \'-\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to use \'-\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -109,7 +125,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to use \'*\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to use \'*\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -127,13 +143,13 @@ var abstract_syntax_tree::calculation()
if(std::isnan(temp.get_number()) || std::isinf(temp.get_number()))
{
exit_type=__sigfpe_arithmetic_exception;
std::cout<<">>[Runtime-error] get number \'NaN\' or \'Inf\'."<<std::endl;
std::cout<<">>[Runtime-error] line "<<line<<": get number \'NaN\' or \'Inf\'."<<std::endl;
}
}
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to use \'/\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to use \'/\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -150,7 +166,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a string to use \'~\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a string to use \'~\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -171,7 +187,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use number or string to use \'==\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use number or string to use \'==\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\'."<<std::endl;
}
@ -179,7 +195,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'==\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'==\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -200,7 +216,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use number or string to use \'!=\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use number or string to use \'!=\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\'."<<std::endl;
}
@ -208,7 +224,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'!=\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'!=\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -229,7 +245,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use number or string to use \'<\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use number or string to use \'<\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\'."<<std::endl;
}
@ -237,7 +253,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'<\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'<\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -258,7 +274,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use number or string to use \'>\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use number or string to use \'>\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\'."<<std::endl;
}
@ -266,7 +282,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'>\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'>\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -287,7 +303,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use number or string to use \'<=\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use number or string to use \'<=\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\'."<<std::endl;
}
@ -295,7 +311,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'<=\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'<=\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -316,7 +332,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use number or string to use \'>=\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use number or string to use \'>=\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\'."<<std::endl;
}
@ -324,7 +340,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'>=\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'>=\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -341,7 +357,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'or\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'or\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -358,7 +374,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use same type to use \'and\' but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use same type to use \'and\' but use \'";
print_scalar(left_child.get_type());
std::cout<<"\' and \'";
print_scalar(right_child.get_type());
@ -368,7 +384,7 @@ var abstract_syntax_tree::calculation()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] error type occurred when doing calculation."<<std::endl;
std::cout<<">>[Runtime-error] line "<<line<<": error type occurred when doing calculation."<<std::endl;
}
return temp;
}
@ -385,7 +401,7 @@ bool abstract_syntax_tree::condition_check()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] must use a number to make a choice but use \'";
std::cout<<">>[Runtime-error] line "<<line<<": must use a number to make a choice but use \'";
print_scalar(temp.get_type());
std::cout<<"\'."<<std::endl;
}
@ -400,7 +416,7 @@ var abstract_syntax_tree::call_identifier()
temp=scope.get_var(name);
else
{
std::cout<<">>[Runtime-error] cannot find a var named \'"<<name<<"\'."<<std::endl;
std::cout<<">>[Runtime-error] line "<<line<<": cannot find a var named \'"<<name<<"\'."<<std::endl;
exit_type=__find_var_failure;
return temp;
}
@ -416,9 +432,9 @@ var abstract_syntax_tree::call_identifier()
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] ";
std::cout<<">>[Runtime-error] line "<<line<<": ";
print_detail_token(i->type);
std::cout<<":incorrect type \'";
std::cout<<": incorrect type \'";
print_scalar(temp.get_type());
std::cout<<"\'."<<std::endl;
break;
@ -426,18 +442,22 @@ var abstract_syntax_tree::call_identifier()
}
else if(i->type==__call_hash && temp.get_type()==__var_hash)
{
temp=temp.get_hash_member(i->name);
if(temp.get_type()==__null_type)
{
exit_type=__get_value_failure;
std::cout<<">>[Runtime-error] line "<<line<<": cannot find a hash-member named \'"<<i->name<<"\'."<<std::endl;
break;
}
}
else if(i->type==__call_function && temp.get_type()==__var_function)
{
}
temp=temp.get_function().run_func();
else
{
exit_type=__error_value_type;
std::cout<<">>[Runtime-error] ";
std::cout<<">>[Runtime-error] line "<<line<<": ";
print_detail_token(i->type);
std::cout<<":incorrect type \'";
std::cout<<": incorrect type \'";
print_scalar(temp.get_type());
std::cout<<"\'."<<std::endl;
}
@ -446,6 +466,31 @@ var abstract_syntax_tree::call_identifier()
return temp;
}
var abstract_syntax_tree::array_generation()
{
var new_var;
new_var.set_type(__var_array);
if(!children.empty())
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
new_var.append_array(i->calculation());
return new_var;
}
var abstract_syntax_tree::hash_generation()
{
var new_var;
new_var.set_type(__var_hash);
if(!children.empty())
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
{
var temp;
temp=i->children.front().calculation();
temp.set_name(i->name);
new_var.append_hash(temp);
}
return new_var;
}
var abstract_syntax_tree::get_value()
{
var temp;
@ -479,7 +524,7 @@ var abstract_syntax_tree::get_value()
temp.set_function(*this);
else
{
std::cout<<">>[Runtime-error] incorrect value."<<std::endl;
std::cout<<">>[Runtime-error] line "<<line<<": incorrect value."<<std::endl;
exit_type=__get_value_failure;
}
return temp;
@ -490,6 +535,7 @@ void abstract_syntax_tree::run_root()
scope.set_clear();
int beg_time,end_time;
exit_type=__process_exited_successfully;
beg_time=time(NULL);
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
{
@ -508,7 +554,7 @@ void abstract_syntax_tree::run_root()
}
else
{
std::cout<<">>[Runtime-error] redeclaration of \'"<<_name<<"\'."<<std::endl;
std::cout<<">>[Runtime-error] line "<<line<<": redeclaration of \'"<<_name<<"\'."<<std::endl;
exit_type=__redeclaration;
break;
}
@ -578,6 +624,8 @@ int abstract_syntax_tree::run_loop()
ret=__return;
break;
}
if(exit_type!=__process_exited_successfully)
break;
}
scope.pop_last_local_scope();
return ret;
@ -637,7 +685,7 @@ int abstract_syntax_tree::run_block()
}
else
{
std::cout<<">>[Runtime-error] redeclaration of \'"<<_name<<"\'."<<std::endl;
std::cout<<">>[Runtime-error] line "<<line<<": redeclaration of \'"<<_name<<"\'."<<std::endl;
exit_type=__redeclaration;
}
}
@ -674,7 +722,7 @@ int abstract_syntax_tree::run_block()
return type;
else
{
std::cout<<"[Runtime-error] incorrect use of break/continue."<<std::endl;
std::cout<<"[Runtime-error] line "<<line<<": incorrect use of break/continue."<<std::endl;
exit_type=__error_command_use;
}
}

View File

@ -7,6 +7,7 @@ class abstract_syntax_tree
{
protected:
int type;
int line;
double number;
std::string str;
std::string name;
@ -15,6 +16,7 @@ class abstract_syntax_tree
abstract_syntax_tree()
{
type=0;
line=0;
number=0;
str="";
name="";
@ -24,6 +26,7 @@ class abstract_syntax_tree
abstract_syntax_tree(const abstract_syntax_tree& p)
{
type=p.type;
line=p.line;
number=p.number;
str=p.str;
name=p.name;
@ -38,6 +41,7 @@ class abstract_syntax_tree
abstract_syntax_tree& operator=(const abstract_syntax_tree& p)
{
type=p.type;
line=p.line;
number=p.number;
str=p.str;
name=p.name;
@ -48,6 +52,7 @@ class abstract_syntax_tree
void set_clear()
{
type=0;
line=0;
number=0;
str="";
name="";
@ -83,6 +88,11 @@ class abstract_syntax_tree
type=_type;
return;
}
void set_line(const int _line)
{
line=_line;
return;
}
void set_string(std::string _str)
{
str=_str;
@ -168,6 +178,10 @@ class abstract_syntax_tree
{
return type;
}
int get_line()
{
return line;
}
double get_number()
{
return number;
@ -187,6 +201,8 @@ class abstract_syntax_tree
var calculation();
bool condition_check();
var call_identifier();
var array_generation();
var hash_generation();
var get_value();
void run_root();
int run_loop();

View File

@ -116,6 +116,7 @@ abstract_syntax_tree balloon_parse::ret()
std::cout<<">>[Parse-error] line "<<this_token.line<<": must use \'return\' here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
get_token();
if(this_token.type==__semi)
parse.push(this_token);
@ -140,6 +141,8 @@ abstract_syntax_tree balloon_parse::choose()
std::cout<<">>[Parse-error] line "<<this_token.line<<": must use \'if\' when generating an if-else statement."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
temp.set_line(this_token.line);
get_token();
if(this_token.type!=__left_curve)
{
@ -172,6 +175,7 @@ abstract_syntax_tree balloon_parse::choose()
if(this_token.type==__if)// else if
{
temp.set_type(__elsif);
temp.set_line(this_token.line);
get_token();
if(this_token.type!=__left_curve)
{
@ -192,6 +196,7 @@ abstract_syntax_tree balloon_parse::choose()
else// real else
{
temp.set_type(__else);
temp.set_line(this_token.line);
parse.push(this_token);
temp.add_child(block());
break;
@ -201,6 +206,7 @@ abstract_syntax_tree balloon_parse::choose()
else if(this_token.type==__elsif)
{
temp.set_type(__elsif);
temp.set_line(this_token.line);
get_token();
if(this_token.type!=__left_curve)
{
@ -234,6 +240,7 @@ abstract_syntax_tree balloon_parse::loop()
std::cout<<">>[Parse-error] line "<<this_token.line<<": must use \'while\' when generating a loop."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
get_token();
if(this_token.type!=__left_curve)
{
@ -266,6 +273,8 @@ abstract_syntax_tree balloon_parse::definition()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a \'var\' here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
temp.set_line(this_token.line);
get_token();
if(this_token.type!=__id)
{
@ -299,6 +308,7 @@ abstract_syntax_tree balloon_parse::assignment()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect an operator for assignment here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
new_node.set_type(this_token.type);
new_node.add_child(scalar());
return new_node;
@ -315,6 +325,7 @@ abstract_syntax_tree balloon_parse::array_generate()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a \'[\' here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
while(1)
{
get_token();
@ -361,6 +372,7 @@ abstract_syntax_tree balloon_parse::hash_generate()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a \'{\' here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
get_token();
if(this_token.type!=__right_brace)
parse.push(this_token);
@ -375,6 +387,7 @@ abstract_syntax_tree balloon_parse::hash_generate()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect an identifier here."<<std::endl;
return new_node;
}
temp.set_line(this_token.line);
temp.set_name(this_token.str);
get_token();
if(this_token.type!=__colon)
@ -425,6 +438,7 @@ abstract_syntax_tree balloon_parse::check_number()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a number here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
new_node.set_number(this_token.str);
return new_node;
}
@ -440,6 +454,7 @@ abstract_syntax_tree balloon_parse::check_string()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a string here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
new_node.set_string(this_token.str);
return new_node;
}
@ -454,6 +469,7 @@ abstract_syntax_tree balloon_parse::check_unary()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a unary operator here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
new_node.set_type(this_token.type);
get_token();
switch(this_token.type)
@ -480,6 +496,7 @@ abstract_syntax_tree balloon_parse::block()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a \'{\' ."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
while(1)
{
get_token();
@ -535,6 +552,8 @@ abstract_syntax_tree balloon_parse::func_generate()
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect a \'func\' here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
para.set_line(this_token.line);
get_token();
if(this_token.type==__left_curve)
{
@ -551,6 +570,7 @@ abstract_syntax_tree balloon_parse::func_generate()
return new_node;
}
temp.set_clear();
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.set_name(this_token.str);
para.add_child(temp);
@ -594,6 +614,7 @@ abstract_syntax_tree balloon_parse::call_identifier()
std::cout<<">>[Parse-error] line "<<this_token.line<<": must have an identifier here."<<std::endl;
return new_node;
}
new_node.set_line(this_token.line);
new_node.set_type(__id);
new_node.set_name(this_token.str);
while(1)
@ -602,6 +623,7 @@ abstract_syntax_tree balloon_parse::call_identifier()
if(this_token.type==__left_curve)
{
temp.set_clear();
temp.set_line(this_token.line);
temp.set_type(__call_function);
get_token();
if(this_token.type!=__right_curve)
@ -622,6 +644,7 @@ abstract_syntax_tree balloon_parse::call_identifier()
else if(this_token.type==__left_bracket)
{
temp.set_clear();
temp.set_line(this_token.line);
temp.set_type(__call_array);
temp.add_child(scalar());
get_token();
@ -635,9 +658,17 @@ abstract_syntax_tree balloon_parse::call_identifier()
}
else if(this_token.type==__dot)
{
get_token();
if(this_token.type!=__id)
{
++error;
std::cout<<">>[Parse-error] line "<<this_token.line<<": expect an identifier when calling hash."<<std::endl;
return new_node;
}
temp.set_clear();
temp=call_identifier();
temp.set_line(this_token.line);
temp.set_type(__call_hash);
temp.set_name(this_token.str);
new_node.add_child(temp);
}
else
@ -654,6 +685,7 @@ abstract_syntax_tree balloon_parse::call_identifier()
parse.push(this_token);
temp=new_node;
new_node=assignment();
new_node.set_line(this_token.line);
new_node.get_children().push_front(temp);
}
else
@ -679,6 +711,7 @@ abstract_syntax_tree balloon_parse::calculation_or()
parse.push(this_token);
return new_node;
}
temp.set_line(this_token.line);
temp.set_type(__or_operator);
temp.add_child(new_node);
while(1)
@ -692,6 +725,7 @@ abstract_syntax_tree balloon_parse::calculation_or()
parse.push(this_token);
break;
}
temp.set_line(this_token.line);
temp.set_type(__or_operator);
temp.add_child(new_node);
}
@ -709,6 +743,7 @@ abstract_syntax_tree balloon_parse::calculation_and()
parse.push(this_token);
return new_node;
}
temp.set_line(this_token.line);
temp.set_type(__and_operator);
temp.add_child(new_node);
while(1)
@ -722,6 +757,7 @@ abstract_syntax_tree balloon_parse::calculation_and()
parse.push(this_token);
break;
}
temp.set_line(this_token.line);
temp.set_type(__and_operator);
temp.add_child(new_node);
}
@ -741,6 +777,7 @@ abstract_syntax_tree balloon_parse::calculation_cmp()
parse.push(this_token);
return new_node;
}
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.add_child(new_node);
while(1)
@ -756,6 +793,7 @@ abstract_syntax_tree balloon_parse::calculation_cmp()
parse.push(this_token);
break;
}
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.add_child(new_node);
}
@ -773,6 +811,7 @@ abstract_syntax_tree balloon_parse::calculation_additive()
parse.push(this_token);
return new_node;
}
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.add_child(new_node);
while(1)
@ -786,6 +825,7 @@ abstract_syntax_tree balloon_parse::calculation_additive()
parse.push(this_token);
break;
}
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.add_child(new_node);
}
@ -797,6 +837,7 @@ abstract_syntax_tree balloon_parse::calculation_multive()
abstract_syntax_tree new_node;
abstract_syntax_tree temp;
get_token();
new_node.set_line(this_token.line);
switch(this_token.type)
{
case __left_curve:
@ -819,12 +860,14 @@ abstract_syntax_tree balloon_parse::calculation_multive()
return new_node;
break;
}
get_token();
if(this_token.type!=__mul_operator && this_token.type!=__div_operator)
{
parse.push(this_token);
return new_node;
}
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.add_child(new_node);
while(1)
@ -860,6 +903,7 @@ abstract_syntax_tree balloon_parse::calculation_multive()
parse.push(this_token);
break;
}
temp.set_line(this_token.line);
temp.set_type(this_token.type);
temp.add_child(new_node);
}
@ -870,6 +914,7 @@ abstract_syntax_tree balloon_parse::scalar()
{
abstract_syntax_tree new_node;
get_token();
new_node.set_line(this_token.line);
switch(this_token.type)
{
case __func:parse.push(this_token);new_node=func_generate();break;
@ -905,6 +950,7 @@ void balloon_parse::parse_main()
{
root.set_clear();
root.set_type(__root);
root.set_line(1);
error=0;
warning=0;

View File

@ -48,7 +48,7 @@ class balloon_scope
global.push_back(t);
return;
}
var& get_var(std::string name)
var get_var(std::string name)
{
if(!scope_list.empty())
{

View File

@ -147,7 +147,8 @@ enum runtime_error_type
__error_value_type,
__error_command_use,
__sigfpe_arithmetic_exception,
__sigsegv_segmentation_error
__sigsegv_segmentation_error,
__terminal_interrupt
};
void print_exit_type(int type)
@ -163,6 +164,7 @@ void print_exit_type(int type)
case __error_command_use: context="command_use_error(continue/break/return)";break;
case __sigfpe_arithmetic_exception: context="SIGFPE";break;
case __sigsegv_segmentation_error: context="SIGSEGV";break;
case __terminal_interrupt: context="interrupt";break;
default: context="unknown";break;
}
std::cout<<context;

View File

@ -41,6 +41,7 @@ class var
public:
var()
{
type=__null_type;
number=0;
str="";
name="";