Update
This commit is contained in:
parent
d4e32b80bd
commit
46c8b4ca58
|
@ -11,10 +11,12 @@ class nasal_parser
|
||||||
std::stack<ast_tree_node> node_cache;
|
std::stack<ast_tree_node> node_cache;
|
||||||
token this_token;
|
token this_token;
|
||||||
int error;
|
int error;
|
||||||
|
int warning;
|
||||||
public:
|
public:
|
||||||
nasal_parser()
|
nasal_parser()
|
||||||
{
|
{
|
||||||
error=0;
|
error=0;
|
||||||
|
warning=0;
|
||||||
this_token.type=0;
|
this_token.type=0;
|
||||||
}
|
}
|
||||||
void get_token()
|
void get_token()
|
||||||
|
@ -135,12 +137,18 @@ void nasal_parser::definition_expr()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get_token();
|
get_token();
|
||||||
if(this_token.type!=__equal)
|
if(this_token.type!=__equal && this_token.type!=__semi)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
std::cout<<">>[Error] line "<<this_token.line<<": must have a \'=\' after identifier."<<std::endl;
|
std::cout<<">>[Error] line "<<this_token.line<<": must have a \'=\' after identifier."<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if(this_token.type==__semi)
|
||||||
|
{
|
||||||
|
++warning;
|
||||||
|
std::cout<<">>[Warning] line "<<this_token.line<<": variable without initializing."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
get_token();
|
get_token();
|
||||||
switch(this_token.type)
|
switch(this_token.type)
|
||||||
{
|
{
|
||||||
|
@ -202,18 +210,19 @@ void nasal_parser::list_init_generator()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
get_token();
|
get_token();
|
||||||
if(this_token.type!=__comma)
|
if(this_token.type!=__comma && this_token.type!=__right_bracket && this_token.type!=__semi)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
std::cout<<">>[Error] line "<<this_token.line<<": expect a \',\'."<<std::endl;
|
std::cout<<">>[Error] line "<<this_token.line<<": expect a \',\' at this line."<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get_token();
|
else if(this_token.type!=__right_bracket)
|
||||||
|
get_token();
|
||||||
}
|
}
|
||||||
if(this_token.type==__semi)
|
if(this_token.type==__semi)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
std::cout<<">>[Error] line "<<this_token.line<<": expect a \']\'."<<std::endl;
|
std::cout<<">>[Error] line "<<this_token.line<<": expect a \']\' at this line."<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -252,13 +261,14 @@ void nasal_parser::hash_init_generator()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
get_token();
|
get_token();
|
||||||
if(this_token.type!=__comma)
|
if(this_token.type!=__comma && this_token.type!=__right_brace && this_token.type!=__semi)
|
||||||
{
|
{
|
||||||
++error;
|
++error;
|
||||||
std::cout<<">>[Error] line "<<this_token.line<<": expect a \',\'."<<std::endl;
|
std::cout<<">>[Error] line "<<this_token.line<<": expect a \',\'."<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get_token();
|
if(this_token.type!=__right_brace)
|
||||||
|
get_token();
|
||||||
}
|
}
|
||||||
if(this_token.type==__semi)
|
if(this_token.type==__semi)
|
||||||
{
|
{
|
||||||
|
@ -482,6 +492,7 @@ void nasal_parser::mul_div_expr()
|
||||||
void nasal_parser::parse_main_work()
|
void nasal_parser::parse_main_work()
|
||||||
{
|
{
|
||||||
error=0;
|
error=0;
|
||||||
|
warning=0;
|
||||||
while(!parse.empty())
|
while(!parse.empty())
|
||||||
{
|
{
|
||||||
get_token();
|
get_token();
|
||||||
|
@ -505,7 +516,7 @@ void nasal_parser::parse_main_work()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout<<">>[Parse] complete generation."<<error<<" error(s)."<<std::endl;
|
std::cout<<">>[Parse] complete generation."<<error<<" error(s),"<<warning<<" warning(s)."<<std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue