This commit is contained in:
Valk Richard Li 2020-12-14 00:10:31 +08:00
parent 09e5b3fa90
commit 73c9f98f4f
3 changed files with 77 additions and 230 deletions

View File

@ -97,7 +97,7 @@ private:
double num; double num;
std::vector<nasal_ast> children; std::vector<nasal_ast> children;
public: public:
nasal_ast(); nasal_ast(int,int);
nasal_ast(const nasal_ast&); nasal_ast(const nasal_ast&);
~nasal_ast(); ~nasal_ast();
nasal_ast& operator=(const nasal_ast&); nasal_ast& operator=(const nasal_ast&);
@ -115,10 +115,10 @@ public:
void print_ast(int); void print_ast(int);
}; };
nasal_ast::nasal_ast() nasal_ast::nasal_ast(int init_line=0,int init_type=ast_null)
{ {
this->line=0; this->line=init_line;
this->type=ast_null; this->type=init_type;
return; return;
} }

View File

@ -27,7 +27,7 @@ enum token_type
tok_colon,tok_add,tok_sub,tok_mult,tok_div,tok_link,tok_not, tok_colon,tok_add,tok_sub,tok_mult,tok_div,tok_link,tok_not,
tok_equal, tok_equal,
tok_add_equal,tok_sub_equal,tok_mult_equal,tok_div_equal,tok_link_equal, tok_add_equal,tok_sub_equal,tok_mult_equal,tok_div_equal,tok_link_equal,
tok_cmp_equal,tok_cmp_not_equal,tok_less_than,tok_greater_than,tok_less_equal,tok_greater_equal tok_cmp_equal,tok_cmp_not_equal,tok_less_than,tok_less_equal,tok_greater_than,tok_greater_equal
}; };
struct struct
@ -78,8 +78,8 @@ struct
{"==" ,tok_cmp_equal }, {"==" ,tok_cmp_equal },
{"!=" ,tok_cmp_not_equal}, {"!=" ,tok_cmp_not_equal},
{"<" ,tok_less_than }, {"<" ,tok_less_than },
{"<=" ,tok_less_equal },
{">" ,tok_greater_than }, {">" ,tok_greater_than },
{"<=" ,tok_less_equal },
{">=" ,tok_greater_equal}, {">=" ,tok_greater_equal},
{NULL ,-1 } {NULL ,-1 }
}; };

View File

@ -282,53 +282,40 @@ bool nasal_parse::need_semi_check(nasal_ast& node)
nasal_ast nasal_parse::null_node_gen() nasal_ast nasal_parse::null_node_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_null);
node.set_line(tok_list[ptr].line);
node.set_type(ast_null);
return node; return node;
} }
nasal_ast nasal_parse::nil_gen() nasal_ast nasal_parse::nil_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_nil);
if(ptr>=tok_list_size) return node;
node.set_line(tok_list[ptr].line);
node.set_type(ast_nil);
return node; return node;
} }
nasal_ast nasal_parse::number_gen() nasal_ast nasal_parse::number_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_number);
node.set_line(tok_list[ptr].line);
node.set_type(ast_number);
node.set_num(trans_string_to_number(tok_list[ptr].str)); node.set_num(trans_string_to_number(tok_list[ptr].str));
return node; return node;
} }
nasal_ast nasal_parse::string_gen() nasal_ast nasal_parse::string_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_string);
node.set_line(tok_list[ptr].line);
node.set_type(ast_string);
node.set_str(tok_list[ptr].str); node.set_str(tok_list[ptr].str);
return node; return node;
} }
nasal_ast nasal_parse::id_gen() nasal_ast nasal_parse::id_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_identifier);
node.set_line(tok_list[ptr].line);
node.set_type(ast_identifier);
node.set_str(tok_list[ptr].str); node.set_str(tok_list[ptr].str);
return node; return node;
} }
nasal_ast nasal_parse::vector_gen() nasal_ast nasal_parse::vector_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_vector);
node.set_line(tok_list[ptr].line);
node.set_type(ast_vector);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_bracket) while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_bracket)
{ {
@ -347,9 +334,7 @@ nasal_ast nasal_parse::vector_gen()
} }
nasal_ast nasal_parse::hash_gen() nasal_ast nasal_parse::hash_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_hash);
node.set_line(tok_list[ptr].line);
node.set_type(ast_hash);
++ptr; ++ptr;
while (ptr<tok_list_size && tok_list[ptr].type!=tok_right_brace) while (ptr<tok_list_size && tok_list[ptr].type!=tok_right_brace)
{ {
@ -384,17 +369,12 @@ nasal_ast nasal_parse::hash_member_gen()
return node; return node;
} }
++ptr; ++ptr;
if(ptr<tok_list_size) node.add_child(calculation());
node.add_child(calculation());
else
die(error_line,"expected scalar");
return node; return node;
} }
nasal_ast nasal_parse::func_gen() nasal_ast nasal_parse::func_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_function);
node.set_line(tok_list[ptr].line);
node.set_type(ast_function);
++ptr; ++ptr;
if(ptr>=tok_list_size) if(ptr>=tok_list_size)
{ {
@ -416,19 +396,12 @@ nasal_ast nasal_parse::func_gen()
nasal_ast null_argument_list; nasal_ast null_argument_list;
node.add_child(null_argument_list); node.add_child(null_argument_list);
} }
if(ptr>=tok_list_size)
{
die(error_line,"expected expression block");
return node;
}
node.add_child(exprs_gen()); node.add_child(exprs_gen());
return node; return node;
} }
nasal_ast nasal_parse::args_list_gen() nasal_ast nasal_parse::args_list_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_args);
node.set_line(tok_list[ptr].line);
node.set_type(ast_args);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve) while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve)
{ {
@ -442,13 +415,12 @@ nasal_ast nasal_parse::args_list_gen()
++ptr; ++ptr;
if(ptr<tok_list_size && (tok_list[ptr].type==tok_equal || tok_list[ptr].type==tok_ellipsis)) if(ptr<tok_list_size && (tok_list[ptr].type==tok_equal || tok_list[ptr].type==tok_ellipsis))
{ {
nasal_ast special_arg; nasal_ast special_arg(tok_list[ptr].line);
special_arg.set_line(tok_list[ptr].line);
if(tok_list[ptr].type==tok_equal) if(tok_list[ptr].type==tok_equal)
{ {
special_arg.add_child(tmp); special_arg.add_child(tmp);
++ptr; ++ptr;
special_arg.add_child(scalar()); special_arg.add_child(calculation());
special_arg.set_type(ast_default_arg); special_arg.set_type(ast_default_arg);
} }
else else
@ -487,12 +459,9 @@ nasal_ast nasal_parse::args_list_gen()
case ast_default_arg: args_format+="val=scalar";break; case ast_default_arg: args_format+="val=scalar";break;
case ast_dynamic_id: args_format+="val...";break; case ast_dynamic_id: args_format+="val...";break;
} }
if(i!=node_child_size-1) args_format+=",)"[i==node_child_size-1];
args_format+=",";
} }
args_format+=")"; bool checked_default_val=false,checked_dynamic_ids=false;
bool checked_default_val=false;
bool checked_dynamic_ids=false;
for(int i=0;i<node_child_size;++i) for(int i=0;i<node_child_size;++i)
{ {
if(node.get_children()[i].get_type()==ast_default_arg) if(node.get_children()[i].get_type()==ast_default_arg)
@ -500,16 +469,15 @@ nasal_ast nasal_parse::args_list_gen()
else if(node.get_children()[i].get_type()==ast_dynamic_id) else if(node.get_children()[i].get_type()==ast_dynamic_id)
checked_dynamic_ids=true; checked_dynamic_ids=true;
if(checked_default_val && node.get_children()[i].get_type()!=ast_default_arg) if(checked_default_val && node.get_children()[i].get_type()!=ast_default_arg)
die(error_line,"default argument must be the end of argument list: "+args_format); die(node.get_children()[i].get_line(),"default argument must be the end of argument list: "+args_format);
if(checked_dynamic_ids && i!=node_child_size-1) if(checked_dynamic_ids && i!=node_child_size-1)
die(error_line,"dynamic identifier must be the end of argument list: "+args_format); die(node.get_children()[i].get_line(),"dynamic identifier must be the end of argument list: "+args_format);
} }
std::map<std::string,bool> argname_table; std::map<std::string,bool> argname_table;
for(int i=0;i<node_child_size;++i) for(int i=0;i<node_child_size;++i)
{ {
int tmp_type=node.get_children()[i].get_type();
std::string new_name; std::string new_name;
switch(tmp_type) switch(node.get_children()[i].get_type())
{ {
case ast_dynamic_id: case ast_dynamic_id:
case ast_identifier:new_name=node.get_children()[i].get_str();break; case ast_identifier:new_name=node.get_children()[i].get_str();break;
@ -524,8 +492,7 @@ nasal_ast nasal_parse::args_list_gen()
} }
nasal_ast nasal_parse::expr() nasal_ast nasal_parse::expr()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line);
node.set_line(tok_list[ptr].line);
int tok_type=tok_list[ptr].type; int tok_type=tok_list[ptr].type;
if((tok_type==tok_break || tok_type==tok_continue) && !in_loop) if((tok_type==tok_break || tok_type==tok_continue) && !in_loop)
{ {
@ -547,25 +514,18 @@ nasal_ast nasal_parse::expr()
case tok_left_bracket: case tok_left_bracket:
case tok_left_brace: case tok_left_brace:
case tok_sub: case tok_sub:
case tok_not: node=calculation(); break; case tok_not: node=calculation(); break;
case tok_var: node=definition(); break; case tok_var: node=definition(); break;
case tok_left_curve: case tok_left_curve: node=(check_multi_definition()?definition():(check_multi_scalar()?multi_assgin():calculation()));break;
if(check_multi_definition())
node=definition();
else if(check_multi_scalar())
node=multi_assgin();
else
node=calculation();
break;
case tok_for: case tok_for:
case tok_forindex: case tok_forindex:
case tok_foreach: case tok_foreach:
case tok_while: node=loop(); break; case tok_while: node=loop(); break;
case tok_if: node=conditional(); break; case tok_if: node=conditional(); break;
case tok_continue: node=continue_expr(); break; case tok_continue: node=continue_expr(); break;
case tok_break: node=break_expr(); break; case tok_break: node=break_expr(); break;
case tok_return: node=return_expr(); break; case tok_return: node=return_expr(); break;
case tok_semi: --ptr; break; case tok_semi: --ptr; break;
default: die(error_line,"error token \""+tok_list[ptr].str+"\"");break; default: die(error_line,"error token \""+tok_list[ptr].str+"\"");break;
} }
return node; return node;
@ -635,17 +595,9 @@ nasal_ast nasal_parse::calculation()
if(ptr<tok_list_size && tok_list[ptr].type==tok_quesmark) if(ptr<tok_list_size && tok_list[ptr].type==tok_quesmark)
{ {
// trinocular calculation // trinocular calculation
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line,ast_trinocular);
tmp.set_line(tok_list[ptr].line);
tmp.set_type(ast_trinocular);
tmp.add_child(node); tmp.add_child(node);
++ptr; tmp.add_child(calculation());
if(ptr<tok_list_size) tmp.add_child(calculation());
else
{
die(error_line,"expected calculation");
return node;
}
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_colon) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_colon)
{ {
@ -653,23 +605,10 @@ nasal_ast nasal_parse::calculation()
return node; return node;
} }
++ptr; ++ptr;
if(ptr<tok_list_size) tmp.add_child(calculation());
tmp.add_child(calculation());
else
die(error_line,"expected calculation");
node=tmp; node=tmp;
} }
else if( else if(ptr<tok_list_size && tok_equal<=tok_list[ptr].type && tok_list[ptr].type<=tok_link_equal)
ptr<tok_list_size &&
(
tok_list[ptr].type==tok_equal ||
tok_list[ptr].type==tok_add_equal ||
tok_list[ptr].type==tok_sub_equal ||
tok_list[ptr].type==tok_mult_equal ||
tok_list[ptr].type==tok_div_equal ||
tok_list[ptr].type==tok_link_equal
)
)
{ {
// check the left expression to confirm it is available to get memory // check the left expression to confirm it is available to get memory
if(node.get_type()!=ast_call && node.get_type()!=ast_identifier) if(node.get_type()!=ast_call && node.get_type()!=ast_identifier)
@ -693,24 +632,11 @@ nasal_ast nasal_parse::calculation()
} }
} }
} }
// assignment // tok_equal~tok_link_equal is 37 to 42,ast_equal~ast_link_equal is 21~26
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_equal+ast_equal);
tmp.set_line(tok_list[ptr].line);
switch(tok_list[ptr].type)
{
case tok_equal: tmp.set_type(ast_equal); break;
case tok_add_equal: tmp.set_type(ast_add_equal); break;
case tok_sub_equal: tmp.set_type(ast_sub_equal); break;
case tok_mult_equal: tmp.set_type(ast_mult_equal); break;
case tok_div_equal: tmp.set_type(ast_div_equal); break;
case tok_link_equal: tmp.set_type(ast_link_equal); break;
}
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
if(ptr<tok_list_size) tmp.add_child(calculation());
tmp.add_child(calculation());
else
die(error_line,"expected calculation");
node=tmp; node=tmp;
} }
else --ptr; else --ptr;
@ -723,9 +649,7 @@ nasal_ast nasal_parse::or_expr()
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type==tok_or) while(ptr<tok_list_size && tok_list[ptr].type==tok_or)
{ {
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line,ast_or);
tmp.set_line(tok_list[ptr].line);
tmp.set_type(ast_or);
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr<tok_list_size)
@ -746,9 +670,7 @@ nasal_ast nasal_parse::and_expr()
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type==tok_and) while(ptr<tok_list_size && tok_list[ptr].type==tok_and)
{ {
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line,ast_and);
tmp.set_line(tok_list[ptr].line);
tmp.set_type(ast_and);
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr<tok_list_size)
@ -803,29 +725,10 @@ nasal_ast nasal_parse::cmp_expr()
nasal_ast node; nasal_ast node;
node=additive_expr(); node=additive_expr();
++ptr; ++ptr;
while( while(ptr<tok_list_size && tok_cmp_equal<=tok_list[ptr].type && tok_list[ptr].type<=tok_greater_equal)
ptr<tok_list_size &&
(
tok_list[ptr].type==tok_cmp_equal ||
tok_list[ptr].type==tok_cmp_not_equal ||
tok_list[ptr].type==tok_less_than ||
tok_list[ptr].type==tok_less_equal ||
tok_list[ptr].type==tok_greater_than ||
tok_list[ptr].type==tok_greater_equal
)
)
{ {
nasal_ast tmp; // tok_cmp_equal~tok_greater_equal is 43~48,ast_cmp_equal~ast_greater_equal is 27~32
tmp.set_line(tok_list[ptr].line); nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_cmp_equal+ast_cmp_equal);
switch(tok_list[ptr].type)
{
case tok_cmp_equal: tmp.set_type(ast_cmp_equal); break;
case tok_cmp_not_equal: tmp.set_type(ast_cmp_not_equal); break;
case tok_less_than: tmp.set_type(ast_less_than); break;
case tok_less_equal: tmp.set_type(ast_less_equal); break;
case tok_greater_than: tmp.set_type(ast_greater_than); break;
case tok_greater_equal: tmp.set_type(ast_greater_equal); break;
}
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr<tok_list_size)
@ -952,8 +855,7 @@ nasal_ast nasal_parse::additive_expr()
++ptr; ++ptr;
while(ptr<tok_list_size && (tok_list[ptr].type==tok_add || tok_list[ptr].type==tok_sub || tok_list[ptr].type==tok_link)) while(ptr<tok_list_size && (tok_list[ptr].type==tok_add || tok_list[ptr].type==tok_sub || tok_list[ptr].type==tok_link))
{ {
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line);
tmp.set_line(tok_list[ptr].line);
switch(tok_list[ptr].type) switch(tok_list[ptr].type)
{ {
case tok_add: tmp.set_type(ast_add); break; case tok_add: tmp.set_type(ast_add); break;
@ -1064,13 +966,7 @@ nasal_ast nasal_parse::multive_expr()
++ptr; ++ptr;
while(ptr<tok_list_size && (tok_list[ptr].type==tok_mult || tok_list[ptr].type==tok_div)) while(ptr<tok_list_size && (tok_list[ptr].type==tok_mult || tok_list[ptr].type==tok_div))
{ {
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_mult+ast_mult);
tmp.set_line(tok_list[ptr].line);
switch(tok_list[ptr].type)
{
case tok_mult:tmp.set_type(ast_mult);break;
case tok_div: tmp.set_type(ast_div); break;
}
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr<tok_list_size)
@ -1140,8 +1036,7 @@ nasal_ast nasal_parse::multive_expr()
} }
nasal_ast nasal_parse::unary() nasal_ast nasal_parse::unary()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line);
node.set_line(tok_list[ptr].line);
switch(tok_list[ptr].type) switch(tok_list[ptr].type)
{ {
case tok_sub:node.set_type(ast_unary_sub);break; case tok_sub:node.set_type(ast_unary_sub);break;
@ -1149,12 +1044,7 @@ nasal_ast nasal_parse::unary()
} }
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr<tok_list_size)
{ node.add_child((tok_list[ptr].type==tok_sub || tok_list[ptr].type==tok_not)?unary():scalar());
if(tok_list[ptr].type==tok_sub || tok_list[ptr].type==tok_not)
node.add_child(unary());
else
node.add_child(scalar());
}
else else
die(error_line,"expected calculation"); die(error_line,"expected calculation");
// pre-calculation // pre-calculation
@ -1204,8 +1094,7 @@ nasal_ast nasal_parse::unary()
} }
nasal_ast nasal_parse::scalar() nasal_ast nasal_parse::scalar()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line);
node.set_line(tok_list[ptr].line);
if(tok_list[ptr].type==tok_nil) if(tok_list[ptr].type==tok_nil)
node=nil_gen(); node=nil_gen();
else if(tok_list[ptr].type==tok_number) else if(tok_list[ptr].type==tok_number)
@ -1235,10 +1124,7 @@ nasal_ast nasal_parse::scalar()
else if(tok_list[ptr].type==tok_left_curve) else if(tok_list[ptr].type==tok_left_curve)
{ {
++ptr; ++ptr;
if(ptr<tok_list_size) node=calculation();
node=calculation();
else
die(error_line,"expected calculation");
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve)
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
@ -1278,9 +1164,7 @@ nasal_ast nasal_parse::call_scalar()
} }
nasal_ast nasal_parse::call_hash() nasal_ast nasal_parse::call_hash()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_call_hash);
node.set_line(tok_list[ptr].line);
node.set_type(ast_call_hash);
++ptr; ++ptr;
if(ptr<tok_list_size && tok_list[ptr].type==tok_identifier) if(ptr<tok_list_size && tok_list[ptr].type==tok_identifier)
node.set_str(tok_list[ptr].str); node.set_str(tok_list[ptr].str);
@ -1290,9 +1174,7 @@ nasal_ast nasal_parse::call_hash()
} }
nasal_ast nasal_parse::call_vector() nasal_ast nasal_parse::call_vector()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_call_vec);
node.set_line(tok_list[ptr].line);
node.set_type(ast_call_vec);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_bracket) while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_bracket)
{ {
@ -1311,9 +1193,7 @@ nasal_ast nasal_parse::call_vector()
} }
nasal_ast nasal_parse::call_func() nasal_ast nasal_parse::call_func()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_call_func);
node.set_line(tok_list[ptr].line);
node.set_type(ast_call_func);
bool special_call=check_special_call(); bool special_call=check_special_call();
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve) while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve)
@ -1343,22 +1223,19 @@ nasal_ast nasal_parse::subvec()
++ptr; ++ptr;
if(ptr<tok_list_size && tok_list[ptr].type==tok_colon) if(ptr<tok_list_size && tok_list[ptr].type==tok_colon)
{ {
nasal_ast tmp;
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr>=tok_list_size)
return node;
nasal_ast tmp(node.get_line(),ast_subvec);
tmp.add_child(node);
if(tok_list[ptr].type==tok_comma || tok_list[ptr].type==tok_right_bracket)
{ {
tmp.set_line(node.get_line()); --ptr;
tmp.set_type(ast_subvec); tmp.add_child(nil_gen());
tmp.add_child(node);
if(tok_list[ptr].type==tok_comma || tok_list[ptr].type==tok_right_bracket)
{
--ptr;
tmp.add_child(nil_gen());
}
else
tmp.add_child(calculation());
node=tmp;
} }
else
tmp.add_child(calculation());
node=tmp;
} }
else else
--ptr; --ptr;
@ -1366,9 +1243,7 @@ nasal_ast nasal_parse::subvec()
} }
nasal_ast nasal_parse::definition() nasal_ast nasal_parse::definition()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_definition);
node.set_line(tok_list[ptr].line);
node.set_type(ast_definition);
if(tok_list[ptr].type==tok_var) if(tok_list[ptr].type==tok_var)
{ {
++ptr; ++ptr;
@ -1469,9 +1344,7 @@ nasal_ast nasal_parse::multi_id()
nasal_ast nasal_parse::multi_scalar(bool check_call_memory) nasal_ast nasal_parse::multi_scalar(bool check_call_memory)
{ {
// if check_call_memory is true,we will check if value called here can reach a memory space // if check_call_memory is true,we will check if value called here can reach a memory space
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_multi_scalar);
node.set_line(tok_list[ptr].line);
node.set_type(ast_multi_scalar);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve) while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve)
{ {
@ -1493,9 +1366,7 @@ nasal_ast nasal_parse::multi_scalar(bool check_call_memory)
} }
nasal_ast nasal_parse::multi_assgin() nasal_ast nasal_parse::multi_assgin()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_multi_assign);
node.set_line(tok_list[ptr].line);
node.set_type(ast_multi_assign);
node.add_child(multi_scalar(true)); node.add_child(multi_scalar(true));
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal)
@ -1536,9 +1407,7 @@ nasal_ast nasal_parse::loop()
} }
nasal_ast nasal_parse::while_loop() nasal_ast nasal_parse::while_loop()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_while);
node.set_line(tok_list[ptr].line);
node.set_type(ast_while);
++ptr; ++ptr;
if(ptr<tok_list_size && tok_list[ptr].type==tok_left_curve) if(ptr<tok_list_size && tok_list[ptr].type==tok_left_curve)
{ {
@ -1562,9 +1431,7 @@ nasal_ast nasal_parse::while_loop()
} }
nasal_ast nasal_parse::for_loop() nasal_ast nasal_parse::for_loop()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_for);
node.set_line(tok_list[ptr].line);
node.set_type(ast_for);
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve)
{ {
@ -1586,14 +1453,7 @@ nasal_ast nasal_parse::for_loop()
else if(tok_list[ptr].type==tok_var) else if(tok_list[ptr].type==tok_var)
node.add_child(definition()); node.add_child(definition());
else if(tok_list[ptr].type==tok_left_curve) else if(tok_list[ptr].type==tok_left_curve)
{ node.add_child(check_multi_definition()?definition():(check_multi_scalar()?multi_assgin():calculation()));
if(check_multi_definition())
node.add_child(definition());
else if(check_multi_scalar())
node.add_child(multi_assgin());
else
node.add_child(calculation());
}
else else
node.add_child(calculation()); node.add_child(calculation());
++ptr; ++ptr;
@ -1648,8 +1508,7 @@ nasal_ast nasal_parse::for_loop()
} }
nasal_ast nasal_parse::forei_loop() nasal_ast nasal_parse::forei_loop()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line);
node.set_line(tok_list[ptr].line);
switch(tok_list[ptr].type) switch(tok_list[ptr].type)
{ {
case tok_forindex: node.set_type(ast_forindex);break; case tok_forindex: node.set_type(ast_forindex);break;
@ -1696,10 +1555,9 @@ nasal_ast nasal_parse::forei_loop()
nasal_ast nasal_parse::new_iter_gen() nasal_ast nasal_parse::new_iter_gen()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line);
if(tok_list[ptr].type==tok_var) if(tok_list[ptr].type==tok_var)
{ {
node.set_line(tok_list[ptr].line);
node.set_type(ast_new_iter); node.set_type(ast_new_iter);
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier)
@ -1711,7 +1569,6 @@ nasal_ast nasal_parse::new_iter_gen()
} }
else else
{ {
node.set_line(tok_list[ptr].line);
node.set_type(ast_call); node.set_type(ast_call);
node.add_child(id_gen()); node.add_child(id_gen());
++ptr; ++ptr;
@ -1727,12 +1584,8 @@ nasal_ast nasal_parse::new_iter_gen()
nasal_ast nasal_parse::conditional() nasal_ast nasal_parse::conditional()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_conditional);
nasal_ast tmp; nasal_ast tmp(tok_list[ptr].line,ast_if);
node.set_line(tok_list[ptr].line);
node.set_type(ast_conditional);
tmp.set_line(tok_list[ptr].line);
tmp.set_type(ast_if);
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve)
{ {
@ -1798,23 +1651,17 @@ nasal_ast nasal_parse::conditional()
} }
nasal_ast nasal_parse::continue_expr() nasal_ast nasal_parse::continue_expr()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_continue);
node.set_line(tok_list[ptr].line);
node.set_type(ast_continue);
return node; return node;
} }
nasal_ast nasal_parse::break_expr() nasal_ast nasal_parse::break_expr()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_break);
node.set_line(tok_list[ptr].line);
node.set_type(ast_break);
return node; return node;
} }
nasal_ast nasal_parse::return_expr() nasal_ast nasal_parse::return_expr()
{ {
nasal_ast node; nasal_ast node(tok_list[ptr].line,ast_return);
node.set_line(tok_list[ptr].line);
node.set_type(ast_return);
++ptr; ++ptr;
if(ptr<tok_list_size) if(ptr<tok_list_size)
{ {