=================================================================== RCS file: /home/cvs/OpenXM/src/OpenMath/OM2OXM.java,v retrieving revision 1.1 retrieving revision 1.8 diff -u -p -r1.1 -r1.8 --- OpenXM/src/OpenMath/OM2OXM.java 1999/11/02 11:52:34 1.1 +++ OpenXM/src/OpenMath/OM2OXM.java 1999/11/15 23:13:21 1.8 @@ -1,5 +1,5 @@ /** - * OM2OXM.java + * $OpenXM: OpenXM/src/OpenMath/OM2OXM.java,v 1.7 1999/11/15 06:19:26 tam Exp $ * * このクラスでは以下の BNF で表される構文解析を実装している * expr -> stag [expr | immediate]* etag @@ -39,6 +39,7 @@ final class OM2OXM implements Runnable{ private int token = TT_NULL; private boolean lexPushbackFlag = false; private OpenXM asir; // for debug + private boolean debug = false; // Token Type for lexical analyzer final static int TT_NULL = 0; @@ -62,7 +63,7 @@ final class OM2OXM implements Runnable{ case OpenXM.OX_DATA: tmp = asir.receiveCMO(); - System.out.println("=> "+ CMO2OM(tmp) +""); + System.out.println("=> "+ CMO2OM(tmp)); break; } @@ -71,6 +72,10 @@ final class OM2OXM implements Runnable{ } public static String CMO2OM(CMO cmo){ + return ""+ CMO2OM_sub(cmo) +""; + } + + private static String CMO2OM_sub(CMO cmo){ String ret = ""; switch(cmo.getDISCRIMINATOR()){ @@ -89,7 +94,7 @@ final class OM2OXM implements Runnable{ case CMO.CMO_MONOMIAL32: ret += ""; - ret += CMO2OM(((CMO_MONOMIAL32)cmo).getCoefficient()); + ret += CMO2OM_sub(((CMO_MONOMIAL32)cmo).getCoefficient()); for(int i=0;i<((CMO_MONOMIAL32)cmo).getDegree().length;i++){ ret += ""+ ((CMO_MONOMIAL32)cmo).getDegree()[i] +""; } @@ -101,8 +106,9 @@ final class OM2OXM implements Runnable{ case CMO.CMO_QQ: return ""+ - CMO2OM(((CMO_QQ)cmo).getBunshi()) + CMO2OM(((CMO_QQ)cmo).getBunbo()) - +""; + CMO2OM_sub(((CMO_QQ)cmo).getBunshi())+ + CMO2OM_sub(((CMO_QQ)cmo).getBunbo())+ + ""; case CMO.CMO_ZERO: return " 0 "; @@ -111,26 +117,36 @@ final class OM2OXM implements Runnable{ case CMO.CMO_DMS_GENERIC: ret += ""; - ret += "2"; + ret += "2"; return ret; case CMO.CMO_DISTRIBUTED_POLYNOMIAL: ret += ""; - ret += CMO2OM(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing()); + ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getRing()); ret += ""; - for(int i=0;i<((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials().length;i++){ - ret += CMO2OM(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials()[i]); + for(int i=0;i<((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials().length; + i++){ + ret += CMO2OM_sub(((CMO_DISTRIBUTED_POLYNOMIAL)cmo).getMonomials()[i]); } ret += ""; return ret; + 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 ""+ - ""; + return "" + ""; */ default: @@ -214,9 +230,9 @@ final class OM2OXM implements Runnable{ }else if(ch != -1){ is.unread(ch); while((ch = is.read()) != '<' && ch != -1){ - System.out.println("debug: "+ch); + 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; @@ -244,7 +260,7 @@ final class OM2OXM implements Runnable{ parse_error("We expect type :'"+ type +"', but we got type :'"+ token +"'("+ attribute +")."); } - //System.out.println(":"+token+":"+attribute+":"+type); + //debug(":"+token+":"+attribute+":"+type); return true; } @@ -260,7 +276,7 @@ final class OM2OXM implements Runnable{ } ret = parse_object(); - + exceptTokenTypeInParse(TT_EndTag); if(!attribute.equals("OMOBJ")){ parse_error("We expect ''."); @@ -272,6 +288,7 @@ final class OM2OXM implements Runnable{ private CMO parse_object() throws IOException{ // object -> variable // | '' S? integer S? '' + // | '' S? utf7 S? '' // | '' S? symbol S? objects S? '' CMO ret; @@ -285,6 +302,9 @@ final class OM2OXM implements Runnable{ }else if(attribute.equals("OMI")){ pushbackLex(); ret = parse_OMI(); + }else if(attribute.equals("OMSTR")){ + pushbackLex(); + ret = parse_OMSTR(); }else if(attribute.equals("OMA")){ String name,cdname; int argnum = 0; @@ -293,6 +313,7 @@ final class OM2OXM implements Runnable{ if(name.equals("DMP")){ ret = parse_symb_DMP(); + debug("poly: "+ret); }else{ ret = new CMO_TREE(name,"Basic",parse_objects()); } @@ -327,6 +348,30 @@ final class OM2OXM implements Runnable{ return ret; } + private CMO_STRING parse_OMSTR() throws IOException{ + CMO_STRING ret; + + exceptTokenTypeInParse(TT_StartTag); + if(!attribute.equals("OMSTR")){ + parse_error("We expect ''."); + } + + 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 ''."); + } + + return ret; + } + private CMO parse_symb_DMP() throws IOException{ parse_object(); return new CMO_DISTRIBUTED_POLYNOMIAL(new CMO_DMS_GENERIC(), @@ -388,10 +433,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; @@ -406,7 +452,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); } @@ -624,6 +670,12 @@ final class OM2OXM implements Runnable{ System.err.println((char)is.read()); }catch(IOException e){} System.exit(1); + } + + private void debug(String str){ + if(debug){ + System.err.println(str); + } } public static void main(String[] argv) throws IOException{