===================================================================
RCS file: /home/cvs/OpenXM/src/OpenMath/OM2OXM.java,v
retrieving revision 1.3
retrieving revision 1.15
diff -u -p -r1.3 -r1.15
--- OpenXM/src/OpenMath/OM2OXM.java 1999/11/12 07:46:37 1.3
+++ OpenXM/src/OpenMath/OM2OXM.java 2000/01/20 13:58:48 1.15
@@ -1,5 +1,5 @@
/**
- * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.2 1999/11/04 19:36:41 tam Exp $
+ * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.14 2000/01/19 15:32:50 tam Exp $
*
* このクラスでは以下の BNF で表される構文解析を実装している
* expr -> stag [expr | immediate]* etag
@@ -39,7 +39,7 @@ final class OM2OXM implements Runnable{
private int token = TT_NULL;
private boolean lexPushbackFlag = false;
private OpenXM asir; // for debug
- private boolean debug = true;
+ protected boolean debug = false; // for debug message
// Token Type for lexical analyzer
final static int TT_NULL = 0;
@@ -54,8 +54,6 @@ final class OM2OXM implements Runnable{
while(true){
CMO tmp;
- Thread.yield();
-
switch(asir.receiveOXtag()){
case OpenXM.OX_COMMAND:
asir.receiveSM();
@@ -75,7 +73,7 @@ final class OM2OXM implements Runnable{
return ""+ CMO2OM_sub(cmo) +"";
}
- private static String CMO2OM_sub(CMO cmo){
+ private static String CMO2OM_sub(CMO cmo) throws NumberFormatException{
String ret = "";
switch(cmo.getDISCRIMINATOR()){
@@ -90,8 +88,18 @@ final class OM2OXM implements Runnable{
case CMO.CMO_STRING:
return ""+ ((CMO_STRING)cmo).getString() +"";
- // case CMO.CMO_LIST:
+ case CMO.CMO_LIST:
+ ret += "";
+ {
+ CMO ob[] = ((CMO_LIST)cmo).getElements();
+ for(int i=0;i";
+ return ret;
+
case CMO.CMO_MONOMIAL32:
ret += "";
ret += CMO2OM_sub(((CMO_MONOMIAL32)cmo).getCoefficient());
@@ -117,9 +125,12 @@ final class OM2OXM implements Runnable{
case CMO.CMO_DMS_GENERIC:
ret += "";
- ret += "2";
+ ret += "2";
return ret;
+ case CMO.CMO_RECURSIVE_POLYNOMIAL:
+ return CMO2OM_CoefficientOfRecursivePOLYNOMIAL(((CMO_RECURSIVE_POLYNOMIAL)cmo).getPolynomial(),((CMO_RECURSIVE_POLYNOMIAL)cmo).getVariables());
+
case CMO.CMO_DISTRIBUTED_POLYNOMIAL:
ret += "";
ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing());
@@ -131,20 +142,67 @@ final class OM2OXM implements Runnable{
ret += "";
return ret;
+ //case CMO.CMO_POLYNOMIAL_IN_ONE_VARIABLE:
+
+ case CMO.CMO_BIGFLOAT:
+ ret += "";
+ ret += CMO2OM_sub(((CMO_BIGFLOAT)cmo).getSyosubu());
+ ret += "";
+ ret += "2";
+ ret += CMO2OM_sub(((CMO_BIGFLOAT)cmo).getShisubu());
+ ret += "";
+ return ret;
+
case CMO.CMO_INDETERMINATE:
return "";
- /*
- case CMO.CMO_TREE:
- return ""+
- "";
- */
+ case CMO.CMO_TREE:
+ ret += "";
+ for(int i=0;i<((CMO_TREE)cmo).getLeaves().getElements().length;i++){
+ ret += CMO2OM_sub(((CMO_TREE)cmo).getLeaves().getElements()[i]);
+ }
+ ret += "";
+ return ret;
default:
- return ""+ cmo.toCMOexpression() +"";
+ //return ""+ cmo.toCMOexpression() +"";
}
+
+ throw new NumberFormatException("unknown convert way:"+
+ cmo.toCMOexpression());
}
+ private static String CMO2OM_CoefficientOfRecursivePOLYNOMIAL(CMO cmo,CMO_LIST variables){
+ CMO_POLYNOMIAL_IN_ONE_VARIABLE poly;
+ String ret = "",variable;
+
+ if(!(cmo instanceof CMO_POLYNOMIAL_IN_ONE_VARIABLE)){
+ return CMO2OM_sub(cmo);
+ }
+
+ poly = (CMO_POLYNOMIAL_IN_ONE_VARIABLE)cmo;
+ variable = CMO2OM_sub(variables.getElements()[poly.getVariable()]);
+
+ for(int i=0;i"+
+ ""+
+ variable +""+ poly.getDegrees()[i] +""+
+ CMO2OM_CoefficientOfRecursivePOLYNOMIAL(poly.getCoefficients()[i],
+ variables)
+ +"";
+ if(i==0){
+ ret = mono;
+ }else{
+ ret = ""+ ret + mono +"";
+ }
+ }
+
+ return ret;
+ }
+
private boolean isSpace(int ch){ // use from lex
return (ch==' ' || ch=='\t' || ch=='\n' || ch=='\r');
}
@@ -223,7 +281,7 @@ final class OM2OXM implements Runnable{
while((ch = is.read()) != '<' && ch != -1){
debug("debug: "+ch);
if(isSpace(ch)){
- String spaces = String.valueOf(ch);
+ String spaces = String.valueOf((char)ch);
while(isSpace(ch = is.read())){
spaces += (char)ch;
@@ -304,6 +362,9 @@ final class OM2OXM implements Runnable{
if(name.equals("DMP")){
ret = parse_symb_DMP();
+ debug("poly: "+ret);
+ }else if(name.equals("list")){
+ ret = parse_objects();
}else{
ret = new CMO_TREE(name,"Basic",parse_objects());
}
@@ -423,10 +484,11 @@ final class OM2OXM implements Runnable{
array[i] = ((CMO_ZZ)degree.elementAt(i+1)).intValue();
}
+ //debug("monom: "+ new CMO_MONOMIAL32(array,(CMO_ZZ)degree.elementAt(0)));
return new CMO_MONOMIAL32(array,(CMO_ZZ)degree.elementAt(0));
}
- private CMO parse_objects() throws IOException{
+ private CMO_LIST parse_objects() throws IOException{
// 解析された object を LIST で返す
Vector objects = new Vector();
CMO[] array;
@@ -441,7 +503,7 @@ final class OM2OXM implements Runnable{
array = new CMO[objects.size()];
objects.copyInto((Object[])array);
- System.out.println("debug :"+ new CMO_LIST(array));
+ debug("debug :"+ new CMO_LIST(array));
return new CMO_LIST(array);
}
@@ -557,6 +619,7 @@ final class OM2OXM implements Runnable{
parse_error("We expect integer.");
}
+ debug("ZZ: "+ str);
return new CMO_ZZ(str);
}
@@ -649,16 +712,19 @@ final class OM2OXM implements Runnable{
return str;
}
- private void parse_error(String mesg){
- System.err.println(mesg);
- System.err.print("error occuered near :");
+ private void parse_error(String mesg) throws NumberFormatException{
+ String ret;
+
+ ret = mesg +"\n";
+ ret += "error occuered near :";
try{
for(int i=0;i<10;i++){
- System.err.print((char)is.read());
+ ret += (char)is.read();
}
- System.err.println((char)is.read());
}catch(IOException e){}
- System.exit(1);
+ ret += "\n";
+
+ throw new NumberFormatException(ret);
}
private void debug(String str){
@@ -712,15 +778,19 @@ final class OM2OXM implements Runnable{
//サーバ側から送信された文字列を受信します。
while(true){
- CMO obj = P.parse(System.in);
- asir.send(obj);
- asir.sendSM(new SM(SM.SM_popCMO));
+ try{
+ CMO obj = P.parse(System.in);
+ asir.send(obj);
+ asir.sendSM(new SM(SM.SM_popCMO));
+ }catch(NumberFormatException e){
+ System.err.println(e.getMessage());
+ }
}
- //System.out.println("breaking...");
-
}catch(IOException e){
e.printStackTrace();
+ }finally{
+ System.out.println("breaking...");
}
}
}