https://github.com/skepticfx/symtable.js
An imperative symbol table library in JavaScript
https://github.com/skepticfx/symtable.js
Last synced: 9 months ago
JSON representation
An imperative symbol table library in JavaScript
- Host: GitHub
- URL: https://github.com/skepticfx/symtable.js
- Owner: skepticfx
- License: mit
- Created: 2015-09-11T01:32:18.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-08-12T18:49:52.000Z (over 6 years ago)
- Last Synced: 2025-02-23T18:05:52.438Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# symtable.js
An imperative symbol table library in Javascript
## Installation
###### Requires ES6.
`npm install symtable.js`
## Usage
```javascript
var Symtable = require('symtable.js');
var globalIds = new Map();
globalIds.set('window', 1);
globalIds.set('document', 2);
// Initialize a new symbol table with a map of symbols in the global scope.
var S = new Symtable(globalIds);
// Start a new nested scope
S.enterScope();
// Add a symbol to the table
S.add('a', '3');
S.add('b', 4);
// Find the value of a Symbol
S.find('a'); // 3
S.find('k'); // null
// Check the current scope for a given symbol
S.checkScope('a'); // true
S.checkScope('window'); // false. Since this exists in the global scope and the current scope.
// Exit the current scope
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