symtable.js
An imperative symbol table library in Javascript
Installation
Requires ES6.
npm install symtable.js
Usage
var Symtable = ; var globalIds = ;globalIds;globalIds; // Initialize a new symbol table with a map of symbols in the global scope.var S = globalIds; // Start a new nested scopeS; // Add a symbol to the tableS;S; // Find the value of a SymbolS; // 3S; // null // Check the current scope for a given symbolS; // trueS; // false. Since this exists in the global scope and the current scope. // Exit the current scopeS;
API
-
enterScope()
- Start a new nested scope. -
add(x, y)
- Add a new symbolx
with associated datay
. -
find(x)
- Finds currentx
in the whole symbol table using the most closely nested rule. Returnsnull
otherwise. -
checkScope(x)
- Returnstrue
ifx
is defined in the current scope. -
exitScope()
- Exit the current scope