-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.js
45 lines (41 loc) · 1.11 KB
/
stack.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
var SymbolTable = require("./");
module.exports = function(){
var symt_stack = [SymbolTable()];
return {
set: function(symbol, value){
return symt_stack[0].set(symbol, {
value: value,
height: symt_stack.length,
}).value;
},
get: function(symbol){
var v = symt_stack[0].get(symbol);
return v
? v.value
: void 0;
},
has: function(symbol){
return symt_stack[0].has(symbol);
},
unset: function(symbol){
return symt_stack[0].unset(symbol);
},
push: function(){
var table = symt_stack[0].push();
symt_stack.unshift(table);
return table;
},
pop: function(){
return symt_stack.shift();
},
height: function(){
return symt_stack.length;
},
getItsHeight: function(symbol){
var v = symt_stack[0].get(symbol);
return v
? v.height
: void 0;
},
};
};