mirror of
https://github.com/mii443/Weil-Pairing.git
synced 2025-08-22 16:35:30 +00:00
Update interpreter.cpp
This commit is contained in:
@ -744,7 +744,7 @@ VALU * expression(int * start)
|
|||||||
*start += 1;
|
*start += 1;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if(checkchar(tokenlist[*start],'+')){ // if add
|
L3: if(checkchar(tokenlist[*start],'+')){ // if add
|
||||||
*start += 1;
|
*start += 1;
|
||||||
VALU * temp = expression(start);
|
VALU * temp = expression(start);
|
||||||
|
|
||||||
@ -766,9 +766,9 @@ VALU * expression(int * start)
|
|||||||
freevalu(temp);
|
freevalu(temp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if(checkchar(tokenlist[*start],'-')){ // if minus
|
L4: if(checkchar(tokenlist[*start],'-')){ // if minus
|
||||||
*start += 1;
|
*start += 1;
|
||||||
VALU * temp = expression(start);
|
VALU * temp = term(start);
|
||||||
|
|
||||||
if(temp == NULL || result == NULL){
|
if(temp == NULL || result == NULL){
|
||||||
if(result)freevalu(result);
|
if(result)freevalu(result);
|
||||||
@ -784,8 +784,13 @@ VALU * expression(int * start)
|
|||||||
freevalu(result);
|
freevalu(result);
|
||||||
result = NULL;
|
result = NULL;
|
||||||
}
|
}
|
||||||
freevalu(temp);
|
if(*start >= tokenlen || checkchar(tokenlist[*start],';') || checkchar(tokenlist[*start],')') || checkchar(tokenlist[*start],',') || checkchar(tokenlist[*start],']')){ // end of expression
|
||||||
return result;
|
*start += 1;
|
||||||
|
freevalu(temp);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if(checkchar(tokenlist[*start],'+'))goto L3;
|
||||||
|
if(checkchar(tokenlist[*start],'-'))goto L4;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Syntax Error! Invalid expression.\n");
|
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
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
L1:
|
||||||
if(checkchar(tokenlist[*start],'*')){
|
if(checkchar(tokenlist[*start],'*')){
|
||||||
*start += 1;
|
*start += 1;
|
||||||
|
|
||||||
@ -957,10 +962,11 @@ VALU * term(int * start)
|
|||||||
freevalu(temp);
|
freevalu(temp);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
L2:
|
||||||
if(checkchar(tokenlist[*start],'/')){
|
if(checkchar(tokenlist[*start],'/')){
|
||||||
*start += 1;
|
*start += 1;
|
||||||
|
|
||||||
VALU * temp = term(start);
|
VALU * temp = atom(start);
|
||||||
|
|
||||||
if(temp == NULL || result == NULL){
|
if(temp == NULL || result == NULL){
|
||||||
if(result)freevalu(result);
|
if(result)freevalu(result);
|
||||||
@ -970,10 +976,14 @@ VALU * term(int * start)
|
|||||||
if(!diviv(result,temp,result)){
|
if(!diviv(result,temp,result)){
|
||||||
printf("Type '%s' can not divide Type '%s'.\n",TYPE[temp->type],TYPE[ty]);
|
printf("Type '%s' can not divide Type '%s'.\n",TYPE[temp->type],TYPE[ty]);
|
||||||
freevalu(result);
|
freevalu(result);
|
||||||
result = NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
freevalu(temp);
|
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;
|
freevalu(temp);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if(checkchar(tokenlist[*start],'*'))goto L1;
|
||||||
|
if(checkchar(tokenlist[*start],'/'))goto L2;
|
||||||
}
|
}
|
||||||
printf("Syntax Error! Invalid term.\n");
|
printf("Syntax Error! Invalid term.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1225,8 +1235,8 @@ void demo()
|
|||||||
system("cls");
|
system("cls");
|
||||||
char dem[2000] = "We first build two empty variables named 'n' and 'm'\n;var n m;\
|
char dem[2000] = "We first build two empty variables named 'n' and 'm'\n;var n m;\
|
||||||
\nthen assign vlaues to them\n;n = 120;\n;m = 200;\n\
|
\nthen assign vlaues to them\n;n = 120;\n;m = 200;\n\
|
||||||
\nCompute m+n\n ;m+n;\n\
|
\nCompute m+n\n;m + n;\n\
|
||||||
\nGenerate a random prime with lenth m and put it to vairable a\n;a=Randomprime(m);\n \
|
\nGenerate a random prime with lenth m and put it to vairable a\n;a = Randomprime(m);\n\
|
||||||
\nSet global prime\n;global_p = a;\n\
|
\nSet global prime\n;global_p = a;\n\
|
||||||
\nEvaluabte an math expression\n;a^2 + m*(n - 12*n)/a +(12*3)*(12+45+34);\n\
|
\nEvaluabte an math expression\n;a^2 + m*(n - 12*n)/a +(12*3)*(12+45+34);\n\
|
||||||
\nGenerate an random point and put it to variable p\n;p = Randompoint();\n\
|
\nGenerate an random point and put it to variable p\n;p = Randompoint();\n\
|
||||||
@ -1237,7 +1247,7 @@ void demo()
|
|||||||
\nIt's order is\n;r = ord(p1);\n\
|
\nIt's order is\n;r = ord(p1);\n\
|
||||||
\nWe can see that they are the same.\n\
|
\nWe can see that they are the same.\n\
|
||||||
\nCompute weil paring\n;f = pair(p,p1,r);\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\
|
\nand f^3 = f1\n;f^3 - f1;\n\
|
||||||
\n;f2 = pair(3*p,5*p1,r);\n\
|
\n;f2 = pair(3*p,5*p1,r);\n\
|
||||||
\n;f^15 - f2;\n\
|
\n;f^15 - f2;\n\
|
||||||
@ -1280,7 +1290,7 @@ void demo()
|
|||||||
free(input);
|
free(input);
|
||||||
i = j+1;continue;
|
i = j+1;continue;
|
||||||
}
|
}
|
||||||
Sleep(10000);
|
Sleep(20000);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
system("pause");
|
system("pause");
|
||||||
@ -1325,7 +1335,7 @@ void help()
|
|||||||
|
|
||||||
|
|
||||||
printf("\n\nOperation:\n");
|
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("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("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");
|
printf("4. We have an automatic type inference system, so all the types are generated automaticaly.\n");
|
||||||
|
Reference in New Issue
Block a user