문제

i have that expression

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

now that are rpn rules

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

i added &&, ||, ~, in,

now, how it should change the RPN's rules?

***Update

That is my table of operators

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

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

"~"      3
"in"     3
")"      3
도움이 되었습니까?

해결책

The rules don't change for those additional operators. You just have to assign each operator the correct precedence. For example, && generally has lower precedence than most other operators, and || has lower precedence than &&.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top