波兰表示法规则添加“in”和运算符与逻辑

时间:2011-08-24 16:16:47

标签: c# algorithm rpn

我有那个表达

ratecode in ('EURV','EURA','EURB','EURO','CHUPin*+-da~') && ( sourcecode ~in ('FMFC','FM') || block == 'yes')

现在这是rpn规则

    /// 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. 

我添加&&,||,〜,in,

现在,它应该如何改变RPN的规则?

***更新

这是我的运营商表

Operator Priority
"+"      0
"-"      0
"&&"     0
"||"     0 

"/"      1
"*"      1
"=="     1
"("      1

"~"      3
"in"     3
")"      3

1 个答案:

答案 0 :(得分:2)

这些附加运营商的规则不会改变。您只需为每个运算符分配正确的优先级。例如,&&的优先级通常低于大多数其他运算符,||的优先级低于&&