mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-21 18:38:44 +08:00
Fixed bugs in lexer & parser::loop
This commit is contained in:
@@ -81,17 +81,25 @@ class resource_programme_process
|
||||
}
|
||||
memset(resource,0,sizeof(char));
|
||||
int i=0;
|
||||
int instring=0;
|
||||
bool findnote=false;// to find the note with # at the head of line.
|
||||
while(!fin.eof())
|
||||
{
|
||||
resource[i]=fin.get();
|
||||
if(resource[i]=='\'' || resource[i]=='\"')
|
||||
++instring;
|
||||
if(resource[i]=='\n')
|
||||
findnote=false;
|
||||
//when meeting '\n' the findnote is set to false then the next statement can be executed.
|
||||
if(resource[i]!='#' && !findnote)
|
||||
++i;
|
||||
else if(resource[i]=='#')
|
||||
findnote=true;
|
||||
{
|
||||
if(instring & 1)
|
||||
++i;
|
||||
else
|
||||
findnote=true;
|
||||
}
|
||||
if(fin.eof())
|
||||
break;
|
||||
}
|
||||
@@ -458,7 +466,7 @@ class nasal_lexer
|
||||
else if((*i).content=="<=")
|
||||
(*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];
|
||||
switch(c)
|
||||
|
||||
@@ -958,6 +958,7 @@ abstract_syntax_tree nasal_parser::loop_expr()
|
||||
node.add_child(definition_expr());
|
||||
break;
|
||||
case __id:
|
||||
parse.push(this_token);
|
||||
node.add_child(calculation_expr());
|
||||
break;
|
||||
case __semi:parse.push(this_token);break;
|
||||
@@ -1235,6 +1236,12 @@ abstract_syntax_tree nasal_parser::mul_div_operator_expr()
|
||||
while(1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
parse.push(this_token);
|
||||
@@ -1666,6 +1673,12 @@ abstract_syntax_tree nasal_parser::identifier_call_expr()
|
||||
case __dot:
|
||||
node=call_hash_expr();
|
||||
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:
|
||||
node.set_node_type(__id);
|
||||
parse.push(this_token);
|
||||
|
||||
Reference in New Issue
Block a user