def getPlusSignOperatorStr(previousChar, nextChar):
    if (previousChar is None) & sI.isNumber(nextChar):
        return "PREFIX_PLUS"
    if (previousChar is None) & sI.isOperator(nextChar):
        return "PREFIX_PLUS"
    elif sI.isNumber(previousChar) | sI.isNumber(nextChar):
        return "INFIX_PLUS"
Esempio n. 2
0
def createAndPushTokenToStack(listIndex, expressionList, operandStack, operatorStack, previousToken):
    currentChar = expressionList[listIndex]
    if sI.isNumber(currentChar):  # formatNumber(number)
        token = operandT.createOperandToken(sI.formatNumber(sI.stringToNumber(currentChar)))
        st.pushStack(operandStack, token)
    elif sI.isOperator(currentChar):  # Raise exception when non operator detected
        token = operatorT.createOperatorToken(operatorT.getOperatorStrAffix(getCharFromToken(previousToken),
                                                                            expressionList[listIndex + 1],
                                                                            currentChar))
        st.pushStack(operatorStack, token)
    return token
Esempio n. 3
0
def createToken(listIndex, expressionList, previousToken):
    currentChar = expressionList[listIndex]
    if sI.isNumber(currentChar):  # formatNumber(number)
        token = operandT.createOperandToken(sI.formatNumber(sI.stringToNumber(currentChar)))
    elif sI.isOperator(currentChar):  # Raise exception when non operator detected, required next char to check get
        # affix
        token = operatorT.createOperatorToken(operatorT.getOperatorStrAffix(getCharFromToken(previousToken),
                                                                            expressionList[listIndex + 1],
                                                                            currentChar))

    token.tokenId = listIndex
    return token
Esempio n. 4
0
def createOperandToken(operandStr):
    if not sI.isNumber(
            operandStr):  # Verify whether the parameter str is number
        # Raise exception if parameter is not number
        raise ValueError(
            "Error: createOperandToken() received invalid operand str.")
    # Convert str to number, then format the numbe (remove decimal if it's int)
    token = OperandToken()
    token.num = sI.formatNumber(sI.stringToNumber(operandStr))
    token.numType = getNumberType(token.num)
    token.tokenType = "OPERAND_TOKEN"
    return token
 def test_c_isNumber_given_symbols_expect_false(self):
     # isNumber(expression)
     self.assertEqual(False, sI.isNumber("@!@$%"))
 def test_b_isNumber_given_12point111111_expect_true(self):
     # isNumber(expression)
     self.assertEqual(True, sI.isNumber("12.111111"))
 def test_a_isNumber_given_1112_expect_true(self):
     # isNumber(expression)
     self.assertEqual(True, sI.isNumber("1112"))