Created
October 30, 2018 00:41
-
-
Save sunary/2fb3657c2745dc247ead5f9aa8fb01fd to your computer and use it in GitHub Desktop.
lisp parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_from_tokens(tokens): | |
token = tokens.pop(0) | |
if token == '(': | |
L = [] | |
while tokens[0] != ')': | |
L.append(read_from_tokens(tokens)) | |
tokens.pop(0) | |
return L | |
elif token == ')': | |
raise SyntaxError('unexpected )') | |
else: | |
return token | |
tk = str.split('( + 1 ( * ( - 10 9 ) 2 ) )', ' ') | |
print read_from_tokens(tk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment