|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.problets.domain.model.DomainModel
org.problets.domain.model.expression.Expression
public class Expression
Expression Creates an expression model from a string representation. Works efficiently even for trivial expressions
Field Summary | |
---|---|
static int |
IDENTITY
|
static int |
MAX_PRECEDENCE_LEVELS
|
Constructor Summary | |
---|---|
Expression(NodeModel inRoot)
Creates an expression of the given pre-constructed tree - used by ParenthesizedStudentNodeView to create a copy of the expression within parentheses |
|
Expression(java.lang.String inExpression)
Constructor for expressions involving only literal constants in standalone expressions, OR expressions created by getCode() method for printing purposes only (not evaluation) |
|
Expression(java.lang.String inExpression,
ActivationRecord inActivationRecord)
Constructor for expressions involving variables also |
Method Summary | |
---|---|
boolean |
containsOperator(java.lang.String operatorSymbol)
Returns true if the expression contains the operator, and false otherwise - Used by ExpressionViewExpert to generate explanation that LHS of &&/|| is evaluated before RHS. |
Value |
evaluate()
Meant to be used by code which wants only the expression to be evaluated and not any associated Scope Call Scope.preProcessFunctionCalls() before calling this, in order to handle embedded function calls |
Value |
evaluate(RunEnv runEnv,
Behavior behavior,
int codeLineNumber,
boolean stepFlag)
Called by expressions in code - ensures function calls are properly handled |
void |
explainObject(Behavior behavior,
int lineNumber)
This must be called after the expession is evaluated first. |
void |
explainPrinting(RunEnv runEnv,
Behavior behavior,
java.lang.String statement,
int event,
int lineNumber,
boolean abbreviate)
Method to explain expression in an output statement - assume this happens only in code, not standalone |
void |
explainProcess(RunEnv runEnv,
Behavior behavior,
java.lang.String statement,
int event,
int lineNumber,
boolean abbreviate)
Explains the execution of expressions in CODE, not standalone expressions. |
ActivationRecord |
getActivationRecord()
Returns a reference to the activation record for this expression if one exists |
void |
getCode(java.util.Vector codeText,
java.lang.String statement,
int lineNumber)
Adds the code for the expression to codeText and adds variables in the expression to the line objects for the line |
java.util.Vector |
getExpressionVariables()
Returns all the variables that participate in this expression so that they can be added as line objects for this line of code - when variables are initialized, in conditions of if/if-else and loops |
java.util.Vector |
getFunctionCalls()
Returns all the function calls in an expression as a vector of FunctionCallOperands |
int |
getNumOperators()
Returns the number of operators in this expression |
Operator |
getOperatorFromSymbol(java.lang.String currentToken,
boolean prefixFlag)
Given an operator symbol, returns the corresponding operator object |
java.lang.String |
getOperatorListString()
Returns a string representation of the operators in an expression, including operators in embedded parentheses |
java.util.Vector |
getOperatorPrecedenceTable()
Returns a Vector representing the precedence table of the operators for this expression - called by ExpressionTutor.explain(). |
static java.lang.String[] |
getPossibleErrors()
Method to return errors for variables May want to post-process based on Student Model |
java.util.Vector |
getPreliminaryCode()
Method that returns variable declarations that precede an expression as a vector of strings (not CodeLine objects) |
java.lang.String |
getProcessedExpression()
Returns the expression after replacing < with <<> for proper printing in code and explanation when the text is printed formatted |
NodeModel |
getRoot()
|
java.lang.String |
getType()
Returns the default data type - the returned value is reliable if the expression contains at least one variable - the default type is taken to be that of the variable |
static boolean |
grade(java.lang.String actualTemplate,
java.lang.String studentCode)
Grades studentCode according to actualTemplate and inserts explanation of grading into explanation |
boolean |
isArithmetic()
Returns true if this is an arithmetic expression, and false otherwise |
boolean |
isAssignment()
Returns true if this is an assignment expression, and false otherwise |
boolean |
isBitwise()
Returns true if this is a bit-wise expression, and false otherwise |
boolean |
isConstant()
|
static boolean |
isLiteralExpression(java.lang.String studentCode)
Method returns whether the studentCode is a literal expression that does not involve any variables, function calls, etc. |
boolean |
isLogical()
Returns true if this is a logical expression, and false otherwise |
boolean |
isRelational()
Returns true if this is a relational expression, and false otherwise |
static boolean |
isValidOperator(java.lang.String operator)
|
boolean |
isVariable()
|
static void |
main(java.lang.String[] args)
|
java.lang.String |
printExpression()
Returns the expression - appropriate for expression evaluation tutors where large whitespace is desired between operands |
static void |
sortExplanation(java.util.Vector explanation)
|
static java.util.Vector |
tokenize(java.lang.String statement)
|
java.lang.String |
toString()
Returns the expression - appropriate for printing expressions in explanation - not extra whitespaces to distract the reader |
Methods inherited from class org.problets.domain.model.DomainModel |
---|
clone, getId, getIdName |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAX_PRECEDENCE_LEVELS
public static final int IDENTITY
Constructor Detail |
---|
public Expression(java.lang.String inExpression)
public Expression(java.lang.String inExpression, ActivationRecord inActivationRecord)
public Expression(NodeModel inRoot)
Method Detail |
---|
public static java.util.Vector tokenize(java.lang.String statement)
public static boolean isValidOperator(java.lang.String operator)
public Operator getOperatorFromSymbol(java.lang.String currentToken, boolean prefixFlag)
public boolean isVariable()
public boolean isConstant()
public NodeModel getRoot()
public static java.lang.String[] getPossibleErrors()
public ActivationRecord getActivationRecord()
public java.lang.String getOperatorListString()
public int getNumOperators()
public java.util.Vector getOperatorPrecedenceTable()
public boolean isArithmetic()
public boolean isRelational()
public boolean isAssignment()
public boolean isLogical()
public boolean isBitwise()
public boolean containsOperator(java.lang.String operatorSymbol)
public java.util.Vector getExpressionVariables()
public java.lang.String getType()
public java.util.Vector getFunctionCalls()
public void getCode(java.util.Vector codeText, java.lang.String statement, int lineNumber)
public java.util.Vector getPreliminaryCode()
public Value evaluate()
public Value evaluate(RunEnv runEnv, Behavior behavior, int codeLineNumber, boolean stepFlag)
public static boolean grade(java.lang.String actualTemplate, java.lang.String studentCode)
public static boolean isLiteralExpression(java.lang.String studentCode)
public void explainProcess(RunEnv runEnv, Behavior behavior, java.lang.String statement, int event, int lineNumber, boolean abbreviate)
public void explainPrinting(RunEnv runEnv, Behavior behavior, java.lang.String statement, int event, int lineNumber, boolean abbreviate)
public void explainObject(Behavior behavior, int lineNumber)
public static void sortExplanation(java.util.Vector explanation)
public static void main(java.lang.String[] args)
public java.lang.String getProcessedExpression()
public java.lang.String printExpression()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |