Add calculation in '(' & ')'

This commit is contained in:
Valk Richard Li 2019-10-02 11:52:31 -05:00 committed by GitHub
parent 9ae53c6f9c
commit 425b609d29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 4 deletions

View File

@ -22,6 +22,10 @@ elsif(this_token.type==__elsif)
parse.push(this_token);
return;
}
else if(this==(1+2+3*1))
{
return nil;
}
else
{
parse.push(this_token);

View File

@ -6,5 +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,(1+2+3+(1+2+3+4)))[3]);
function([0,1,2,3],{str:"str"});

View File

@ -20,7 +20,11 @@ for(var i=0;i<1024;i+=1)
{
print(i);
}
foreach(var i;[1,2,3,4])
for(var i=0;(2*512)>=i;i+=1)
{
print(i);
}
foreach(var i;[1+(1+1),2,3,4])
{
print(i);
}

View File

@ -265,6 +265,7 @@ void nasal_parser::list_generate_expr()
case __id:identifier_begin_expr();break;
case __left_bracket:list_generate_expr();break;
case __left_brace:hash_generate_expr();break;
case __left_curve:in_curve_calc_expr();break;
default:
++error;
std::cout<<">>[Error] line "<<this_token.line<<": incorrect token '";
@ -319,6 +320,7 @@ void nasal_parser::hash_generate_expr()
case __func:function_generate_expr();break;
case __left_bracket:list_generate_expr();break;
case __left_brace:hash_generate_expr();break;
case __left_curve:in_curve_calc_expr();break;
default:
++error;
std::cout<<">>[Error] line "<<this_token.line<<": incorrect token '";
@ -440,6 +442,7 @@ void nasal_parser::if_else_expr()
case __number:number_begin_expr();break;
case __string:string_begin_expr();break;
case __id:identifier_begin_expr();break;
case __left_curve:in_curve_calc_expr();break;
default:
++error;
std::cout<<">>[Error] line "<<this_token.line<<": expect a correct data."<<std::endl;
@ -732,6 +735,24 @@ void nasal_parser::in_curve_calc_expr()
++error;
std::cout<<">>[Error] line "<<this_token.line<<": expect a ')' at this line."<<std::endl;
}
get_token();
switch(this_token.type)
{
case __add_operator:
case __sub_operator:add_sub_operator_expr();break;
case __mul_operator:
case __div_operator:mul_div_operator_expr();break;
case __link_operator:link_operator_expr();break;
case __and_operator:
case __or_operator:
case __cmp_equal:
case __cmp_not_equal:
case __cmp_less:
case __cmp_more:
case __cmp_less_or_equal:
case __cmp_more_or_equal:compare_operator_expr();break;
default:parse.push(this_token);break;
}
return;
}
void nasal_parser::number_begin_expr()
@ -752,7 +773,6 @@ void nasal_parser::number_begin_expr()
case __cmp_more:
case __cmp_less_or_equal:
case __cmp_more_or_equal:compare_operator_expr();break;
case __left_curve:in_curve_calc_expr();break;
default:parse.push(this_token);break;
}
return;
@ -775,7 +795,6 @@ void nasal_parser::string_begin_expr()
case __cmp_more:
case __cmp_less_or_equal:
case __cmp_more_or_equal:compare_operator_expr();break;
case __left_curve:in_curve_calc_expr();break;
default:parse.push(this_token);break;
}
return;