adding cs235

This commit is contained in:
dm
2016-04-06 20:46:10 -07:00
parent 8e52ce1982
commit cf99ec6565
178 changed files with 13079 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
from collections import deque
op_prec = {
'*': 3,
'/': 3,
'%': 3,
'+': 2,
'-': 2,
}
def shunt(tokens):
tokens = deque(tokens)
output = deque()
operators = deque()
while tokens:
token = tokens.pop()
if token.isdigit():
output.append(token)
elif token in op_prec:
operators.append(token)
return output, operators
+10
View File
@@ -0,0 +1,10 @@
import unittest
from shunting import shunt
class ShuntTest(unittest.TestCase):
def test_simple_add(self):
o, s = shunt(['4', '+', '3'])
self.assertEquals(o, ['4', '3', '+'])