version 1.1, 1999/11/02 11:52:34 |
version 1.6, 1999/11/14 22:57:44 |
|
|
/** |
/** |
* OM2OXM.java |
* $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.5 1999/11/12 11:36:09 tam Exp $ |
* |
* |
* $B$3$N%/%i%9$G$O0J2<$N(B BNF $B$GI=$5$l$k9=J82r@O$r<BAu$7$F$$$k(B |
* $B$3$N%/%i%9$G$O0J2<$N(B BNF $B$GI=$5$l$k9=J82r@O$r<BAu$7$F$$$k(B |
* expr -> stag [expr | immediate]* etag |
* expr -> stag [expr | immediate]* etag |
Line 39 final class OM2OXM implements Runnable{ |
|
Line 39 final class OM2OXM implements Runnable{ |
|
private int token = TT_NULL; |
private int token = TT_NULL; |
private boolean lexPushbackFlag = false; |
private boolean lexPushbackFlag = false; |
private OpenXM asir; // for debug |
private OpenXM asir; // for debug |
|
private boolean debug = true; |
|
|
// Token Type for lexical analyzer |
// Token Type for lexical analyzer |
final static int TT_NULL = 0; |
final static int TT_NULL = 0; |
Line 62 final class OM2OXM implements Runnable{ |
|
Line 63 final class OM2OXM implements Runnable{ |
|
|
|
case OpenXM.OX_DATA: |
case OpenXM.OX_DATA: |
tmp = asir.receiveCMO(); |
tmp = asir.receiveCMO(); |
System.out.println("=> <OMOBJ>"+ CMO2OM(tmp) +"</OMOBJ>"); |
System.out.println("=> "+ CMO2OM(tmp)); |
break; |
break; |
} |
} |
|
|
Line 71 final class OM2OXM implements Runnable{ |
|
Line 72 final class OM2OXM implements Runnable{ |
|
} |
} |
|
|
public static String CMO2OM(CMO cmo){ |
public static String CMO2OM(CMO cmo){ |
|
return "<OMOBJ>"+ CMO2OM_sub(cmo) +"</OMOBJ>"; |
|
} |
|
|
|
private static String CMO2OM_sub(CMO cmo){ |
String ret = ""; |
String ret = ""; |
|
|
switch(cmo.getDISCRIMINATOR()){ |
switch(cmo.getDISCRIMINATOR()){ |
Line 89 final class OM2OXM implements Runnable{ |
|
Line 94 final class OM2OXM implements Runnable{ |
|
|
|
case CMO.CMO_MONOMIAL32: |
case CMO.CMO_MONOMIAL32: |
ret += "<OMA><OMS name=\"Monom\" cd=\"poly\"/>"; |
ret += "<OMA><OMS name=\"Monom\" cd=\"poly\"/>"; |
ret += CMO2OM(((CMO_MONOMIAL32)cmo).getCoefficient()); |
ret += CMO2OM_sub(((CMO_MONOMIAL32)cmo).getCoefficient()); |
for(int i=0;i<((CMO_MONOMIAL32)cmo).getDegree().length;i++){ |
for(int i=0;i<((CMO_MONOMIAL32)cmo).getDegree().length;i++){ |
ret += "<OMI>"+ ((CMO_MONOMIAL32)cmo).getDegree()[i] +"</OMI>"; |
ret += "<OMI>"+ ((CMO_MONOMIAL32)cmo).getDegree()[i] +"</OMI>"; |
} |
} |
Line 101 final class OM2OXM implements Runnable{ |
|
Line 106 final class OM2OXM implements Runnable{ |
|
|
|
case CMO.CMO_QQ: |
case CMO.CMO_QQ: |
return "<OMA><OMS name=\"over\" cd=\"basic\"/>"+ |
return "<OMA><OMS name=\"over\" cd=\"basic\"/>"+ |
CMO2OM(((CMO_QQ)cmo).getBunshi()) + CMO2OM(((CMO_QQ)cmo).getBunbo()) |
CMO2OM_sub(((CMO_QQ)cmo).getBunshi())+ |
+"</OMA>"; |
CMO2OM_sub(((CMO_QQ)cmo).getBunbo())+ |
|
"</OMA>"; |
|
|
case CMO.CMO_ZERO: |
case CMO.CMO_ZERO: |
return "<OMI> 0 </OMI>"; |
return "<OMI> 0 </OMI>"; |
Line 111 final class OM2OXM implements Runnable{ |
|
Line 117 final class OM2OXM implements Runnable{ |
|
|
|
case CMO.CMO_DMS_GENERIC: |
case CMO.CMO_DMS_GENERIC: |
ret += "<OMA><OMS name=\"PolyRing\" cd=\"poly\"/>"; |
ret += "<OMA><OMS name=\"PolyRing\" cd=\"poly\"/>"; |
ret += "<OMI>2</OMI>"; |
ret += "<OMI>2</OMI></OMA>"; |
return ret; |
return ret; |
|
|
case CMO.CMO_DISTRIBUTED_POLYNOMIAL: |
case CMO.CMO_DISTRIBUTED_POLYNOMIAL: |
ret += "<OMA><OMS name=\"DMP\" cd=\"poly\"/>"; |
ret += "<OMA><OMS name=\"DMP\" cd=\"poly\"/>"; |
ret += CMO2OM(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing()); |
ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing()); |
ret += "<OMA><OMS name=\"SDMP\" cd=\"poly\"/>"; |
ret += "<OMA><OMS name=\"SDMP\" cd=\"poly\"/>"; |
for(int i=0;i<((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials().length;i++){ |
for(int i=0;i<((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials().length; |
ret += CMO2OM(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials()[i]); |
i++){ |
|
ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials()[i]); |
} |
} |
ret += "</OMA></OMA>"; |
ret += "</OMA></OMA>"; |
return ret; |
return ret; |
Line 214 final class OM2OXM implements Runnable{ |
|
Line 221 final class OM2OXM implements Runnable{ |
|
}else if(ch != -1){ |
}else if(ch != -1){ |
is.unread(ch); |
is.unread(ch); |
while((ch = is.read()) != '<' && ch != -1){ |
while((ch = is.read()) != '<' && ch != -1){ |
System.out.println("debug: "+ch); |
debug("debug: "+ch); |
if(isSpace(ch)){ |
if(isSpace(ch)){ |
String spaces = String.valueOf(ch); |
String spaces = String.valueOf((char)ch); |
|
|
while(isSpace(ch = is.read())){ |
while(isSpace(ch = is.read())){ |
spaces += (char)ch; |
spaces += (char)ch; |
Line 244 final class OM2OXM implements Runnable{ |
|
Line 251 final class OM2OXM implements Runnable{ |
|
parse_error("We expect type :'"+ type |
parse_error("We expect type :'"+ type |
+"', but we got type :'"+ token +"'("+ attribute +")."); |
+"', but we got type :'"+ token +"'("+ attribute +")."); |
} |
} |
//System.out.println(":"+token+":"+attribute+":"+type); |
//debug(":"+token+":"+attribute+":"+type); |
return true; |
return true; |
} |
} |
|
|
Line 260 final class OM2OXM implements Runnable{ |
|
Line 267 final class OM2OXM implements Runnable{ |
|
} |
} |
|
|
ret = parse_object(); |
ret = parse_object(); |
|
|
exceptTokenTypeInParse(TT_EndTag); |
exceptTokenTypeInParse(TT_EndTag); |
if(!attribute.equals("OMOBJ")){ |
if(!attribute.equals("OMOBJ")){ |
parse_error("We expect '</OMOBJ>'."); |
parse_error("We expect '</OMOBJ>'."); |
Line 272 final class OM2OXM implements Runnable{ |
|
Line 279 final class OM2OXM implements Runnable{ |
|
private CMO parse_object() throws IOException{ |
private CMO parse_object() throws IOException{ |
// object -> variable |
// object -> variable |
// | '<OMI>' S? integer S? '</OMI>' |
// | '<OMI>' S? integer S? '</OMI>' |
|
// | '<OMSTR>' S? utf7 S? '</OMSTR>' |
// | '<OMA>' S? symbol S? objects S? '</OMA>' |
// | '<OMA>' S? symbol S? objects S? '</OMA>' |
CMO ret; |
CMO ret; |
|
|
Line 285 final class OM2OXM implements Runnable{ |
|
Line 293 final class OM2OXM implements Runnable{ |
|
}else if(attribute.equals("OMI")){ |
}else if(attribute.equals("OMI")){ |
pushbackLex(); |
pushbackLex(); |
ret = parse_OMI(); |
ret = parse_OMI(); |
|
}else if(attribute.equals("OMSTR")){ |
|
pushbackLex(); |
|
ret = parse_OMSTR(); |
}else if(attribute.equals("OMA")){ |
}else if(attribute.equals("OMA")){ |
String name,cdname; |
String name,cdname; |
int argnum = 0; |
int argnum = 0; |
Line 293 final class OM2OXM implements Runnable{ |
|
Line 304 final class OM2OXM implements Runnable{ |
|
|
|
if(name.equals("DMP")){ |
if(name.equals("DMP")){ |
ret = parse_symb_DMP(); |
ret = parse_symb_DMP(); |
|
debug("poly: "+ret); |
}else{ |
}else{ |
ret = new CMO_TREE(name,"Basic",parse_objects()); |
ret = new CMO_TREE(name,"Basic",parse_objects()); |
} |
} |
Line 327 final class OM2OXM implements Runnable{ |
|
Line 339 final class OM2OXM implements Runnable{ |
|
return ret; |
return ret; |
} |
} |
|
|
|
private CMO_STRING parse_OMSTR() throws IOException{ |
|
CMO_STRING ret; |
|
|
|
exceptTokenTypeInParse(TT_StartTag); |
|
if(!attribute.equals("OMSTR")){ |
|
parse_error("We expect '<OMSTR>'."); |
|
} |
|
|
|
if(readNextToken() == TT_String){ |
|
//ret = (CMO_STRING)parse_utf7(); |
|
ret = new CMO_STRING(attribute); |
|
}else{ |
|
ret = new CMO_STRING(""); |
|
pushbackLex(); |
|
} |
|
|
|
exceptTokenTypeInParse(TT_EndTag); |
|
if(!attribute.equals("OMSTR")){ |
|
parse_error("We expect '</OMSTR>'."); |
|
} |
|
|
|
return ret; |
|
} |
|
|
private CMO parse_symb_DMP() throws IOException{ |
private CMO parse_symb_DMP() throws IOException{ |
parse_object(); |
parse_object(); |
return new CMO_DISTRIBUTED_POLYNOMIAL(new CMO_DMS_GENERIC(), |
return new CMO_DISTRIBUTED_POLYNOMIAL(new CMO_DMS_GENERIC(), |
Line 388 final class OM2OXM implements Runnable{ |
|
Line 424 final class OM2OXM implements Runnable{ |
|
array[i] = ((CMO_ZZ)degree.elementAt(i+1)).intValue(); |
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)); |
return new CMO_MONOMIAL32(array,(CMO_ZZ)degree.elementAt(0)); |
} |
} |
|
|
Line 624 final class OM2OXM implements Runnable{ |
|
Line 661 final class OM2OXM implements Runnable{ |
|
System.err.println((char)is.read()); |
System.err.println((char)is.read()); |
}catch(IOException e){} |
}catch(IOException e){} |
System.exit(1); |
System.exit(1); |
|
} |
|
|
|
private void debug(String str){ |
|
if(debug){ |
|
System.err.println(str); |
|
} |
} |
} |
|
|
public static void main(String[] argv) throws IOException{ |
public static void main(String[] argv) throws IOException{ |