tcl.lang
Class Expression

java.lang.Object
  extended by tcl.lang.Expression

public class Expression
extends Object

This class handles Tcl expressions.


Field Summary
static int AND
           
static int BIT_AND
           
static int BIT_NOT
           
static int BIT_OR
           
static int BIT_XOR
           
static int CLOSE_PAREN
           
static int COLON
           
static int COMMA
           
static int DIVIDE
           
static int END
           
static int EQUAL
           
static int GEQ
           
static int GREATER
           
static int LEFT_SHIFT
           
static int LEQ
           
static int LESS
           
 HashMap<String,tcl.lang.MathFunction> mathFuncTable
          Maps name of function to its implementation
static int MINUS
           
static int MOD
           
static int MULT
           
static int NEQ
           
static int NOT
           
static int OPEN_PAREN
           
static String[] operatorStrings
          Mapping from operator numbers to strings; used for error messages.
static int OR
           
static int PLUS
           
static int[] precTable
          Precedence table.
static int QUESTY
           
static int RIGHT_SHIFT
           
static int STREQ
           
static int STRNEQ
           
static int UNARY_MINUS
           
static int UNARY_PLUS
           
static int UNKNOWN
           
static int VALUE
           
 
Constructor Summary
Expression()
          Constructor.
 
Method Summary
static void evalBinaryOperator(Interp interp, int operator, ExprValue value, ExprValue value2)
           
 boolean evalBoolean(Interp interp, String string)
          Evaluate an Tcl expression.
 void evalMathFunction(Interp interp, String funcName, ExprValue[] values, boolean releaseValues, ExprValue result)
          This procedure will lookup and invoke a math function given the name of the function and an array of ExprValue arguments.
 void evalSetResult(Interp interp, String string)
          Evaluate a Tcl expression and set the interp result to the value.
static void evalUnaryOperator(Interp interp, int operator, ExprValue value)
           
static void ExprParseObject(Interp interp, TclObject obj, ExprValue value)
          Given a TclObject, such as the result of a command or variable evaluation, fill in a ExprValue with the parsed result.
static void ExprParseString(Interp interp, TclObject obj, ExprValue value)
          TclParseNumber -> ExprParseString Given a TclObject that contains a String to be parsed (from a command or variable subst), fill in an ExprValue based on the string's numeric value.
 ExprValue grabExprValue()
           
static void IntegerTooLarge(Interp interp)
           
static boolean looksLikeInt(String s, int len, int i, boolean whole)
          This procedure decides whether the leading characters of a string look like an integer or something else (such as a floating-point number or string).
 void releaseExprValue(ExprValue val)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE

public static final int VALUE
See Also:
Constant Field Values

OPEN_PAREN

public static final int OPEN_PAREN
See Also:
Constant Field Values

CLOSE_PAREN

public static final int CLOSE_PAREN
See Also:
Constant Field Values

COMMA

public static final int COMMA
See Also:
Constant Field Values

END

public static final int END
See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
See Also:
Constant Field Values

MULT

public static final int MULT
See Also:
Constant Field Values

DIVIDE

public static final int DIVIDE
See Also:
Constant Field Values

MOD

public static final int MOD
See Also:
Constant Field Values

PLUS

public static final int PLUS
See Also:
Constant Field Values

MINUS

public static final int MINUS
See Also:
Constant Field Values

LEFT_SHIFT

public static final int LEFT_SHIFT
See Also:
Constant Field Values

RIGHT_SHIFT

public static final int RIGHT_SHIFT
See Also:
Constant Field Values

LESS

public static final int LESS
See Also:
Constant Field Values

GREATER

public static final int GREATER
See Also:
Constant Field Values

LEQ

public static final int LEQ
See Also:
Constant Field Values

GEQ

public static final int GEQ
See Also:
Constant Field Values

EQUAL

public static final int EQUAL
See Also:
Constant Field Values

NEQ

public static final int NEQ
See Also:
Constant Field Values

BIT_AND

public static final int BIT_AND
See Also:
Constant Field Values

BIT_XOR

public static final int BIT_XOR
See Also:
Constant Field Values

BIT_OR

public static final int BIT_OR
See Also:
Constant Field Values

AND

public static final int AND
See Also:
Constant Field Values

OR

public static final int OR
See Also:
Constant Field Values

QUESTY

public static final int QUESTY
See Also:
Constant Field Values

COLON

public static final int COLON
See Also:
Constant Field Values

STREQ

public static final int STREQ
See Also:
Constant Field Values

STRNEQ

public static final int STRNEQ
See Also:
Constant Field Values

UNARY_MINUS

public static final int UNARY_MINUS
See Also:
Constant Field Values

UNARY_PLUS

public static final int UNARY_PLUS
See Also:
Constant Field Values

NOT

public static final int NOT
See Also:
Constant Field Values

BIT_NOT

public static final int BIT_NOT
See Also:
Constant Field Values

precTable

public static int[] precTable
Precedence table. The values for non-operator token types are ignored.


operatorStrings

public static String[] operatorStrings
Mapping from operator numbers to strings; used for error messages.


mathFuncTable

public HashMap<String,tcl.lang.MathFunction> mathFuncTable
Maps name of function to its implementation

Constructor Detail

Expression

public Expression()
Constructor.

Method Detail

evalSetResult

public void evalSetResult(Interp interp,
                          String string)
                   throws TclException
Evaluate a Tcl expression and set the interp result to the value.

Parameters:
interp - the context in which to evaluate the expression.
string - expression to evaluate.
Throws:
TclException - for malformed expressions.

evalBoolean

public boolean evalBoolean(Interp interp,
                           String string)
                    throws TclException
Evaluate an Tcl expression.

Parameters:
interp - the context in which to evaluate the expression.
string - expression to evaluate.
Returns:
the value of the expression in boolean.
Throws:
TclException - for malformed expressions.

IntegerTooLarge

public static void IntegerTooLarge(Interp interp)
                            throws TclException
Throws:
TclException

ExprParseObject

public static void ExprParseObject(Interp interp,
                                   TclObject obj,
                                   ExprValue value)
                            throws TclException
Given a TclObject, such as the result of a command or variable evaluation, fill in a ExprValue with the parsed result. If the TclObject already has an internal rep that is a numeric type, then no need to parse from the string rep. If the string rep is parsed into a numeric type, then update the internal rep of the object to the parsed value.

Throws:
TclException

ExprParseString

public static void ExprParseString(Interp interp,
                                   TclObject obj,
                                   ExprValue value)
TclParseNumber -> ExprParseString Given a TclObject that contains a String to be parsed (from a command or variable subst), fill in an ExprValue based on the string's numeric value. The value may be a floating-point, an integer, or a string. If the string value is converted to a numeric value, then update the internal rep of the TclObject.

Parameters:
interp - the context in which to evaluate the expression.
obj - the TclObject containing the string to parse.
value - the ExprValue object to save the parsed value in.

evalUnaryOperator

public static void evalUnaryOperator(Interp interp,
                                     int operator,
                                     ExprValue value)
                              throws TclException
Throws:
TclException

evalBinaryOperator

public static void evalBinaryOperator(Interp interp,
                                      int operator,
                                      ExprValue value,
                                      ExprValue value2)
                               throws TclException
Throws:
TclException

evalMathFunction

public void evalMathFunction(Interp interp,
                             String funcName,
                             ExprValue[] values,
                             boolean releaseValues,
                             ExprValue result)
                      throws TclException
This procedure will lookup and invoke a math function given the name of the function and an array of ExprValue arguments. Each ExprValue is released before the function exits. This method is intended to be used by other modules that may need to invoke a math function at runtime. It is assumed that the caller has checked the number of arguments, the type of the arguments will be adjusted before invocation if needed. The values argument can be null when there are no args to pass. The releaseValues argument should be true when the ExprValue objecys in the array should be released.

Throws:
TclException

looksLikeInt

public static boolean looksLikeInt(String s,
                                   int len,
                                   int i,
                                   boolean whole)
This procedure decides whether the leading characters of a string look like an integer or something else (such as a floating-point number or string). If the whole flag is true then the entire string must look like an integer.

Returns:
a boolean value indicating if the string looks like an integer.

grabExprValue

public final ExprValue grabExprValue()

releaseExprValue

public final void releaseExprValue(ExprValue val)


Copyright © 2015. All rights reserved.