0.3.5 • Published 6 years ago

jsymbol v0.3.5

Weekly downloads
131
License
MIT
Repository
github
Last release
6 years ago

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();