jsymbol
v0.3.5
Published
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.
Downloads
158
Maintainers
Readme
jsymbol
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();