⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lispstandard.java

📁 计算机代数系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        aTarget.Set(LispSubList.New(newList.Get()));      }      else      {        aTarget.Set(object.Copy(false));      }    }  }  public static String InternalUnstringify(String aOriginal) throws Exception  {    LispError.Check(aOriginal != null,LispError.KLispErrInvalidArg);    LispError.Check(aOriginal.charAt(0) == '\"',LispError.KLispErrInvalidArg);    int nrc=aOriginal.length()-1;    LispError.Check(aOriginal.charAt(nrc) == '\"',LispError.KLispErrInvalidArg);    return aOriginal.substring(1,nrc);  }  public static void DoInternalLoad(LispEnvironment aEnvironment,LispInput aInput) throws Exception  {    LispInput previous = aEnvironment.iCurrentInput;    try    {      aEnvironment.iCurrentInput = aInput;      // TODO make "EndOfFile" a global thing      // read-parse-eval to the end of file      String eof = aEnvironment.HashTable().LookUp("EndOfFile");      boolean endoffile = false;      InfixParser parser = new InfixParser(new LispTokenizer(),                         aEnvironment.iCurrentInput, aEnvironment,                         aEnvironment.iPrefixOperators, aEnvironment.iInfixOperators,                         aEnvironment.iPostfixOperators, aEnvironment.iBodiedOperators);      LispPtr readIn =new LispPtr();      while (!endoffile)      {        // Read expression        parser.Parse(readIn);        LispError.Check(readIn.Get() != null, LispError.KLispErrReadingFile);        // Check for end of file        if (readIn.Get().String() == eof)        {          endoffile = true;        }        // Else evaluate        else        {          LispPtr result = new LispPtr();          aEnvironment.iEvaluator.Eval(aEnvironment, result, readIn);        }      }    }    catch (Exception e)    {      throw e;    }    finally    {      aEnvironment.iCurrentInput = previous;    }  }  public static void InternalLoad(LispEnvironment aEnvironment,String aFileName) throws Exception  {    String oper = InternalUnstringify(aFileName);    String hashedname = aEnvironment.HashTable().LookUp(oper);    InputStatus oldstatus = new InputStatus(aEnvironment.iInputStatus);    aEnvironment.iInputStatus.SetTo(hashedname);    try    {      // Open file      LispInput newInput = // new StdFileInput(hashedname, aEnvironment.iInputStatus);          OpenInputFile(aEnvironment, aEnvironment.iInputDirectories, hashedname, aEnvironment.iInputStatus);            LispError.Check(newInput != null, LispError.KLispErrFileNotFound);      DoInternalLoad(aEnvironment,newInput);    }    catch (Exception e)    {      throw e;    }    finally    {      aEnvironment.iInputStatus.RestoreFrom(oldstatus);    }  }      public static void InternalUse(LispEnvironment aEnvironment,String aFileName) throws Exception  {    LispDefFile def = aEnvironment.iDefFiles.File(aFileName);    if (!def.IsLoaded())    {      def.SetLoaded();      InternalLoad(aEnvironment,aFileName);    }  }  static String PrintExpression(LispPtr aExpression,                      LispEnvironment aEnvironment,                      int aMaxChars) throws Exception  {    StringBuffer result = new StringBuffer();    StringOutput newOutput = new StringOutput(result);    InfixPrinter infixprinter = new InfixPrinter(aEnvironment.iPrefixOperators,                              aEnvironment.iInfixOperators,                              aEnvironment.iPostfixOperators,                              aEnvironment.iBodiedOperators);    infixprinter.Print(aExpression, newOutput, aEnvironment);    if (aMaxChars > 0 && result.length()>aMaxChars)    {      result.delete(aMaxChars,result.length());      result.append((char)'.');      result.append((char)'.');      result.append((char)'.');    }    return result.toString();  }  public static LispInput OpenInputFile(String aFileName, InputStatus aInputStatus) throws Exception  {    try    {      if (zipFile != null)      {        java.util.zip.ZipEntry e = zipFile.getEntry(aFileName);        if (e != null)        {          java.io.InputStream s = zipFile.getInputStream(e);          return new StdFileInput(s, aInputStatus);        }      }      if (aFileName.substring(0,4).equals("jar:"))      {        return new JarInputFile(aFileName, aInputStatus);      }      else      {        return new StdFileInput(aFileName, aInputStatus);      }    }    catch (Exception e)    {    }    return null;  }  public static LispInput OpenInputFile(LispEnvironment aEnvironment,      InputDirectories aInputDirectories, String aFileName,      InputStatus aInputStatus) throws Exception  {    String othername = aFileName;    int i = 0;    LispInput f = OpenInputFile(othername, aInputStatus);    while (f == null && i<aInputDirectories.size())    {      othername = ((String)aInputDirectories.get(i)) + aFileName;      f = OpenInputFile(othername, aInputStatus);      i++;    }    return f;  }  public static String InternalFindFile(String aFileName, InputDirectories aInputDirectories) throws Exception  {    InputStatus inputStatus = new InputStatus();    String othername = aFileName;    int i = 0;    LispInput f = OpenInputFile(othername, inputStatus);    if (f != null) return othername;    while (i<aInputDirectories.size())    {      othername = ((String)aInputDirectories.get(i)) + aFileName;      f = OpenInputFile(othername, inputStatus);      if (f != null) return othername;      i++;    }    return "";  }  public static java.util.zip.ZipFile zipFile = null;  private static void DoLoadDefFile(LispEnvironment aEnvironment, LispInput aInput,                            LispDefFile def) throws Exception  {    LispInput previous = aEnvironment.iCurrentInput;    try    {      aEnvironment.iCurrentInput = aInput;      String eof = aEnvironment.HashTable().LookUp("EndOfFile");      String end = aEnvironment.HashTable().LookUp("}");      boolean endoffile = false;      LispTokenizer tok = new LispTokenizer();      while (!endoffile)      {        // Read expression        String token = tok.NextToken(aEnvironment.iCurrentInput, aEnvironment.HashTable());        // Check for end of file        if (token == eof || token == end)        {            endoffile = true;        }        // Else evaluate        else        {            String str = token;            LispMultiUserFunction multiUser = aEnvironment.MultiUserFunction(str);            if (multiUser.iFileToOpen!=null)            {              throw new Yacasexception("["+str+"]"+"] : def file already chosen: "+multiUser.iFileToOpen.iFileName);            }            multiUser.iFileToOpen = def;        }      }    }    catch (Exception e)    {      throw e;    }    finally    {      aEnvironment.iCurrentInput = previous;    }  }  public static void LoadDefFile(LispEnvironment aEnvironment, String aFileName) throws Exception  {    LispError.LISPASSERT(aFileName!=null);    String flatfile = InternalUnstringify(aFileName) + ".def";    LispDefFile def = aEnvironment.iDefFiles.File(aFileName);//TODO remove    LispStringPtr contents = aEnvironment.FindCachedFile(flatfile.String());    String hashedname = aEnvironment.HashTable().LookUp(flatfile);    InputStatus oldstatus = aEnvironment.iInputStatus;    aEnvironment.iInputStatus.SetTo(hashedname);/*TODO remove    if (contents)    {        StringInput newInput(*contents,aEnvironment.iInputStatus);        DoLoadDefFile(aEnvironment, &newInput,def);        delete contents;    }    else*/    {      LispInput newInput = // new StdFileInput(hashedname, aEnvironment.iInputStatus);          OpenInputFile(aEnvironment, aEnvironment.iInputDirectories, hashedname, aEnvironment.iInputStatus);      LispError.Check(newInput != null, LispError.KLispErrFileNotFound);      DoLoadDefFile(aEnvironment, newInput,def);    }    aEnvironment.iInputStatus.RestoreFrom(oldstatus);  }  //////////////////////////////////////////////////  ///// bits_to_digits and digits_to_bits implementation  //////////////////////////////////////////////////  // lookup table for transforming the number of digits  static int log2_table_size = 32;  // report the table size  int log2_table_range()  {    return log2_table_size;  }  // A lookup table of Ln(n)/Ln(2) for n = 1 .. 32.  // With this we don't have to use math.h if all we need is to convert the number of digits from one base to another. This is also faster.  // Generated by: PrintList(N(Ln(1 .. 32)/Ln(2)), ",") at precision 40  static double log2_table[] =    {    0.,    1.,    1.5849625007211561814537389439478165087598,    2.,    2.3219280948873623478703194294893901758648,    2.5849625007211561814537389439478165087598,    2.807354922057604107441969317231830808641,    3.,    3.1699250014423123629074778878956330175196,    3.3219280948873623478703194294893901758648,    3.4594316186372972561993630467257929587032,    3.5849625007211561814537389439478165087598,    3.7004397181410921603968126542566947336284,    3.807354922057604107441969317231830808641,    3.9068905956085185293240583734372066846246,    4.,    4.0874628412503394082540660108104043540112,    4.1699250014423123629074778878956330175196,    4.2479275134435854937935194229068344226935,    4.3219280948873623478703194294893901758648,    4.3923174227787602888957082611796473174008,    4.4594316186372972561993630467257929587032,    4.5235619560570128722941482441626688444988,    4.5849625007211561814537389439478165087598,    4.6438561897747246957406388589787803517296,    4.7004397181410921603968126542566947336284,    4.7548875021634685443612168318434495262794,    4.807354922057604107441969317231830808641,    4.8579809951275721207197733246279847624768,    4.9068905956085185293240583734372066846246,    4.9541963103868752088061235991755544235489,    5.    };  // table look-up of small integer logarithms, for converting the number of digits to binary and back  static double log2_table_lookup(int n) throws Exception  {      if (n<=log2_table_size && n>=2)        return log2_table[n-1];      else      {        throw new Yacasexception("log2_table_lookup: error: invalid argument "+n);      }  }  // convert the number of digits in given base to the number of bits, and back.  // need to round the number of digits.  // to make sure that there is no hysteresis, we round upwards on digits_to_bits but round down on bits_to_digits  static long digits_to_bits(long digits, int base) throws Exception  {    return (long)Math.ceil(((double)digits)*log2_table_lookup(base));  }  static long bits_to_digits(long bits, int base) throws Exception  {    return (long)Math.floor(((double)bits)/log2_table_lookup(base));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -