C# Class ExpressionParser.RPNParser

Summary description for RPNParser.
Datei anzeigen Open project: IndiansIncredible/.NetIDS Class Usage Examples

Public Methods

Method Description
Convert2String ( ArrayList arrExpr ) : string
EvaluateExpression ( string szExpr, Type varType, bool bFormula, Hashtable htValues ) : object
EvaluateRPN ( ArrayList arrExpr, Type varType, Hashtable htValues ) : object

Algo of EvaluateRPN (source : Expression Evaluator : using RPN by lallous in the C++/MFC section of www.CodeProject.com. 1. Initialize stack for storing results, prepare input postfix (or RPN) expression. 2. Start scanning from left to right till we reach end of RPN expression 3. Get token, if token is: I. An operator: a. Get top of stack and store into variable op2; Pop the stack b. Get top of stack and store into variable op1; Pop the stack c. Do the operation expression in operator on both op1 and op2 d. Push the result into the stack II. An operand: stack its numerical representation into our numerical stack. 4. At the end of the RPN expression, the stack should only have one value and that should be the result and can be retrieved from the top of the stack.

GetPostFixNotation ( string szExpr, Type varType, bool bFormula ) : ArrayList

Algo of GetPostFixNotation (source : Expression Evaluator : using RPN by lallous in the C++/MFC section of www.CodeProject.com. 1. Initialize an empty stack (string stack), prepare input infix expression and clear RPN string 2. Repeat until we reach end of infix expression I. Get token (operand or operator); skip white spaces II. If token is: a. Left parenthesis: Push it into stack b. Right parenthesis: Keep popping from the stack and appending to RPN string until we reach the left parenthesis. If stack becomes empty and we didn't reach the left parenthesis then break out with error "Unbalanced parenthesis" c. Operator: If stack is empty or operator has a higher precedence than the top of the stack then push operator into stack. Else if operator has lower precedence then we keep popping and appending to RPN string, this is repeated until operator in stack has lower precedence than the current operator. d. An operand: we simply append it to RPN string. III. When the infix expression is finished, we start popping off the stack and appending to RPN string till stack becomes empty.

RPNParser ( ) : System

Method Details

Convert2String() public method

public Convert2String ( ArrayList arrExpr ) : string
arrExpr System.Collections.ArrayList
return string

EvaluateExpression() public method

public EvaluateExpression ( string szExpr, Type varType, bool bFormula, Hashtable htValues ) : object
szExpr string
varType System.Type
bFormula bool
htValues System.Collections.Hashtable
return object

EvaluateRPN() public method

Algo of EvaluateRPN (source : Expression Evaluator : using RPN by lallous in the C++/MFC section of www.CodeProject.com. 1. Initialize stack for storing results, prepare input postfix (or RPN) expression. 2. Start scanning from left to right till we reach end of RPN expression 3. Get token, if token is: I. An operator: a. Get top of stack and store into variable op2; Pop the stack b. Get top of stack and store into variable op1; Pop the stack c. Do the operation expression in operator on both op1 and op2 d. Push the result into the stack II. An operand: stack its numerical representation into our numerical stack. 4. At the end of the RPN expression, the stack should only have one value and that should be the result and can be retrieved from the top of the stack.
public EvaluateRPN ( ArrayList arrExpr, Type varType, Hashtable htValues ) : object
arrExpr System.Collections.ArrayList
varType System.Type
htValues System.Collections.Hashtable Values for each of the variables in the expression
return object

GetPostFixNotation() public method

Algo of GetPostFixNotation (source : Expression Evaluator : using RPN by lallous in the C++/MFC section of www.CodeProject.com. 1. Initialize an empty stack (string stack), prepare input infix expression and clear RPN string 2. Repeat until we reach end of infix expression I. Get token (operand or operator); skip white spaces II. If token is: a. Left parenthesis: Push it into stack b. Right parenthesis: Keep popping from the stack and appending to RPN string until we reach the left parenthesis. If stack becomes empty and we didn't reach the left parenthesis then break out with error "Unbalanced parenthesis" c. Operator: If stack is empty or operator has a higher precedence than the top of the stack then push operator into stack. Else if operator has lower precedence then we keep popping and appending to RPN string, this is repeated until operator in stack has lower precedence than the current operator. d. An operand: we simply append it to RPN string. III. When the infix expression is finished, we start popping off the stack and appending to RPN string till stack becomes empty.
public GetPostFixNotation ( string szExpr, Type varType, bool bFormula ) : ArrayList
szExpr string
varType System.Type
bFormula bool
return System.Collections.ArrayList

RPNParser() public method

public RPNParser ( ) : System
return System