This commit is contained in:
Valk Richard Li 2020-07-13 03:05:02 -07:00 committed by GitHub
parent d28c9e2c31
commit f235c168ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 26 deletions

View File

@ -43,8 +43,10 @@ void del_func()
void lex_func() void lex_func()
{ {
lexer.scanner(resource.get_file()); lexer.scanner(resource.get_file());
if(!lexer.get_error()) lexer.print_token(); if(!lexer.get_error())
else std::cout<<">> [lexer] error occurred,stop.\n"; lexer.print_token();
else
std::cout<<">> [lexer] error occurred,stop.\n";
return; return;
} }
@ -55,9 +57,11 @@ void par_func()
{ {
parse.set_toklist(lexer.get_token_list()); parse.set_toklist(lexer.get_token_list());
parse.main_process(); parse.main_process();
if(parse.get_error()) std::cout<<">> [parse] error occurred,stop.\n"; if(parse.get_error())
std::cout<<">> [parse] error occurred,stop.\n";
} }
else std::cout<<">> [lexer] error occurred,stop.\n"; else
std::cout<<">> [lexer] error occurred,stop.\n";
return; return;
} }

View File

@ -34,7 +34,7 @@ enum ast_node
ast_for,ast_forindex,ast_foreach,ast_while, ast_for,ast_forindex,ast_foreach,ast_while,
ast_if,ast_elsif,ast_else, ast_if,ast_elsif,ast_else,
ast_multi_id,ast_multi_scalar, ast_multi_id,ast_multi_scalar,
ast_definition,ast_multi_assign,ast_calculation, ast_definition,ast_multi_assign,
ast_continue,ast_break,ast_return, ast_continue,ast_break,ast_return,
}; };

View File

@ -78,6 +78,9 @@ private:
nasal_ast call_func(); nasal_ast call_func();
nasal_ast subvec(); nasal_ast subvec();
nasal_ast definition(); nasal_ast definition();
nasal_ast normal_def();
nasal_ast var_incurve_def();
nasal_ast var_outcurve_def();
nasal_ast multi_id(); nasal_ast multi_id();
nasal_ast multi_scalar(); nasal_ast multi_scalar();
nasal_ast multi_assgin(); nasal_ast multi_assgin();
@ -198,7 +201,7 @@ bool nasal_parse::check_special_call()
int check_ptr=ptr+1; int check_ptr=ptr+1;
int curve_cnt=1; int curve_cnt=1;
bool ret=false; bool ret=false;
while(check_ptr<tok_list_size && curve_cnt && !ret) while(check_ptr<tok_list_size && curve_cnt)
{ {
switch(tok_list[check_ptr].type) switch(tok_list[check_ptr].type)
{ {
@ -210,6 +213,7 @@ bool nasal_parse::check_special_call()
ret=true; ret=true;
break; break;
} }
++check_ptr;
} }
return ret; return ret;
} }
@ -722,7 +726,10 @@ nasal_ast nasal_parse::scalar()
node.add_child(tmp); node.add_child(tmp);
} }
while(ptr<tok_list_size && (tok_list[ptr].type==tok_left_curve || tok_list[ptr].type==tok_left_bracket || tok_list[ptr].type==tok_dot)) while(ptr<tok_list_size && (tok_list[ptr].type==tok_left_curve || tok_list[ptr].type==tok_left_bracket || tok_list[ptr].type==tok_dot))
{
node.add_child(call_scalar()); node.add_child(call_scalar());
++ptr;
}
--ptr; --ptr;
return node; return node;
} }
@ -789,10 +796,11 @@ nasal_ast nasal_parse::call_func()
node.add_child(special_call?hash_member_gen():calculation()); node.add_child(special_call?hash_member_gen():calculation());
++ptr; ++ptr;
if(ptr<tok_list_size && tok_list[ptr].type==tok_comma) ++ptr; if(ptr<tok_list_size && tok_list[ptr].type==tok_comma) ++ptr;
else if(ptr>=tok_list_size || tok_list[ptr].type!=tok_comma || tok_list[ptr].type!=tok_right_curve) else if(ptr>=tok_list_size || (tok_list[ptr].type!=tok_comma && tok_list[ptr].type!=tok_right_curve))
{ {
++error; ++error;
error_info(error_line,lack_comma); error_info(error_line,lack_comma);
break;
} }
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve)
@ -841,28 +849,73 @@ nasal_ast nasal_parse::definition()
if(tok_list[ptr].type==tok_var) if(tok_list[ptr].type==tok_var)
{ {
++ptr; ++ptr;
// unfinished switch(tok_list[ptr].type)
{
case tok_identifier:node.add_child(normal_def()); break;
case tok_left_curve:node.add_child(var_outcurve_def()); break;
default:
++error;
error_info(error_line,lack_identifier);
return node;
}
} }
else if(tok_list[ptr].type==tok_left_curve) else if(tok_list[ptr].type==tok_left_curve)
node.add_child(var_incurve_def());
++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal)
{ {
++ptr; ++error;
node.add_child(multi_id()); error_info(error_line,lack_equal);
++ptr; return node;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) }
{ ++ptr;
++error; // unfinished
error_info(error_line,lack_right_curve); return node;
return node; }
} nasal_ast nasal_parse::normal_def()
++ptr; {
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal) nasal_ast node;
{ node.set_line(tok_list[ptr].line);
++error; node.set_str(tok_list[ptr].str);
error_info(error_line,lack_equal); node.set_type(ast_identifier);
return node; return node;
} }
++ptr; nasal_ast nasal_parse::var_incurve_def()
// unfinished {
nasal_ast node;
++ptr;// check_multi_definition will check the 'var'
++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier)
{
++error;
error_info(error_line,lack_identifier);
return node;
}
node=multi_id();
++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve)
{
++error;
error_info(error_line,lack_right_curve);
}
return node;
}
nasal_ast nasal_parse::var_outcurve_def()
{
nasal_ast node;
++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier)
{
++error;
error_info(error_line,lack_identifier);
return node;
}
node=multi_id();
++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve)
{
++error;
error_info(error_line,lack_right_curve);
} }
return node; return node;
} }