Fixed bugs in lexer & parser::loop

This commit is contained in:
Valk Richard Li
2019-10-24 15:14:42 +08:00
committed by GitHub
parent 6580014509
commit 9ae42db76c
2 changed files with 23 additions and 2 deletions
+10 -2
View File
@@ -81,17 +81,25 @@ class resource_programme_process
} }
memset(resource,0,sizeof(char)); memset(resource,0,sizeof(char));
int i=0; int i=0;
int instring=0;
bool findnote=false;// to find the note with # at the head of line. bool findnote=false;// to find the note with # at the head of line.
while(!fin.eof()) while(!fin.eof())
{ {
resource[i]=fin.get(); resource[i]=fin.get();
if(resource[i]=='\'' || resource[i]=='\"')
++instring;
if(resource[i]=='\n') if(resource[i]=='\n')
findnote=false; findnote=false;
//when meeting '\n' the findnote is set to false then the next statement can be executed. //when meeting '\n' the findnote is set to false then the next statement can be executed.
if(resource[i]!='#' && !findnote) if(resource[i]!='#' && !findnote)
++i; ++i;
else if(resource[i]=='#') else if(resource[i]=='#')
findnote=true; {
if(instring & 1)
++i;
else
findnote=true;
}
if(fin.eof()) if(fin.eof())
break; break;
} }
@@ -458,7 +466,7 @@ class nasal_lexer
else if((*i).content=="<=") else if((*i).content=="<=")
(*i).type=__cmp_less_or_equal; (*i).type=__cmp_less_or_equal;
} }
else if(((*i).content==";") || ((*i).content==",") || ((*i).content=="=") || ((*i).content==":") || ((*i).content==".") || ((*i).content=="?") || ((*i).content=="|") || ((*i).content=="%") || ((*i).content=="$") || ((*i).content=="`") || ((*i).content=="^") || ((*i).content=="@")) else if(((*i).content==";") || ((*i).content==",") || ((*i).content=="=") || ((*i).content==":") || ((*i).content==".") || ((*i).content=="?") || ((*i).content=="|") || ((*i).content=="&") || ((*i).content=="%") || ((*i).content=="$") || ((*i).content=="`") || ((*i).content=="^") || ((*i).content=="@"))
{ {
char c=(*i).content[0]; char c=(*i).content[0];
switch(c) switch(c)
+13
View File
@@ -958,6 +958,7 @@ abstract_syntax_tree nasal_parser::loop_expr()
node.add_child(definition_expr()); node.add_child(definition_expr());
break; break;
case __id: case __id:
parse.push(this_token);
node.add_child(calculation_expr()); node.add_child(calculation_expr());
break; break;
case __semi:parse.push(this_token);break; case __semi:parse.push(this_token);break;
@@ -1235,6 +1236,12 @@ abstract_syntax_tree nasal_parser::mul_div_operator_expr()
while(1) while(1)
{ {
get_token(); get_token();
if(this_token.type==__unknown_operator)
{
++error;
std::cout<<">>[Error] line "<<this_token.line<<": __unknown_operator."<<std::endl;
return node;
}
if(this_token.type!=__mul_operator && this_token.type!=__div_operator) if(this_token.type!=__mul_operator && this_token.type!=__div_operator)
{ {
parse.push(this_token); parse.push(this_token);
@@ -1666,6 +1673,12 @@ abstract_syntax_tree nasal_parser::identifier_call_expr()
case __dot: case __dot:
node=call_hash_expr(); node=call_hash_expr();
break; break;
case __unknown_operator:
node.set_node_type(__id);
++error;
std::cout<<">>[Error] line "<<this_token.line<<": __unknown_operator."<<std::endl;
return node;
break;
default: default:
node.set_node_type(__id); node.set_node_type(__id);
parse.push(this_token); parse.push(this_token);