forked from xxq250/Nasal-Interpreter
Add 'else if' recognition
This commit is contained in:
@@ -8,6 +8,10 @@ elsif(this_token.type==__elsif)
|
||||
parse.push(this_token);
|
||||
return;
|
||||
}
|
||||
else if(this_token.type!=__else)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
elsif(this_token.type==__elsif)
|
||||
{
|
||||
parse.push(this_token);
|
||||
|
||||
@@ -6,4 +6,5 @@ var f=func(n,m,dynamic...)
|
||||
n+=m;
|
||||
return dynamic;
|
||||
};
|
||||
print(f(1,1,0,0,0,0,0)[3]);
|
||||
print(f(1,1,0,0,0,0,0)[3]);
|
||||
function([0,1,2,3],{str:"str"});
|
||||
@@ -18,7 +18,7 @@ int main()
|
||||
std::cout<<">> 2. [cls ] |clear the screen."<<std::endl;
|
||||
std::cout<<">> 3. [exit ] |shut down the interpreter."<<std::endl;
|
||||
std::cout<<">> 4. [lexer ] |run and show the lexer. (-lexer)"<<std::endl;
|
||||
std::cout<<">> 5. [parser] |run parser. (-parser)"<<std::endl;
|
||||
std::cout<<">> 5. [parser] |run parser and see parse stack & parse result(s). (-parser)"<<std::endl;
|
||||
std::cout<<">> 6. [ast ] |print the abstract syntax tree."<<std::endl;
|
||||
std::cout<<">> 7. [del ] |delete program in memory."<<std::endl;
|
||||
std::cout<<">> 8. [run ] |run the programme in stack. (-lexer -parser)"<<std::endl;
|
||||
|
||||
@@ -105,7 +105,7 @@ class nasal_parser
|
||||
if(!error)
|
||||
root.run();
|
||||
else
|
||||
std::cout<<">>[Parse] "<<error<<"error(s) occurred,stop."<<std::endl;
|
||||
std::cout<<">>[Parse] "<<error<<" error(s) occurred,stop."<<std::endl;
|
||||
return;
|
||||
}
|
||||
void parse_main_work();
|
||||
@@ -120,6 +120,7 @@ class nasal_parser
|
||||
void definition_expr();
|
||||
void assignment_expr();
|
||||
void loop_expr();
|
||||
bool else_if_check();
|
||||
void if_else_expr();
|
||||
void add_sub_operator_expr();
|
||||
void mul_div_operator_expr();
|
||||
@@ -396,6 +397,24 @@ void nasal_parser::assignment_expr()
|
||||
}
|
||||
return;
|
||||
}
|
||||
bool nasal_parser::else_if_check()
|
||||
{
|
||||
token temp=this_token;
|
||||
if(this_token.type!=__else)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
get_token();
|
||||
if(this_token.type!=__if)
|
||||
{
|
||||
parse.push(this_token);
|
||||
this_token=temp;// to avoid when recognizing 'else' without 'if'
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void nasal_parser::if_else_expr()
|
||||
{
|
||||
get_token();
|
||||
@@ -433,7 +452,7 @@ void nasal_parser::if_else_expr()
|
||||
}
|
||||
statements_block();
|
||||
get_token();
|
||||
while(this_token.type==__elsif)
|
||||
while(this_token.type==__elsif || else_if_check())
|
||||
{
|
||||
get_token();
|
||||
if(this_token.type!=__left_curve)
|
||||
|
||||
Reference in New Issue
Block a user