Update interpreter.cpp

This commit is contained in:
paul-wu
2015-05-23 00:32:28 +08:00
parent 4366aaa1a8
commit 18c102c76d

View File

@ -744,7 +744,7 @@ VALU * expression(int * start)
*start += 1;
return result;
}
if(checkchar(tokenlist[*start],'+')){ // if add
L3: if(checkchar(tokenlist[*start],'+')){ // if add
*start += 1;
VALU * temp = expression(start);
@ -766,9 +766,9 @@ VALU * expression(int * start)
freevalu(temp);
return result;
}
if(checkchar(tokenlist[*start],'-')){ // if minus
L4: if(checkchar(tokenlist[*start],'-')){ // if minus
*start += 1;
VALU * temp = expression(start);
VALU * temp = term(start);
if(temp == NULL || result == NULL){
if(result)freevalu(result);
@ -784,9 +784,14 @@ VALU * expression(int * start)
freevalu(result);
result = NULL;
}
if(*start >= tokenlen || checkchar(tokenlist[*start],';') || checkchar(tokenlist[*start],')') || checkchar(tokenlist[*start],',') || checkchar(tokenlist[*start],']')){ // end of expression
*start += 1;
freevalu(temp);
return result;
}
if(checkchar(tokenlist[*start],'+'))goto L3;
if(checkchar(tokenlist[*start],'-'))goto L4;
}
printf("Syntax Error! Invalid expression.\n");
@ -937,7 +942,7 @@ VALU * term(int * start)
if(*start >= tokenlen || checkchar(tokenlist[*start],';') || checkchar(tokenlist[*start],')') || checkchar(tokenlist[*start],',') || checkchar(tokenlist[*start],'+') || checkchar(tokenlist[*start],'-') || checkchar(tokenlist[*start],']')){ // end of expression
return result;
}
L1:
if(checkchar(tokenlist[*start],'*')){
*start += 1;
@ -957,10 +962,11 @@ VALU * term(int * start)
freevalu(temp);
return result;
}
L2:
if(checkchar(tokenlist[*start],'/')){
*start += 1;
VALU * temp = term(start);
VALU * temp = atom(start);
if(temp == NULL || result == NULL){
if(result)freevalu(result);
@ -970,11 +976,15 @@ VALU * term(int * start)
if(!diviv(result,temp,result)){
printf("Type '%s' can not divide Type '%s'.\n",TYPE[temp->type],TYPE[ty]);
freevalu(result);
result = NULL;
return NULL;
}
if(*start >= tokenlen || checkchar(tokenlist[*start],';') || checkchar(tokenlist[*start],')') || checkchar(tokenlist[*start],',') || checkchar(tokenlist[*start],'+') || checkchar(tokenlist[*start],'-') || checkchar(tokenlist[*start],']')){ // end of expression
freevalu(temp);
return result;
}
if(checkchar(tokenlist[*start],'*'))goto L1;
if(checkchar(tokenlist[*start],'/'))goto L2;
}
printf("Syntax Error! Invalid term.\n");
return NULL;
}
@ -1237,7 +1247,7 @@ void demo()
\nIt's order is\n;r = ord(p1);\n\
\nWe can see that they are the same.\n\
\nCompute weil paring\n;f = pair(p,p1,r);\n\
\nVarify binearity\n;f1 = pair(3*p,p1,r);\n\
\nVarify bilinearity\n;f1 = pair(3*p,p1,r);\n\
\nand f^3 = f1\n;f^3 - f1;\n\
\n;f2 = pair(3*p,5*p1,r);\n\
\n;f^15 - f2;\n\
@ -1280,7 +1290,7 @@ void demo()
free(input);
i = j+1;continue;
}
Sleep(10000);
Sleep(20000);
i++;
}
system("pause");
@ -1325,7 +1335,7 @@ void help()
printf("\n\nOperation:\n");
printf("1. Our langudge compatible with the common mathematical expression completely.\n");
printf("1. Our language compatible with the common mathematical expression completely.\n");
printf("2. To buid new variables, you can use 'var name1 name2 name3 ...', or just 'a = value'.\n");
printf("3. Use 'del name' to delete the varaible you don't need.\n");
printf("4. We have an automatic type inference system, so all the types are generated automaticaly.\n");