📄 operator.java
字号:
c = get1(); if (c == '#') { LispObject rr = f_const_date(); if (get1() != '#') { throw new FormulaParseException("expected trailing '#' in date constant"); } return rr; } unget1(); if (c == '"') { return f_const_string(); } if (//#ifdef ISDIGIT //# isDigit(c)//#else Character.isDigit(c)//#endif ) { return f_const_numeric(); } StringBuffer sb = new StringBuffer(10); // address char prev = '\0'; while ( isLetter(c = buf[nBuf++]) ||//#ifdef ISDIGIT //# isDigit(c) ||//#else Character.isDigit(c) ||//#endif c == '-' || c == '$' || c == ':') { if( c == '-' ) { if( //#ifdef ISDIGIT //# isDigit(prev)//#else Character.isDigit(prev)//#endif ) break; } sb.append(c); prev = c; } unget1(); if (sb.length() <= 0) { throw new FormulaParseException("bad formula - expected a constant"); } String name = sb.toString()/*.toUpperCase()*/; if (get1() == '(') { // function Vector vv = new Vector(3); if ((c = get1()) != ')') { unget1(); } while (c != ')') { if (c == '\0') { throw new FormulaParseException("Missing ')' in function"); } vv.addElement(f_comp()); c = get1(); if (c != ',' && c != ')') { throw new FormulaParseException("Missing ')' in function"); } } int nn = vv.size(); LispObject funcargs[] = new LispObject[ nn+1 ]; try { funcargs[0] = ModuleHandler.MODULEHANDLER.createName( name ); } catch( EvaluateException ee ) { throw new FormulaParseException(ee.getMessage()); } for (int i = 0; i < nn; i++) { funcargs[i+1] = (LispObject) vv.elementAt(i); } return createFunctorList( funcargs ); } unget1(); if (name.equals("nil")) return NIL; if (name.compareTo("true") == 0) { return BooleanAtom.TRUE; } if (name.compareTo("false") == 0) { return BooleanAtom.FALSE; } // a nameobject (name) - must exists (in contary with lisp parser NameObjectBase nm = ModuleHandler.MODULEHANDLER.findNameInAllModules( name ); if( nm != null ) return nm; // cell address return Reference.parseAddress(name); } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private static LispObject f_const_string() throws FormulaParseException { char c; StringBuffer sb = new StringBuffer(20); nBuf++; // skip the first '"' while ((c = buf[nBuf++]) != '"') { if (c == '\0') { unget1(); break; } sb.append(c); } return new StringAtom(sb.toString()); } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private static LispObject f_const_string1() throws FormulaParseException { char c; StringBuffer sb = new StringBuffer(20); nBuf++; // skip the first '\'' while ((c = buf[nBuf]) != '\0') { nBuf++; sb.append(c); } return new StringAtom(sb.toString()); } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private static LispObject f_const_numeric() throws FormulaParseException { char c; boolean fDot = false; StringBuffer sb = new StringBuffer(30); if (buf[nBuf] == 'i' && buf[nBuf+1] == 'n' && buf[nBuf+2] == 'f') { nBuf += 3; return new FloatAtom( Real.INF ); } if (buf[nBuf] == 'n' && buf[nBuf+1] == 'a' && buf[nBuf+2] == 'a') { nBuf += 3; return new FloatAtom( Real.NAN ); } while (((c = buf[nBuf++]) >= '0' && c <= '9') || c == '.' ) { if( c == '.' ) fDot = true; sb.append(c); } if (c == 'e') { fDot = true; // no dot, but surely a floating point number sb.append(c); if ( buf[nBuf] == '-' ) sb.append(buf[nBuf++]); while ((c = buf[nBuf++]) >= '0' && c <= '9' ) sb.append(c); } String ss = sb.toString(); try { if (c == 'L' || c == 'l') { return new LongAtom( Long.parseLong(ss) ); } unget1(); if( !fDot ) { return ShortAtom.createShortAtom( Short.parseShort(ss) ); } return new FloatAtom( ss ); } catch( NumberFormatException ee ) { throw new FormulaParseException( "Cannot parse numeric constant" ); } } private final static String MSG_DATE = "bad date format (must be {DD/MM/YYYY|DDDD} [HH:MM] )"; /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private static LispObject f_const_date() throws FormulaParseException { char c; StringBuffer sb = new StringBuffer(20); while (((c = buf[nBuf++]) >= '0' && c <= '9') || c == '/' || c == ':' || c == ' ') { sb.append(c); } unget1(); String ss = sb.toString(); int nn1 = ss.indexOf('/'); int nn2 = ss.indexOf('/', nn1 + 1); int nn3 = ss.indexOf(' ', nn2 + 1); int nn4 = ss.indexOf(':', nn3 + 1); int day = 0; int month = 0; int year = 0; int hour = 0; int min = 0; try { if (nn1 > 0 && nn2 > 0) { day = Integer.parseInt(ss.substring(0, nn1)); month = Integer.parseInt(ss.substring(nn1 + 1, nn2)); year = Integer.parseInt(ss.substring(nn2 + 1, nn3 > 0 ? nn3 : ss.length())); if (day < 0 || day > 31 || month <= 0 || month > 12) { throw new FormulaParseException(MSG_DATE); } } else if (nn1 <= 0 && nn2 <= 0 && nn4 > 0) { day = Integer.parseInt(ss.substring(0,nn3)); // days hours minutes } else if (!ss.equals("")) { day = Integer.parseInt(ss); } else { return new DateAtom(); // date+time: now } if (nn4 > 0) { hour = Integer.parseInt(ss.substring(nn3 + 1, nn4)); min = Integer.parseInt(ss.substring(nn4 + 1)); } } catch (Exception e) { throw new FormulaParseException(MSG_DATE); } return new DateAtom( year, month, day, hour, min ); } class OperatorName extends ModuleName { String sign; // operator signature OperatorName(String _sign, int offset) { super(offset); sign = _sign; } // this - functor in FunctorList fl. // parent is upper operator in the tree, to output (), may be NULL public void toFormulaBuffer( StringBuffer sb, FunctorList fl ) { int size = fl.listSize(); if( offset == NAME_UMIN ) { sb.append( '-' ); } else if( offset == NAME_PARENTHIS ) { sb.append( '(' ); } for( int i=1; i<size; i++ ) { if( i != 1 ) sb.append( sign ); fl.getArgumentN(i).toFormulaBuffer( sb );// LispObject lo = value[i];// if( lo instanceof FunctorList ) {// FunctorList fl1 = (FunctorList) lo;// NameObject name = (NameObject) fl1.value[0]; // will throw an exception for QuotedList - bugfeature// if( name instanceof OperatorName ) {// // print as an operator// toFormulaBuffer( sb, fl1 );// }// else {// // print as a function// fl1.toFormulaBuffer( sb );// }// }// else {// // an atom// lo.toFormulaBuffer( sb );// } } if( offset == NAME_PARENTHIS ) { sb.append( ')' ); } } /* (non-Javadoc) * @see com.wapindustrial.calc.NameObjectBase#getMappedObject() */ public LispObject getMappedObject() { return Operator.OPERATOR; } } //#ifdef JAVA_COMPILER protected String getModuleClassName() { return "Operator"; }//#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -