npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

symbol-table

v1.3.2

Published

A data structure for tracking symbols in a compiler or interpreter.

Downloads

5

Readme

symbol-table

A data structure for tracking symbols in a compiler or interpreter.

var SymbolTable = require("symbol-table");

//create the root scope
var s0 = SymbolTable();

//define some symbols
s0.set("a", 1);
s0.set("b", 2);

//now enter a sub-scope that inherits s0
var s1 = s0.push();

//define/override symbols in the new scope
s1.set("b", 200);
s1.set("c", 300);

//s1 inherited "a"
s1.get("a");
//-> 1

//s1 changed "b"
s1.get("b");
//-> 200
//but s0 "b" was not touched
s0.get("b");
//-> 2

//s1 has "c", but s0 does not
s1.has("c");
//-> true
s0.has("c");
//-> false

API

s = SymbolTable()

Creates a new symbol table.

s.has(symbol)

Returns true if the symbol is in scope.

value = s.get(symbol)

Returns the value associated with that symbol in scope. Returns undefined if not found.

s.set(symbol, value)

Set the value associated with symbol. This can be anything you want. It can be another data structure if you need to store symbol values and type information for example.

s.unset(symbol)

Remove a symbol from a scope

s2 = s.push()

Return a new scope that inherits the current scope.

Stack

Create a stack of symbol tables/scopes where you always work with the current scope at the top of the stack. It has the same API as the symbol table except you push/pop the scope.

var SymbolTableStack = require("symbol-table/stack");

var s = SymbolTableStack();

s.set("a", 1);
s.push();

s.set("a", 2);
s.get("a");
//-> 2

s.pop();

s.get("a");
//-> 1

has, get, set, unset

These all work the same as the symbol table. However, it will always be the scope at the top of the stack.

table = s.push()

Creates a new table/scope and pushes it on top of the stack. It also returns the new table.

table = s.pop()

Pops the current table/scope off the stack.

i = s.height()

Get the stack height (initially it's 1)

i = s.getItsHeight(symbol)

What was the stack height when this symbol was set/defined? Returns undefined if the symbol is not found.

License

MIT