Nettoyage de la classe JArithmeticInterpreter

This commit is contained in:
Marc Baloup 2014-12-26 16:56:39 +01:00
parent 9ec2dfb95b
commit 6f05cf681f

View File

@ -449,16 +449,19 @@ public class JArithmeticInterpreter {
//.................................................................................... Write_Tree //.................................................................................... Write_Tree
public String writeTree() {
StringBuffer sb = new StringBuffer();
writeTree(sb);
return sb.toString();
}
private void writeTree(StringBuffer string) { private void writeTree(StringBuffer string) {
boolean parenthese=false; boolean parenthese=false;
switch(mOperator) { switch(mOperator) {
case -2:
string.append('y');
break;
case -1:
string.append('x');
break;
case 0: case 0:
string.append(mValue); string.append(mValue);
break; break;
@ -550,7 +553,7 @@ public class JArithmeticInterpreter {
string.append(')'); string.append(')');
break; break;
case 9: case 9:
string.append("<EFBFBD>("); string.append("sqrt(");
fg.writeTree(string); fg.writeTree(string);
string.append(')'); string.append(')');
break; break;
@ -605,7 +608,7 @@ public class JArithmeticInterpreter {
signe=-1; signe=-1;
i++; i++;
} }
if (chaine.charAt(i)=='<27>') return signe*Math.PI; if (chaine.charAt(i)=='<27>') return signe*Math.PI; // TODO changer le caractère non reconnu
while (i<longueur && chaine.charAt(i)>47 && chaine.charAt(i)<58) { while (i<longueur && chaine.charAt(i)>47 && chaine.charAt(i)<58) {
temp=temp*10+(chaine.charAt(i)-48); temp=temp*10+(chaine.charAt(i)-48);
@ -626,102 +629,102 @@ public class JArithmeticInterpreter {
//.................................................................................... FindOperator //.................................................................................... FindOperator
private static void FindOperator(VariableInt oper,VariableInt esp,StringBuffer chaine,int pos) { private static void FindOperator(VariableInt oper,VariableInt esp,StringBuffer chaine,int pos) {
switch(chaine.charAt(pos)) { switch(chaine.charAt(pos)) {
case 'a': case 'a':
switch(chaine.charAt(pos+1)) { switch(chaine.charAt(pos+1)) {
case 'b': case 'b':
esp.mValue=3; esp.mValue=3;
oper.mValue=10; oper.mValue=10;
break; break;
case 'c': case 'c':
esp.mValue=4; esp.mValue=4;
oper.mValue=15; oper.mValue=15;
break; break;
case 's': case 's':
esp.mValue=4; esp.mValue=4;
oper.mValue=14; oper.mValue=14;
break; break;
case 't': case 't':
esp.mValue=4; esp.mValue=4;
oper.mValue=16; oper.mValue=16;
break; break;
} }
break; break;
case 'c': case 'c':
if (chaine.charAt(pos+1)=='h') { if (chaine.charAt(pos+1)=='h') {
esp.mValue=2; esp.mValue=2;
oper.mValue=18;
}
else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='s')) {
if (chaine.charAt(pos+3)=='h') {
esp.mValue=4;
oper.mValue=18; oper.mValue=18;
} }
else { else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='s')) {
esp.mValue=3; if (chaine.charAt(pos+3)=='h') {
oper.mValue=12; esp.mValue=4;
oper.mValue=18;
}
else {
esp.mValue=3;
oper.mValue=12;
}
} }
} break;
break; case 'e':
case 'e': if ((chaine.charAt(pos+1)=='x') && (chaine.charAt(pos+2)=='p')) {
if ((chaine.charAt(pos+1)=='x') && (chaine.charAt(pos+2)=='p')) { esp.mValue=3;
esp.mValue=3; oper.mValue=6;
oper.mValue=6; }
} else oper.mValue=-10;
else oper.mValue=-10; break;
break; case 'l':
case 'l': if (chaine.charAt(pos+1)=='n') {
if (chaine.charAt(pos+1)=='n') { esp.mValue=2;
esp.mValue=2; oper.mValue=7;
oper.mValue=7; }
} else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='g')){
else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='g')){ esp.mValue=3;
esp.mValue=3; oper.mValue=8;
oper.mValue=8; }
} else oper.mValue=-10;
else oper.mValue=-10; break;
break; case 's':
case 's': if (chaine.charAt(pos+1)=='h') {
if (chaine.charAt(pos+1)=='h') { esp.mValue=2;
esp.mValue=2;
oper.mValue=17;
}
else if (chaine.charAt(pos+1)=='q') {
esp.mValue=4;
oper.mValue=9;
}
else {
if (chaine.charAt(pos+3)=='h') {
esp.mValue=4;
oper.mValue=17; oper.mValue=17;
} }
else { else if (chaine.charAt(pos+1)=='q') {
esp.mValue=3;
oper.mValue=11;
}
}
break;
case 't':
if (chaine.charAt(pos+1)=='h') {
esp.mValue=2;
oper.mValue=19;
}
else if ((chaine.charAt(pos+1)=='a') && (chaine.charAt(pos+2)=='n')) {
if (chaine.charAt(pos+3)=='h') {
esp.mValue=4; esp.mValue=4;
oper.mValue=9;
}
else {
if (chaine.charAt(pos+3)=='h') {
esp.mValue=4;
oper.mValue=17;
}
else {
esp.mValue=3;
oper.mValue=11;
}
}
break;
case 't':
if (chaine.charAt(pos+1)=='h') {
esp.mValue=2;
oper.mValue=19; oper.mValue=19;
} }
else { else if ((chaine.charAt(pos+1)=='a') && (chaine.charAt(pos+2)=='n')) {
esp.mValue=3; if (chaine.charAt(pos+3)=='h') {
oper.mValue=13; esp.mValue=4;
oper.mValue=19;
}
else {
esp.mValue=3;
oper.mValue=13;
}
} }
else oper.mValue=-10;
break;
default:
oper.mValue=-10;
break;
} }
else oper.mValue=-10;
break;
default:
oper.mValue=-10;
break;
}
} }
//.................................................................................... CopyPartialString //.................................................................................... CopyPartialString