ScriptMathProcessor
Date: 2019-10-22

org.jmol.script

## Class ScriptMathProcessor

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

-     public class ScriptMathProcessor
      extends java.lang.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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private boolean` | `allowUnderflow`
    `boolean` | `asBitSet`
    `private boolean` | `assignLeft`
    `private boolean` | `asVector`
    `private int` | `braceCount`
    `private boolean` | `chk`
    `private boolean` | `debugHigh`
    `private boolean` | `doSelections`
    `private int` | `equalCount`
    `private ScriptExpr` | `eval`
    `private boolean` | `haveSpaceBeforeSquare`
    `private int` | `ifPt`
    `private char[]` | `ifStack`
    `private boolean` | `isArrayItem`
    `private boolean` | `isAssignment`
    `private boolean` | `isSpecialAssignment`
    `private SV` | `lastAssignedString`
    `int` | `oPt`
    `private T[]` | `oStack`
    `private int` | `parenCount`
    `private int` | `ptid`
    `private int` | `pto`
    `private int` | `ptx`
    `private static java.lang.String` | `qMods`
    `private boolean` | `skipping`
    `private int` | `squareCount`
    `private Viewer` | `vwr`
    `private boolean` | `wasSyntaxCheck`
    `boolean` | `wasX`
    `private int` | `xPt`
    `private SV[]` | `xStack`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ScriptMathProcessor(ScriptExpr eval, boolean isSpecialAssignment, boolean isArrayItem, boolean asVector, boolean asBitSet, boolean allowUnderflow, java.lang.String key)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `addOp(T op)` addOp The primary driver of the Reverse Polish Notation evaluation engine.
    `(package private) boolean` | `addOpAllowMath(T op, boolean allowMathFunc, int tokNext)`
    `boolean` | `addX(SV x)`
    `boolean` | `addXAD(double[] x)`
    `boolean` | `addXAF(float[] x)`
    `boolean` | `addXAFF(float[][] x)`
    `boolean` | `addXAI(int[] x)`
    `boolean` | `addXAII(int[][] x)`
    `boolean` | `addXAS(java.lang.String[] x)`
    `boolean` | `addXAV(SV[] x)`
    `boolean` | `addXBool(boolean x)`
    `boolean` | `addXBs(javajs.util.BS bs)`
    `boolean` | `addXCopy(SV x)`
    `boolean` | `addXFloat(float x)`
    `boolean` | `addXInt(int x)`
    `boolean` | `addXList(javajs.util.Lst<?> x)`
    `boolean` | `addXM3(javajs.util.M3 x)`
    `boolean` | `addXM4(javajs.util.M4 x)`
    `boolean` | `addXMap(java.util.Map<java.lang.String,?> x)`
    `boolean` | `addXNum(T x)`
    `boolean` | `addXObj(java.lang.Object x)`
    `boolean` | `addXPt(javajs.util.P3 pt)`
    `boolean` | `addXPt4(javajs.util.P4 pt)`
    `boolean` | `addXStr(java.lang.String x)`
    `boolean` | `binaryOp(T op, SV x1, SV x2)`
    `private boolean` | `checkSkip(T op, int tok0)`
    `private boolean` | `doSelection()`
    `(package private) void` | `dumpStacks(java.lang.String message)`
    `boolean` | `endAssignment()`
    `private boolean` | `evaluateFunction(int tok)`
    `private boolean` | `getAllProperties(SV x2, java.lang.String abbr)`
    `private boolean` | `getBoundBox(SV x2)`
    `static javajs.util.M4` | `getMatrix4f(javajs.util.M3 matRotate, javajs.util.T3 vTranslate)`
    `private boolean` | `getPointOrBitsetOperation(T op, SV x2)`
    `(package private) SV` | `getResult()`
    `SV` | `getX()`
    `int` | `getXTok()`
    `private boolean` | `isDecimal(SV x)`
    `private static boolean` | `isOpFunc(T op)`
    `private boolean` | `operate()`
    `javajs.util.P4` | `planeValue(T x)`
    `javajs.util.P3` | `ptValue(SV x, javajs.util.BS bsRestrict)`
    `private void` | `putIf(char c)`
    `private void` | `putOp(T op)`
    `private void` | `putX(SV x)`
    `private static java.lang.String` | `typeOf(SV x)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### 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 java.lang.String qMods

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ScriptMathProcessor

          ScriptMathProcessor(ScriptExpr eval,
                              boolean isSpecialAssignment,
                              boolean isArrayItem,
                              boolean asVector,
                              boolean asBitSet,
                              boolean allowUnderflow,
                              java.lang.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 Detail

    - #### 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(java.lang.Object x)

    - #### addXStr

          public boolean addXStr(java.lang.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(java.util.Map<java.lang.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(java.lang.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(java.lang.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`

    - #### planeValue

          public javajs.util.P4 planeValue(T x)

    - #### typeOf

          private static java.lang.String typeOf(SV x)

    - #### getAllProperties

          private boolean getAllProperties(SV x2,
                                           java.lang.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`