update
This commit is contained in:
parent
eb66bbee20
commit
150135a733
|
@ -111,7 +111,7 @@ while_loop::=
|
||||||
while '(' calculation ')' expressions
|
while '(' calculation ')' expressions
|
||||||
;
|
;
|
||||||
for_loop::=
|
for_loop::=
|
||||||
for '(' [definition] ';' [calculation] ';' [calculation] ')' expressions
|
for '(' [definition|calculation] ';' [calculation] ';' [calculation] ')' expressions
|
||||||
;
|
;
|
||||||
forei_loop::=
|
forei_loop::=
|
||||||
(forindex | foreach) '(' (definition | assignment) ';' calculation ')' expressions
|
(forindex | foreach) '(' (definition | assignment) ';' calculation ')' expressions
|
||||||
|
|
|
@ -52,6 +52,7 @@ enum parse_error
|
||||||
lack_scalar,
|
lack_scalar,
|
||||||
lack_identifier,
|
lack_identifier,
|
||||||
lack_calculation,
|
lack_calculation,
|
||||||
|
lack_token,
|
||||||
};
|
};
|
||||||
|
|
||||||
void error_info(int line,int error_type,std::string error_str="")
|
void error_info(int line,int error_type,std::string error_str="")
|
||||||
|
@ -74,6 +75,7 @@ void error_info(int line,int error_type,std::string error_str="")
|
||||||
case lack_scalar: detail="expected scalar here."; break;
|
case lack_scalar: detail="expected scalar here."; break;
|
||||||
case lack_identifier: detail="expected identifier here."; break;
|
case lack_identifier: detail="expected identifier here."; break;
|
||||||
case lack_calculation: detail="expected arithmetic-expression here."; break;
|
case lack_calculation: detail="expected arithmetic-expression here."; break;
|
||||||
|
case lack_token: detail="expected \'"+error_str+"\' here."; break;
|
||||||
}
|
}
|
||||||
std::cout<<detail<<std::endl;
|
std::cout<<detail<<std::endl;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -738,6 +738,12 @@ nasal_ast nasal_parse::multi_assgin()
|
||||||
nasal_ast nasal_parse::loop()
|
nasal_ast nasal_parse::loop()
|
||||||
{
|
{
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
|
if(ptr>tok_list_size)
|
||||||
|
{
|
||||||
|
++error;
|
||||||
|
error_info(tok_list.back().line,lack_token,"loop");
|
||||||
|
return node;
|
||||||
|
}
|
||||||
switch(tok_list[ptr].type)
|
switch(tok_list[ptr].type)
|
||||||
{
|
{
|
||||||
case tok_while: node=while_loop(); break;
|
case tok_while: node=while_loop(); break;
|
||||||
|
@ -750,21 +756,68 @@ nasal_ast nasal_parse::loop()
|
||||||
nasal_ast nasal_parse::while_loop()
|
nasal_ast nasal_parse::while_loop()
|
||||||
{
|
{
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
|
node.set_line(tok_list[ptr].line);
|
||||||
|
node.set_type(ast_while);
|
||||||
|
++ptr;
|
||||||
|
if(ptr<tok_list_size && tok_list[ptr].type==tok_left_curve)
|
||||||
|
{
|
||||||
|
++ptr;
|
||||||
|
node.add_child(calculation());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++error;
|
||||||
|
error_info(node.get_line(),lack_left_curve);
|
||||||
|
}
|
||||||
|
++ptr;
|
||||||
|
if(ptr>tok_list_size || tok_list[ptr].type!=tok_right_curve)
|
||||||
|
{
|
||||||
|
++error;
|
||||||
|
error_info(node.get_line(),lack_right_curve);
|
||||||
|
}
|
||||||
|
++ptr;
|
||||||
|
node.add_child(exprs_gen());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::for_loop()
|
nasal_ast nasal_parse::for_loop()
|
||||||
{
|
{
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
|
node.set_line(tok_list[ptr].line);
|
||||||
|
node.set_type(ast_for);
|
||||||
|
++ptr;
|
||||||
|
if(ptr>tok_list_size || tok_list[ptr].type!=tok_left_curve)
|
||||||
|
{
|
||||||
|
++error;
|
||||||
|
error_info(node.get_line(),lack_left_curve);
|
||||||
|
}
|
||||||
|
++ptr;
|
||||||
|
// unfinished
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::forei_loop()
|
nasal_ast nasal_parse::forei_loop()
|
||||||
{
|
{
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
|
node.set_line(tok_list[ptr].line);
|
||||||
|
switch(tok_list[ptr].type)
|
||||||
|
{
|
||||||
|
case tok_forindex: node.set_type(ast_forindex);break;
|
||||||
|
case tok_foreach: node.set_type(ast_foreach); break;
|
||||||
|
}
|
||||||
|
++ptr;
|
||||||
|
if(ptr>tok_list_size || tok_list[ptr].type!=tok_left_curve)
|
||||||
|
{
|
||||||
|
++error;
|
||||||
|
error_info(node.get_line(),lack_left_curve);
|
||||||
|
}
|
||||||
|
++ptr;
|
||||||
|
// unfinished
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::conditional()
|
nasal_ast nasal_parse::conditional()
|
||||||
{
|
{
|
||||||
nasal_ast node;
|
nasal_ast node;
|
||||||
|
node.set_line(tok_list[ptr].line);
|
||||||
|
node.set_type(ast_if);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
nasal_ast nasal_parse::continue_expr()
|
nasal_ast nasal_parse::continue_expr()
|
||||||
|
|
Loading…
Reference in New Issue