Bug fixes
This commit is contained in:
parent
194777ab40
commit
936053c2a5
|
@ -45,9 +45,11 @@ data type = <scalar> <identifier> <calculation> <list> <hash> <function>
|
|||
<func> <(> <identifier>|<identifiers> <)> <{> <statement> <}>
|
||||
<1><definition> ::=
|
||||
<var> <identifier> <=> <scalar>|<identifier>|<list>|<hash>|<calculation> <;>
|
||||
<var> <identifier> <=> <(> <scalar>|<identifier>|<list>|<hash>|<calculation> <)> <;>
|
||||
<var> <identifier> <=> <function>
|
||||
<1><assigntment> ::=
|
||||
<!=var> <identifier> <=> <scalar>|<identifier>|<list>|<hash>|<calculation> <;>
|
||||
<!=var> <identifier> <=> <(> <scalar>|<identifier>|<list>|<hash>|<calculation> <)> <;>
|
||||
<statement> ::=
|
||||
<!=<for> <(>> <definition>|<assignment>
|
||||
<return> <scalar>|<identifier>|<list>|<hash>|<calculation> <;>
|
||||
|
|
|
@ -19,4 +19,6 @@ if(!e.e)e;
|
|||
var e=e.e("str",1).e()*e.e("str",1).e*0.001;
|
||||
e.e("str",1).e("str",e-e);
|
||||
e.e(e("str",e.e()/2880)~"str");
|
||||
var e=func(){e;};
|
||||
var e=func(){e;};
|
||||
var e=e+e-e;
|
||||
var e=e+e+e+e;
|
||||
|
|
|
@ -7,8 +7,10 @@ int main()
|
|||
nasal_lexer lex;
|
||||
nasal_parser par;
|
||||
std::string command;
|
||||
std::cout<<">> nasal-- script by ValKmjolnir"<<std::endl;
|
||||
std::cout<<">> nasal script interpreter by ValKmjolnir"<<std::endl;
|
||||
std::cout<<">> input \"help\" to find help."<<std::endl;
|
||||
std::cout<<">> Be careful: this interpreter uses strict methods to check if there's an error."<<std::endl;
|
||||
std::cout<<" Always add \";\" after each statement (except loop and if-else)."<<std::endl;
|
||||
while(1)
|
||||
{
|
||||
std::cout<<">> ";
|
||||
|
|
|
@ -451,7 +451,7 @@ class nasal_parser
|
|||
temp.pop();
|
||||
}
|
||||
|
||||
if((tbl[2]!=__scalar) && (tbl[2]!=__identifier) && ((tbl[1]==__sub_operator) || (tbl[1]==__add_operator)) && (tbl[0]==__identifier))
|
||||
if((tbl[2]!=__scalar) && (tbl[2]!=__identifier) && (tbl[2]!=__calculation) && ((tbl[1]==__sub_operator) || (tbl[1]==__add_operator)) && (tbl[0]==__identifier))
|
||||
{
|
||||
parse_unit t;
|
||||
t.type=__identifier;
|
||||
|
@ -759,9 +759,9 @@ class nasal_parser
|
|||
}
|
||||
bool definition_check()
|
||||
{
|
||||
int tbl[5]={0};
|
||||
int tbl[7]={0};
|
||||
std::stack<parse_unit> temp;
|
||||
for(int i=0;i<5;++i)
|
||||
for(int i=0;i<7;++i)
|
||||
{
|
||||
if(parser.empty())
|
||||
break;
|
||||
|
@ -769,7 +769,7 @@ class nasal_parser
|
|||
tbl[i]=temp.top().type;
|
||||
parser.pop();
|
||||
}
|
||||
for(int i=0;i<5;++i)
|
||||
for(int i=0;i<7;++i)
|
||||
{
|
||||
if(temp.empty())
|
||||
break;
|
||||
|
@ -786,6 +786,16 @@ class nasal_parser
|
|||
parser.push(t);
|
||||
return true;
|
||||
}
|
||||
else if((tbl[6]==__var) && (tbl[5]==__identifier) && (tbl[4]==__equal) && (tbl[3]==__left_curve) && ((tbl[2]==__identifier) || (tbl[2]==__scalar) || (tbl[2]==__list) || (tbl[2]==__hash) || (tbl[2]==__calculation)) && (tbl[1]==__right_curve) && (tbl[0]==__semi))
|
||||
{
|
||||
parse_unit t;
|
||||
t.type=__definition;
|
||||
t.line=parser.top().line;
|
||||
for(int i=0;i<7;++i)
|
||||
parser.pop();
|
||||
parser.push(t);
|
||||
return true;
|
||||
}
|
||||
else if((tbl[3]=__var) && (tbl[2]==__identifier) && (tbl[1]==__equal) && (tbl[0]==__function))
|
||||
{
|
||||
parse_unit t;
|
||||
|
@ -800,9 +810,9 @@ class nasal_parser
|
|||
}
|
||||
bool assignment_check()
|
||||
{
|
||||
int tbl[4]={0};
|
||||
int tbl[6]={0};
|
||||
std::stack<parse_unit> temp;
|
||||
for(int i=0;i<4;++i)
|
||||
for(int i=0;i<6;++i)
|
||||
{
|
||||
if(parser.empty())
|
||||
break;
|
||||
|
@ -810,7 +820,7 @@ class nasal_parser
|
|||
tbl[i]=temp.top().type;
|
||||
parser.pop();
|
||||
}
|
||||
for(int i=0;i<4;++i)
|
||||
for(int i=0;i<6;++i)
|
||||
{
|
||||
if(temp.empty())
|
||||
break;
|
||||
|
@ -830,6 +840,18 @@ class nasal_parser
|
|||
parser.push(t);
|
||||
return true;
|
||||
}
|
||||
else if((tbl[5]==__identifier) && ((tbl[4]==__equal) || (tbl[4]==__add_equal) || (tbl[4]==__sub_equal)
|
||||
|| (tbl[4]==__mul_equal) || (tbl[4]==__div_equal) || (tbl[4]==__link_equal))
|
||||
&& (tbl[3]==__left_curve) && ((tbl[2]==__identifier) || (tbl[2]==__scalar) || (tbl[2]==__list) || (tbl[2]==__hash) || (tbl[2]==__calculation)) && (tbl[1]==__right_curve) && (tbl[0]==__semi))
|
||||
{
|
||||
parse_unit t;
|
||||
t.type=__definition;
|
||||
t.line=parser.top().line;
|
||||
for(int i=0;i<6;++i)
|
||||
parser.pop();
|
||||
parser.push(t);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool function_def()
|
||||
|
|
|
@ -1 +1 @@
|
|||
null
|
||||
null
|
Loading…
Reference in New Issue