def f():      
		stream = StringStream(expression)
		_numberParser = NumberParser()
		_operatorParser = OperatorParser()

		number = _numberParser.parse(stream)		
		operator = _operatorParser.parse(stream)		
		number = _numberParser.parse(stream)		

		if stream.has_chars():
			return "Stream should now be empty"
Exemple #2
0
    def f():

        stream = StringStream(expression)

        _stack = ParserStack()
        _logic = ParserStackInteractor(_stack)
        _numberParser = NumberParser()
        _operatorParser = OperatorParser()

        _expressionParser = ExpressionParser(_logic, _numberParser,
                                             _operatorParser)
        result = _expressionParser.parse(stream)
        if not result.evaluate() == expectedResult:
            return "Result is: %s. \n object is: %s" % (str(
                result.evaluate()), str(result))
def testStream():
		stream = StringStream("1+1")
		
		def f():
			stream.peek()
			stream.next()
			stream.peek()
			stream.next()
			stream.peek()
			stream.peek()
			stream.peek()
			stream.next()
			stream.peek()
			stream.peek()

			if stream.has_chars():
				return "Stream should be empty"

		return utils.Test("Test that stream operators work", f)
Exemple #4
0
def evaluate(expressionString):
    stream = StringStream(expressionString)
    return parse(stream).evaluate()