org.jmol.viewer
Class Compiler

java.lang.Object
  extended by org.jmol.viewer.Compiler

 class Compiler
extends java.lang.Object


Nested Class Summary
private static class Compiler.FlowContext
           
 
Field Summary
private  Token[][] aatokenCompiled
           
(package private)  Token[] atokenInfix
           
private  int cchScript
           
private  int cchToken
           
private  java.util.Hashtable contextVariables
           
private static int ERROR_badArgumentCount
           
private static int ERROR_badContext
           
private static int ERROR_commandExpected
           
private static int ERROR_coordinateExpected
           
private static int ERROR_endOfCommandUnexpected
           
private static int ERROR_endOfExpressionExpected
           
private static int ERROR_identifierOrResidueSpecificationExpected
           
private static int ERROR_invalidAtomSpecification
           
private static int ERROR_invalidChainSpecification
           
private static int ERROR_invalidExpressionToken
           
private static int ERROR_invalidModelSpecification
           
private static int ERROR_missingEnd
           
private static int ERROR_numberExpected
           
private static int ERROR_numberOrVariableNameExpected
           
private static int ERROR_residueSpecificationExpected
           
private static int ERROR_tokenExpected
           
private static int ERROR_tokenUnexpected
           
private static int ERROR_unrecognizedExpressionToken
           
private static int ERROR_unrecognizedParameter
           
private static int ERROR_unrecognizedToken
           
private  java.lang.String errorLine
           
private  java.lang.String errorMessage
           
private static java.lang.String[] errors
           
private  java.lang.String filename
           
private  Compiler.FlowContext flowContext
           
(package private) static java.util.Hashtable globalFunctions
           
(package private)  boolean haveString
           
private  int ichCurrentCommand
           
private  int ichToken
           
private  int iCommand
           
private  boolean iHaveQuotedString
           
private  boolean isCheckOnly
           
(package private)  boolean isCommaAsOrAllowed
           
(package private)  boolean isEmbeddedExpression
           
(package private)  boolean isImplicitExpression
           
private  boolean isNewSet
           
private  boolean isSetBrace
           
(package private)  boolean isSetOrDefine
           
private  boolean isShowCommand
           
private  boolean isShowScriptOutput
           
private  boolean isSilent
           
(package private)  int itokenInfix
           
private  Token lastToken
           
private  short lineCurrent
           
private  int[] lineIndices
           
private  short[] lineNumbers
           
(package private) static java.lang.String[] loadFormats
           
(package private)  java.util.Hashtable localFunctions
           
private  boolean logMessages
           
private  java.util.Vector ltoken
           
(package private)  java.util.Vector ltokenPostfix
           
private  int nSemiSkip
           
private  boolean preDefining
           
private  int ptNewSetModifier
           
private  boolean residueSpecCodeGenerated
           
private  java.lang.String script
           
(package private)  Token theToken
           
(package private)  java.lang.Object theValue
           
private  Function thisFunction
           
(package private)  int tokCommand
           
(package private)  Token tokenCommand
           
private  Viewer viewer
           
 
Constructor Summary
Compiler(Viewer viewer)
           
 
Method Summary
private  void addContextVariable(java.lang.String ident)
           
(package private)  void addFunction(Function function)
           
private  boolean addNextToken()
           
private  boolean addNextTokenIf(int tok)
           
private  boolean addSubstituteTokenIf(int tok, Token token)
           
private  boolean addTokenToPostfix(int tok, int intValue, java.lang.Object value)
           
private  boolean addTokenToPostfix(int tok, java.lang.Object value)
           
private  boolean addTokenToPostfix(Token token)
           
private  void addTokenToPrefix(Token token)
           
private  boolean charToken()
           
private  boolean checkForCoordinate(boolean isImplicitExpression)
           
private  boolean checkForItemSelector()
           
private  boolean clauseAlternateSpec()
           
private  boolean clauseAnd()
           
private  boolean clauseAtomSpec()
           
private  boolean clauseCell()
           
private  boolean clauseChainSpec(int tok)
           
private  boolean clauseComparator()
           
private  boolean clauseConnected()
           
private  boolean clauseDefine()
           
private  boolean clauseItemSelector()
           
private  boolean clauseModelSpec()
           
private  boolean clauseNot()
           
private  boolean clauseOr(boolean allowComma)
           
private  boolean clausePrimitive()
           
private  boolean clauseResidueSpec()
           
private  boolean clauseResNameSpec()
           
private  boolean clauseSequenceSpec()
           
private  boolean clauseSubstructure()
           
private  boolean clauseWithin()
           
private static java.lang.String cleanScriptComments(java.lang.String script)
          allows for three kinds of comments.
private  boolean commandExpected()
           
(package private)  boolean compile(java.lang.String filename, java.lang.String script, boolean isPredefining, boolean isSilent, boolean debugScript, boolean isCheckOnly)
           
private  boolean compile0()
           
private  boolean compileCommand()
           
private  boolean compileExpression()
           
private  boolean eol(char ch)
           
private  boolean error(int error)
           
private  boolean error(int error, java.lang.String value)
           
private  boolean error(int error, java.lang.String value, java.lang.String more)
           
private  boolean error(java.lang.String errorMessage)
           
private  float floatValue()
           
private  boolean generateResidueSpecCode(Token token)
           
(package private)  Token[][] getAatokenCompiled()
           
private  Compiler.FlowContext getBreakableContext(int nLevelsUp)
           
(package private)  java.util.Hashtable getContextVariables()
           
private  boolean getData(java.lang.String key)
           
(package private)  java.lang.String getErrorMessage()
           
(package private) static int getHexitValue(char ch)
           
(package private)  int[] getLineIndices()
           
(package private)  short[] getLineNumbers()
           
private  boolean getNumericalToken()
           
(package private)  java.lang.String getScript()
           
private  Token getSequenceCode(boolean isSecond)
           
private  Token getToken()
          gets the next token and sets global theToken and theValue
(package private)  java.lang.String getUnescapedStringLiteral()
           
private  boolean handleError()
           
private  int intPeek()
           
private  boolean isExpressionNext()
           
(package private)  boolean isFunction(java.lang.String name)
           
private  boolean isLineContinuation(int ichT)
           
private static boolean isSpaceOrTab(char ch)
           
private  boolean isSpecTerminator(int tok)
           
private  boolean isToken(int tok)
           
(package private)  java.util.BitSet lookingAtBitset()
           
private  boolean lookingAtComment()
           
private  boolean lookingAtDecimal()
           
private  boolean lookingAtEndOfLine()
           
private  boolean lookingAtEndOfStatement()
           
private  float lookingAtExponential()
           
private  boolean lookingAtInteger()
           
private  boolean lookingAtLeadingWhitespace()
           
private  boolean lookingAtLoadFormat()
           
private  boolean lookingAtLookupToken()
           
private  boolean lookingAtObjectID(boolean allowWildID)
           
private  boolean lookingAtSeqcode()
           
private  boolean lookingAtSpecialString()
           
private  boolean lookingAtString()
           
(package private) static int modelValue(java.lang.String strDecimal)
           
private  boolean moreTokens()
           
private  boolean returnToken()
           
(package private) static void setErrorMessages()
           
private  int tokAt(int i)
           
(package private) static boolean tokAttr(int a, int b)
           
(package private) static boolean tokAttrOr(int a, int b1, int b2)
           
private static boolean tokenAttr(Token token, int tok)
           
private  Token tokenNext()
          increments the pointer; does NOT set theToken or theValue
private  boolean tokenNext(int tok)
           
private  int tokPeek()
           
private  boolean tokPeek(int tok)
           
private  java.lang.Object valuePeek()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localFunctions

java.util.Hashtable localFunctions

globalFunctions

static java.util.Hashtable globalFunctions

thisFunction

private Function thisFunction

viewer

private Viewer viewer

filename

private java.lang.String filename

script

private java.lang.String script

lineNumbers

private short[] lineNumbers

lineIndices

private int[] lineIndices

aatokenCompiled

private Token[][] aatokenCompiled

errorMessage

private java.lang.String errorMessage

errorLine

private java.lang.String errorLine

preDefining

private boolean preDefining

isSilent

private boolean isSilent

isShowScriptOutput

private boolean isShowScriptOutput

isCheckOnly

private boolean isCheckOnly

contextVariables

private java.util.Hashtable contextVariables

logMessages

private boolean logMessages

flowContext

private Compiler.FlowContext flowContext

nSemiSkip

private int nSemiSkip

cchScript

private int cchScript

lineCurrent

private short lineCurrent

ichToken

private int ichToken

cchToken

private int cchToken

iCommand

private int iCommand

ichCurrentCommand

private int ichCurrentCommand

isNewSet

private boolean isNewSet

isSetBrace

private boolean isSetBrace

ptNewSetModifier

private int ptNewSetModifier

iHaveQuotedString

private boolean iHaveQuotedString

ltoken

private java.util.Vector ltoken

lastToken

private Token lastToken

isShowCommand

private boolean isShowCommand

loadFormats

static java.lang.String[] loadFormats

isImplicitExpression

boolean isImplicitExpression

isSetOrDefine

boolean isSetOrDefine

tokenCommand

Token tokenCommand

tokCommand

int tokCommand

ltokenPostfix

java.util.Vector ltokenPostfix

atokenInfix

Token[] atokenInfix

itokenInfix

int itokenInfix

isEmbeddedExpression

boolean isEmbeddedExpression

isCommaAsOrAllowed

boolean isCommaAsOrAllowed

theToken

Token theToken

theValue

java.lang.Object theValue

haveString

boolean haveString

residueSpecCodeGenerated

private boolean residueSpecCodeGenerated

ERROR_badArgumentCount

private static final int ERROR_badArgumentCount
See Also:
Constant Field Values

ERROR_badContext

private static final int ERROR_badContext
See Also:
Constant Field Values

ERROR_commandExpected

private static final int ERROR_commandExpected
See Also:
Constant Field Values

ERROR_coordinateExpected

private static final int ERROR_coordinateExpected
See Also:
Constant Field Values

ERROR_endOfCommandUnexpected

private static final int ERROR_endOfCommandUnexpected
See Also:
Constant Field Values

ERROR_endOfExpressionExpected

private static final int ERROR_endOfExpressionExpected
See Also:
Constant Field Values

ERROR_identifierOrResidueSpecificationExpected

private static final int ERROR_identifierOrResidueSpecificationExpected
See Also:
Constant Field Values

ERROR_invalidAtomSpecification

private static final int ERROR_invalidAtomSpecification
See Also:
Constant Field Values

ERROR_invalidChainSpecification

private static final int ERROR_invalidChainSpecification
See Also:
Constant Field Values

ERROR_invalidExpressionToken

private static final int ERROR_invalidExpressionToken
See Also:
Constant Field Values

ERROR_invalidModelSpecification

private static final int ERROR_invalidModelSpecification
See Also:
Constant Field Values

ERROR_missingEnd

private static final int ERROR_missingEnd
See Also:
Constant Field Values

ERROR_numberExpected

private static final int ERROR_numberExpected
See Also:
Constant Field Values

ERROR_numberOrVariableNameExpected

private static final int ERROR_numberOrVariableNameExpected
See Also:
Constant Field Values

ERROR_residueSpecificationExpected

private static final int ERROR_residueSpecificationExpected
See Also:
Constant Field Values

ERROR_tokenExpected

private static final int ERROR_tokenExpected
See Also:
Constant Field Values

ERROR_tokenUnexpected

private static final int ERROR_tokenUnexpected
See Also:
Constant Field Values

ERROR_unrecognizedExpressionToken

private static final int ERROR_unrecognizedExpressionToken
See Also:
Constant Field Values

ERROR_unrecognizedParameter

private static final int ERROR_unrecognizedParameter
See Also:
Constant Field Values

ERROR_unrecognizedToken

private static final int ERROR_unrecognizedToken
See Also:
Constant Field Values

errors

private static java.lang.String[] errors
Constructor Detail

Compiler

Compiler(Viewer viewer)
Method Detail

isFunction

boolean isFunction(java.lang.String name)

addFunction

void addFunction(Function function)

compile

boolean compile(java.lang.String filename,
                java.lang.String script,
                boolean isPredefining,
                boolean isSilent,
                boolean debugScript,
                boolean isCheckOnly)

getScript

java.lang.String getScript()

getLineNumbers

short[] getLineNumbers()

getLineIndices

int[] getLineIndices()

getContextVariables

java.util.Hashtable getContextVariables()

addContextVariable

private void addContextVariable(java.lang.String ident)

getAatokenCompiled

Token[][] getAatokenCompiled()

tokAttr

static boolean tokAttr(int a,
                       int b)

tokAttrOr

static boolean tokAttrOr(int a,
                         int b1,
                         int b2)

modelValue

static int modelValue(java.lang.String strDecimal)

cleanScriptComments

private static java.lang.String cleanScriptComments(java.lang.String script)
allows for three kinds of comments. NOTE: closing involves two asterisks and slash together, but that can't be shown here. 1) /** .... ** / 2) /* ..... * / may be INSIDE /**....** /). 3) \n//.....\n single-line comments -- like #, but removed entirely The reason is that /* ... * / will appear as standard in MOVETO command but we still might want to escape it, so around that you can have /** .... ** / also,

Parameters:
script -
Returns:
cleaned script

addTokenToPrefix

private void addTokenToPrefix(Token token)

compile0

private boolean compile0()

getBreakableContext

private Compiler.FlowContext getBreakableContext(int nLevelsUp)

getData

private boolean getData(java.lang.String key)

isSpaceOrTab

private static boolean isSpaceOrTab(char ch)

eol

private boolean eol(char ch)

lookingAtLeadingWhitespace

private boolean lookingAtLeadingWhitespace()

isLineContinuation

private boolean isLineContinuation(int ichT)

lookingAtComment

private boolean lookingAtComment()

lookingAtEndOfLine

private boolean lookingAtEndOfLine()

lookingAtEndOfStatement

private boolean lookingAtEndOfStatement()

lookingAtString

private boolean lookingAtString()

getUnescapedStringLiteral

java.lang.String getUnescapedStringLiteral()

getHexitValue

static int getHexitValue(char ch)

lookingAtLoadFormat

private boolean lookingAtLoadFormat()

lookingAtSpecialString

private boolean lookingAtSpecialString()

lookingAtExponential

private float lookingAtExponential()

lookingAtDecimal

private boolean lookingAtDecimal()

lookingAtSeqcode

private boolean lookingAtSeqcode()

lookingAtInteger

private boolean lookingAtInteger()

lookingAtBitset

java.util.BitSet lookingAtBitset()

lookingAtObjectID

private boolean lookingAtObjectID(boolean allowWildID)

lookingAtLookupToken

private boolean lookingAtLookupToken()

charToken

private boolean charToken()

compileCommand

private boolean compileCommand()

compileExpression

private boolean compileExpression()

isExpressionNext

private boolean isExpressionNext()

tokenAttr

private static boolean tokenAttr(Token token,
                                 int tok)

moreTokens

private boolean moreTokens()

tokAt

private int tokAt(int i)

tokPeek

private int tokPeek()

tokPeek

private boolean tokPeek(int tok)

intPeek

private int intPeek()

valuePeek

private java.lang.Object valuePeek()

tokenNext

private Token tokenNext()
increments the pointer; does NOT set theToken or theValue

Returns:
the next token

tokenNext

private boolean tokenNext(int tok)

returnToken

private boolean returnToken()

getToken

private Token getToken()
gets the next token and sets global theToken and theValue

Returns:
the next token

isToken

private boolean isToken(int tok)

getNumericalToken

private boolean getNumericalToken()

floatValue

private float floatValue()

addTokenToPostfix

private boolean addTokenToPostfix(int tok,
                                  java.lang.Object value)

addTokenToPostfix

private boolean addTokenToPostfix(int tok,
                                  int intValue,
                                  java.lang.Object value)

addTokenToPostfix

private boolean addTokenToPostfix(Token token)

addNextToken

private boolean addNextToken()

addNextTokenIf

private boolean addNextTokenIf(int tok)

addSubstituteTokenIf

private boolean addSubstituteTokenIf(int tok,
                                     Token token)

clauseOr

private boolean clauseOr(boolean allowComma)

clauseAnd

private boolean clauseAnd()

clauseNot

private boolean clauseNot()

clausePrimitive

private boolean clausePrimitive()

checkForCoordinate

private boolean checkForCoordinate(boolean isImplicitExpression)

checkForItemSelector

private boolean checkForItemSelector()

clauseWithin

private boolean clauseWithin()

clauseConnected

private boolean clauseConnected()

clauseSubstructure

private boolean clauseSubstructure()

clauseItemSelector

private boolean clauseItemSelector()

clauseComparator

private boolean clauseComparator()

clauseCell

private boolean clauseCell()

clauseDefine

private boolean clauseDefine()

generateResidueSpecCode

private boolean generateResidueSpecCode(Token token)

clauseResidueSpec

private boolean clauseResidueSpec()

clauseResNameSpec

private boolean clauseResNameSpec()

clauseSequenceSpec

private boolean clauseSequenceSpec()

getSequenceCode

private Token getSequenceCode(boolean isSecond)

clauseChainSpec

private boolean clauseChainSpec(int tok)

isSpecTerminator

private boolean isSpecTerminator(int tok)

clauseAlternateSpec

private boolean clauseAlternateSpec()

clauseModelSpec

private boolean clauseModelSpec()

clauseAtomSpec

private boolean clauseAtomSpec()

setErrorMessages

static void setErrorMessages()

commandExpected

private boolean commandExpected()

error

private boolean error(int error)

error

private boolean error(int error,
                      java.lang.String value)

error

private boolean error(int error,
                      java.lang.String value,
                      java.lang.String more)

error

private boolean error(java.lang.String errorMessage)

getErrorMessage

java.lang.String getErrorMessage()

handleError

private boolean handleError()