Commits

Matt Bone committed 7e320e0

close, but have an off by one problem in this parser

  • Participants
  • Parent commits 5822f3d

Comments (0)

Files changed (1)

File in_py/parse_sexp.py

 def parse(tokens):
     
     stack = list()
-    stack.append(list())
+    top = None
     
     for token in tokens:
         print stack
         if isinstance(token, open_paren_token):
             if len(stack) == 0:
-                new_list = list()
-                stack.append(new_list)
+                top = list()
+                stack.append(top)
                 
             else:
                 new_list = list()
 
             stack[-1].append(Number(token.value))
 
-    if len(stack) != 1: raise syntax_exception("Unbalanced Parentheses")
+    if len(stack) != 0: raise syntax_exception("Unbalanced Parentheses")
     
-    return append_to[-1]
+    return top
 
 def sexp_to_tree():
     pass