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.
npm install jsymbolsh
yarn add jsymbol
`
$3
`sh
npm install jsymbol --save
`
Usage
$3
`typescript
import { SymbolTable, AstSymbol } from "jsymbol";
let st: SymbolTable = new SymbolTable(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();
`
$3
`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();
``