===================================================================
RCS file: /home/cvs/OpenXM/src/OpenMath/OM2OXM.java,v
retrieving revision 1.6
retrieving revision 1.19
diff -u -p -r1.6 -r1.19
--- OpenXM/src/OpenMath/OM2OXM.java 1999/11/14 22:57:44 1.6
+++ OpenXM/src/OpenMath/OM2OXM.java 2000/03/14 04:44:16 1.19
@@ -1,5 +1,5 @@
/**
- * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.5 1999/11/12 11:36:09 tam Exp $
+ * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.18 2000/02/28 14:10:28 takayama 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,14 +73,14 @@ 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()){
- 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:
@@ -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());
@@ -120,6 +128,9 @@ final class OM2OXM implements Runnable{
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.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');
}
@@ -306,7 +364,17 @@ final class OM2OXM implements Runnable{
ret = parse_symb_DMP();
debug("poly: "+ret);
}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);
@@ -314,7 +382,7 @@ final class OM2OXM implements Runnable{
parse_error("We expect ''.");
}
}else{
- parse_error("???");
+ parse_error("We expect ' or '' or ''.");
ret = null;
}
@@ -399,6 +467,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);
@@ -410,6 +479,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());
@@ -419,17 +496,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