===================================================================
RCS file: /home/cvs/OpenXM/src/OpenMath/OM2OXM.java,v
retrieving revision 1.16
retrieving revision 1.25
diff -u -p -r1.16 -r1.25
--- OpenXM/src/OpenMath/OM2OXM.java 2000/01/20 18:14:32 1.16
+++ OpenXM/src/OpenMath/OM2OXM.java 2000/09/13 06:44:55 1.25
@@ -1,6 +1,8 @@
+/*
+ * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.24 2000/04/17 03:18:57 tam Exp $
+ */
+
/**
- * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.15 2000/01/20 13:58:48 tam Exp $
- *
* このクラスでは以下の BNF で表される構文解析を実装している
* expr -> stag [expr | immediate]* etag
* immediate -> INTEGER
@@ -31,7 +33,7 @@
import java.io.*;
import java.net.*;
import java.util.Vector;
-import JP.ac.kobe_u.math.tam.OpenXM.*;
+import ORG.openxm.tam.*;
final class OM2OXM implements Runnable{
private PushbackInputStream is;
@@ -52,19 +54,12 @@ final class OM2OXM implements Runnable{
//サーバ側から送信された文字列を受信します。
try{
while(true){
- CMO tmp;
+ OXmessage message = asir.receive();
- switch(asir.receiveOXtag()){
- case OpenXM.OX_COMMAND:
- asir.receiveSM();
+ if(message.getTag() == OXmessage.OX_DATA){
+ System.out.println("=> "+ CMO2OM((CMO)message.getBody()));
break;
-
- case OpenXM.OX_DATA:
- tmp = asir.receiveCMO();
- System.out.println("=> "+ CMO2OM(tmp));
- break;
}
-
}
}catch(IOException e){}
}
@@ -77,18 +72,18 @@ final class OM2OXM implements Runnable{
String ret = "";
switch(cmo.getDISCRIMINATOR()){
- case CMO.CMO_NULL:
+ case CMO.NULL:
return "0";
- case CMO.CMO_INT32:
+ case CMO.INT32:
return ""+ ((CMO_INT32)cmo).intValue() +"";
- // case CMO.CMO_DATUM:
+ // case CMO.DATUM:
- case CMO.CMO_STRING:
+ case CMO.STRING:
return ""+ ((CMO_STRING)cmo).getString() +"";
- case CMO.CMO_LIST:
+ case CMO.LIST:
ret += "";
{
CMO ob[] = ((CMO_LIST)cmo).getElements();
@@ -100,7 +95,7 @@ final class OM2OXM implements Runnable{
ret += "";
return ret;
- case CMO.CMO_MONOMIAL32:
+ case CMO.MONOMIAL32:
ret += "";
ret += CMO2OM_sub(((CMO_MONOMIAL32)cmo).getCoefficient());
for(int i=0;i<((CMO_MONOMIAL32)cmo).getDegree().length;i++){
@@ -109,29 +104,29 @@ final class OM2OXM implements Runnable{
ret += "";
return ret;
- case CMO.CMO_ZZ:
+ case CMO.ZZ:
return ""+ ((CMO_ZZ)cmo).BigIntValue() +"";
- case CMO.CMO_QQ:
+ case CMO.QQ:
return ""+
CMO2OM_sub(((CMO_QQ)cmo).getBunshi())+
CMO2OM_sub(((CMO_QQ)cmo).getBunbo())+
"";
- case CMO.CMO_ZERO:
+ case CMO.ZERO:
return " 0 ";
- // case CMO.CMO_DMS:
+ // case CMO.DMS:
- case CMO.CMO_DMS_GENERIC:
+ case CMO.DMS_GENERIC:
ret += "";
ret += "2";
return ret;
- case CMO.CMO_RECURSIVE_POLYNOMIAL:
+ case CMO.RECURSIVE_POLYNOMIAL:
return CMO2OM_CoefficientOfRecursivePOLYNOMIAL(((CMO_RECURSIVE_POLYNOMIAL)cmo).getPolynomial(),((CMO_RECURSIVE_POLYNOMIAL)cmo).getVariables());
- case CMO.CMO_DISTRIBUTED_POLYNOMIAL:
+ case CMO.DISTRIBUTED_POLYNOMIAL:
ret += "";
ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing());
ret += "";
@@ -142,9 +137,9 @@ final class OM2OXM implements Runnable{
ret += "";
return ret;
- //case CMO.CMO_POLYNOMIAL_IN_ONE_VARIABLE:
+ //case CMO.POLYNOMIAL_IN_ONE_VARIABLE:
- case CMO.CMO_BIGFLOAT:
+ case CMO.BIGFLOAT:
ret += "";
ret += CMO2OM_sub(((CMO_BIGFLOAT)cmo).getSyosubu());
ret += "";
@@ -153,10 +148,10 @@ final class OM2OXM implements Runnable{
ret += "";
return ret;
- case CMO.CMO_INDETERMINATE:
+ case CMO.INDETERMINATE:
return "";
- case CMO.CMO_TREE:
+ case CMO.TREE:
ret += "";
for(int i=0;i<((CMO_TREE)cmo).getLeaves().getElements().length;i++){
@@ -363,10 +358,18 @@ 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());
+ CMO[] leaves = parse_objects();
+
+ if(name.equals("list")){
+ ret = new CMO_LIST(leaves);
+ }else if(name.equals("over") && leaves.length==2
+ && leaves[0] instanceof CMO_ZZ
+ && leaves[1] instanceof CMO_ZZ){
+ ret = new CMO_QQ((CMO_ZZ)leaves[0],(CMO_ZZ)leaves[1]);
+ }else{
+ ret = new CMO_TREE(name,"basic",new CMO_LIST(leaves));
+ }
}
exceptTokenTypeInParse(TT_EndTag);
@@ -374,7 +377,7 @@ final class OM2OXM implements Runnable{
parse_error("We expect ''.");
}
}else{
- parse_error("???");
+ parse_error("We expect ' or '' or ''.");
ret = null;
}
@@ -459,6 +462,7 @@ final class OM2OXM implements Runnable{
private CMO_MONOMIAL32 parse_symb_Monom() throws IOException{
Vector degree = new Vector();
+ CMO coefficient;
int[] array;
exceptTokenTypeInParse(TT_StartTag);
@@ -470,6 +474,14 @@ final class OM2OXM implements Runnable{
parse_error("We expect ''");
}
+ coefficient = parse_object();
+ if(!(coefficient instanceof CMO_ZZ
+ || coefficient instanceof CMO_QQ
+ || coefficient instanceof CMO_INT32
+ || coefficient instanceof CMO_ZERO)){
+ parse_error("the coefficient of Monomials must be integer or rational.");
+ }
+
while(readNextToken() != TT_EndTag){
pushbackLex();
degree.addElement(parse_OMI());
@@ -479,17 +491,16 @@ final class OM2OXM implements Runnable{
parse_error("We expect ''.");
}
- array = new int[degree.size()-1];
+ array = new int[degree.size()];
for(int i=0;i