symtable.js
An imperative symbol table library in Javascript
Installation
Requires ES6.
npm install symtable.js
Usage
var Symtable = require('symtable.js');
var globalIds = new Map();
globalIds.set('window', 1);
globalIds.set('document', 2);
var S = new Symtable(globalIds);
S.enterScope();
S.add('a', '3');
S.add('b', 4);
S.find('a');
S.find('k');
S.checkScope('a');
S.checkScope('window');
S.exitScope();
API
-
enterScope()
- Start a new nested scope.
-
add(x, y)
- Add a new symbol x
with associated data y
.
-
find(x)
- Finds current x
in the whole symbol table using the most closely nested rule. Returns null
otherwise.
-
checkScope(x)
- Returns true
if x
is defined in the current scope.
-
exitScope()
- Exit the current scope