Class ScriptMathProcessor

java.lang.Object
org.jmol.script.ScriptMathProcessor

public class ScriptMathProcessor extends Object
Reverse Polish Notation Engine for IF, SET, and @{...} Just a (not so simple?) RPN processor that can handle boolean, int, float, String, Point3f, BitSet, Array, Hashtable, Matrix3f, Matrix4f -- Bob Hanson 2/16/2007
Author:
hansonr
  • Field Details

    • wasX

      public boolean wasX
    • asBitSet

      public boolean asBitSet
    • oPt

      public int oPt
    • chk

      private boolean chk
    • wasSyntaxCheck

      private boolean wasSyntaxCheck
    • debugHigh

      private boolean debugHigh
    • eval

      private ScriptExpr eval
    • vwr

      private Viewer vwr
    • oStack

      private T[] oStack
    • xStack

      private SV[] xStack
    • ifStack

      private char[] ifStack
    • ifPt

      private int ifPt
    • xPt

      private int xPt
    • parenCount

      private int parenCount
    • squareCount

      private int squareCount
    • braceCount

      private int braceCount
    • isArrayItem

      private boolean isArrayItem
    • asVector

      private boolean asVector
    • haveSpaceBeforeSquare

      private boolean haveSpaceBeforeSquare
    • equalCount

      private int equalCount
    • ptid

      private int ptid
    • ptx

      private int ptx
    • pto

      private int pto
    • isSpecialAssignment

      private boolean isSpecialAssignment
    • doSelections

      private boolean doSelections
    • assignLeft

      private boolean assignLeft
    • allowUnderflow

      private boolean allowUnderflow
    • isAssignment

      private boolean isAssignment
    • skipping

      private boolean skipping
    • lastAssignedString

      private SV lastAssignedString
    • qMods

      private static final String qMods
      See Also:
  • Constructor Details

    • ScriptMathProcessor

      ScriptMathProcessor(ScriptExpr eval, boolean isSpecialAssignment, boolean isArrayItem, boolean asVector, boolean asBitSet, boolean allowUnderflow, String key)
      Parameters:
      eval -
      isSpecialAssignment - x[n] = ...
      isArrayItem -
      asVector - return a Lst(SV) from getResult()
      asBitSet - return a (SV)bitset
      allowUnderflow - expression can terminate prior to end of statement
      key -
  • Method Details

    • endAssignment

      public boolean endAssignment()
    • getResult

      SV getResult() throws ScriptException
      Throws:
      ScriptException
    • putX

      private void putX(SV x)
    • putOp

      private void putOp(T op)
    • putIf

      private void putIf(char c)
    • addXCopy

      public boolean addXCopy(SV x)
    • addX

      public boolean addX(SV x)
    • addXObj

      public boolean addXObj(Object x)
    • addXStr

      public boolean addXStr(String x)
    • addXBool

      public boolean addXBool(boolean x)
    • addXInt

      public boolean addXInt(int x)
    • addXList

      public boolean addXList(javajs.util.Lst<?> x)
    • addXMap

      public boolean addXMap(Map<String,?> x)
    • addXM3

      public boolean addXM3(javajs.util.M3 x)
    • addXM4

      public boolean addXM4(javajs.util.M4 x)
    • addXFloat

      public boolean addXFloat(float x)
    • addXBs

      public boolean addXBs(javajs.util.BS bs)
    • addXPt

      public boolean addXPt(javajs.util.P3 pt)
    • addXPt4

      public boolean addXPt4(javajs.util.P4 pt)
    • addXNum

      public boolean addXNum(T x) throws ScriptException
      Throws:
      ScriptException
    • addXAV

      public boolean addXAV(SV[] x)
    • addXAD

      public boolean addXAD(double[] x)
    • addXAS

      public boolean addXAS(String[] x)
    • addXAI

      public boolean addXAI(int[] x)
    • addXAII

      public boolean addXAII(int[][] x)
    • addXAF

      public boolean addXAF(float[] x)
    • addXAFF

      public boolean addXAFF(float[][] x)
    • isOpFunc

      private static boolean isOpFunc(T op)
    • addOp

      public boolean addOp(T op) throws ScriptException
      addOp The primary driver of the Reverse Polish Notation evaluation engine. This method loads operators onto the oStack[] and processes them based on a precedence system. Operands are added by addX() onto the xStack[]. We check here for syntax issues that were not caught in the compiler. I suppose that should be done at compilation stage, but this is how it is for now. The processing of functional arguments and (___?___:___) constructs is carried out by pushing markers onto the stacks that later can be used to fill argument lists or turn "skipping" on or off. Note that in the case of skipped sections of ( ? : ) no attempt is made to do syntax checking. [That's not entirely true -- when syntaxChecking is true, that is, when the user is typing at the Jmol application console, then this code is being traversed with dummy variables. That could be improved, for sure. Actually, there's plenty of room for improvement here. I did this based on what I learned in High School in 1974 -- 35 years ago! -- when I managed to build a mini FORTRAN compiler from scratch in machine code. That was fun. (This was fun, too.) -- Bob Hanson, hansonr@stolaf.edu 6/9/2009
      Parameters:
      op -
      Returns:
      false if an error condition arises
      Throws:
      ScriptException
    • addOpAllowMath

      boolean addOpAllowMath(T op, boolean allowMathFunc, int tokNext) throws ScriptException
      Throws:
      ScriptException
    • checkSkip

      private boolean checkSkip(T op, int tok0)
    • doSelection

      private boolean doSelection()
    • dumpStacks

      void dumpStacks(String message)
    • getX

      public SV getX() throws ScriptException
      Throws:
      ScriptException
    • getXTok

      public int getXTok()
    • evaluateFunction

      private boolean evaluateFunction(int tok) throws ScriptException
      Throws:
      ScriptException
    • operate

      private boolean operate() throws ScriptException
      Throws:
      ScriptException
    • binaryOp

      public boolean binaryOp(T op, SV x1, SV x2) throws ScriptException
      Throws:
      ScriptException
    • isDecimal

      private boolean isDecimal(SV x)
    • ptValue

      public javajs.util.P3 ptValue(SV x, javajs.util.BS bsRestrict) throws ScriptException
      Throws:
      ScriptException
    • typeOf

      private static String typeOf(SV x)
    • getAllProperties

      private boolean getAllProperties(SV x2, String abbr) throws ScriptException
      Throws:
      ScriptException
    • getMatrix4f

      public static javajs.util.M4 getMatrix4f(javajs.util.M3 matRotate, javajs.util.T3 vTranslate)
    • getBoundBox

      private boolean getBoundBox(SV x2)
    • getPointOrBitsetOperation

      private boolean getPointOrBitsetOperation(T op, SV x2) throws ScriptException
      Throws:
      ScriptException