Created
October 19, 2010 06:34
-
-
Save masahitojp/633721 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function tokenize(str) { | |
str=str.replace(/\(/g,"( "); | |
str=str.replace(/\)/g," )"); | |
arr = str.split(' '); | |
return arr; | |
} | |
function InputToLObject(arr){ | |
var rtn; | |
if(arr[0] == "("){ | |
rtn = InputToList(arr); | |
} | |
else if(isFinite(arr[0])){ | |
rtn = Number(arr.shift()); | |
} | |
else{ | |
rtn = arr.shift(); | |
} | |
return rtn; | |
} | |
function InputToList(arr){ | |
var list = []; | |
arr.shift(); | |
while(arr[0] != ")"){ | |
list.push(InputToLObject(arr)); | |
} | |
arr.shift(); | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment