📄 operator.java
字号:
case (NAME_NE<<USED_BITS)|TYPE_FLOAT: case (NAME_NE<<USED_BITS)|TYPE_DATE: b_rez = ra1.notEqualTo(ra2); break; default: throw new EvaluateException("Unsupported datatypes for operators expression", sexp); } if( optype == NAME_LE || optype == NAME_LT || optype == NAME_GE || optype == NAME_GT || optype == NAME_EQ || optype == NAME_NE ) maxtype = TYPE_BOOLEAN; if( maxtype == TYPE_BOOLEAN ) { rez = BooleanAtom.createBoolean( b_rez ); } else if( maxtype == TYPE_SHORT ) { rez = ShortAtom.createShortAtom( i_rez ); } else if( maxtype == TYPE_LONG ) { rez = new LongAtom( l_rez ); } else if( maxtype == TYPE_FLOAT ) { rez = new FloatAtom( ra1 ); } else if( maxtype == TYPE_DATE ) { ra1.toDHMS(); rez = new DateAtom( ra1 ); } break; } } return rez; } /* * ============================================================== * Formula parser */ private static char buf[]; private static int nBuf; static final FunctorList createOper(NameObjectBase oper, LispObject _oper1, LispObject _oper2) { return new FunctorList2( oper, _oper1, _oper2 ); } static final FunctorList createOper1(NameObjectBase oper, LispObject _oper1) { return new FunctorList1( oper, _oper1 ); } private static final char get1() throws FormulaParseException { char c; try { while ((c = buf[nBuf++]) == ' ' || c == '\t' || c == '\n') { ; } } catch( ArrayIndexOutOfBoundsException ee ) { throw new FormulaParseException( "Invalid formula, unexpected end of string" ); } return c; } /** * Description of the Method */ private static final void unget1() { nBuf--; } /** * Gets the letter attribute of the Result class * *@param c Description of the Parameter *@return The letter value */ private static final boolean isLetter(char c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '_'); } /** * Description of the Method * *@param ss Description of the Parameter *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ synchronized public LispObject parseFormula(String ss) throws FormulaParseException { LispObject rr; // copy src to the char array try { int len = ss.length(); buf = new char[len + 1]; ss.getChars(0, len, buf, 0); buf[len] = '\0'; nBuf = 0; if (get1() == '=') { rr = f_comp(); if (get1() != '\0') { throw new FormulaParseException("Bad expression, expected end of string"); } } else { unget1(); try { rr = f_const(); if (get1() != '\0') { throw new FormulaParseException("Bad expression, expected end of string"); } // the constant isn't properly ended } catch (FormulaParseException e) { rr = new StringAtom( ss ); // will be a string then } } } finally { buf = null; } return rr; } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_comp() throws FormulaParseException { LispObject a,b; char c; a = f_add(); while ((c = get1()) == '=' || c == '<' || c == '>' || c == '!') { NameObjectBase oper = table[INDEX_EQ]; if (c == '!') { if (buf[nBuf++] != '=') { throw new FormulaParseException("Expected '!=' statement"); } oper = table[INDEX_NE]; } else if (c != '=') { if (buf[nBuf] == '=') { nBuf++; oper = table[c == '>' ? INDEX_GE : INDEX_LE]; } else { oper = table[c == '>' ? INDEX_GT : INDEX_LT]; } } b = f_add(); a = createOper(oper, a, b); } unget1(); return a; } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_add() throws FormulaParseException { LispObject a,b; char c; a = f_mul(); while ((c = get1()) == '+' || c == '-') { b = f_mul(); a = createOper(table[c == '+' ? INDEX_ADD : INDEX_SUB], a, b); } unget1(); return a; } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_mul() throws FormulaParseException { LispObject a,b; char c; a = f_uminus(); while ((c = get1()) == '*' || c == '/') { b = f_uminus(); a = createOper(table[c == '*' ? INDEX_MUL : INDEX_DIV], a, b); } unget1(); return a; } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_uminus() throws FormulaParseException { if (get1() == '-') { return createOper1(table[INDEX_UMIN], f_brackets()); } unget1(); return f_brackets(); } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_brackets() throws FormulaParseException { if (get1() == '(') { LispObject a = f_comp(); if (get1() != ')') { throw new FormulaParseException("missing ')'"); } return createOper1(table[INDEX_PARENTHIS], a); } unget1(); return f_name(); } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_const() throws FormulaParseException { char c; c = get1(); // skip spaces unget1(); if (c == '\'') { return f_const_string1(); } if (c == '-') { // we shouldn't produce expression tree here (I could parse to tree then calculate it) c = get1(); LispObject rr = f_const_numeric(); int type = rr.typeNumber(); if (type == TYPE_SHORT) { ShortAtom sa = (ShortAtom) rr; sa.value = (short)-sa.value; } if (type == TYPE_LONG) { LongAtom la = (LongAtom) rr; la.value = -la.value; } if (type == TYPE_FLOAT) { FloatAtom fa = (FloatAtom) rr; fa.value.neg(); } return rr; } if (//#ifdef ISDIGIT //# isDigit(c)//#else Character.isDigit(c)//#endif ) { // check if it's a date int nn = nBuf; while ((c = buf[nn++]) != '\0') { if (c == '/' || c == ':') { return f_const_date(); } } return f_const_numeric(); } StringBuffer sb = new StringBuffer(10); while ( isLetter(c = buf[nBuf++]) ||//#ifdef ISDIGIT //# isDigit(c) //#else Character.isDigit( c )//#endif ) { sb.append(c); } unget1(); String name = sb.toString()/*.toUpperCase()*/; if (name.equals("nil")) return NIL; if (name.compareTo("true") == 0) { return BooleanAtom.TRUE; } if (name.compareTo("false") == 0) { return BooleanAtom.FALSE; } throw new FormulaParseException("Expected a constant"); // not a constant } /** * Description of the Method * *@return Description of the Return Value *@exception BadFormulaException Description of the Exception */ private LispObject f_name() throws FormulaParseException { char c;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -