npm.io
0.3.5 • Published 8 years ago

jsymbol

Licence
MIT
Version
0.3.5
Deps
0
Size
141 kB
Vulns
0
Weekly
0
Stars
3

jsymbol

Build Status NPM version Coverage Status

Data structures for symbols and symbol table to be used in compilers/interpreters. Written in TypeScript and can be used in TypeScript and JavaScript projects.

Installation

Using yarn

yarn add jsymbol
Using npm
npm install jsymbol --save

Usage

TypeScript
import { SymbolTable, AstSymbol } from "jsymbol";

let st: SymbolTable<AstSymbol> = new SymbolTable<AstSymbol>(s => s.identifier);
let sym: AstSymbol = new AstSymbol("counter", "variable");   // symbol and its type

st.add(sym);

st.enterScope();
// assert: st.lookup("counter") === sym;

st.exitScope();
JavaScript
const jsymbol = require("jsymbol");

let st = new jsymbol.SymbolTable(s => s.identifier);
let sym = new jsymbol.AstSymbol("counter", "variable");

st.add(sym);

st.enterScope();
// assert: st.lookup("counter") === sym;

st.exitScope();

Keywords