-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmy_lisp.js
63 lines (61 loc) · 980 Bytes
/
my_lisp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
inlin=" (cdr '(a b))"
function getSexp(){
var a=getToken();
if (a=="'"){
return ["quote",getSexp()]
}
else if(a!="("){
return a;
}
a=[]
while(1){
b=getSexp()
if(b==")"){
return a;
}
a.push(b)
console.log(a);
}
}
i=0
function getToken(){
while ( nextChar() ==" "){
getChar();
}
a=getChar()
// if(a==")")
// {console.log("probel");}
// console.log("gets=",a)
if(a=="(")
return a
// console.log("ddd",nextChar())
while(nextChar()!=" " && nextChar()!="(" & nextChar()!=")" && nextChar()!=""){
a=a+getChar()
}
if(isNaN(a)){
return a
}
else{
// console.log("getting=",a);
// console.log("1=",typeof(a));
b=parseFloat(a);
//console.log("2",typeof(b));
// console.log(b);
return a
}
}
function nextChar(){
return inlin.slice(0,1);
}
function getChar(){
c=nextChar()
inlin=inlin.slice(1,inlin.length)
// console.log("c=",c,"inlin=",inlin);
return c
}
var j=0
while(inlin!=""){
var c=getSexp();
console.log(c)
j=j+1;
}