{"id":22710546,"url":"https://github.com/smallhelm/symbol-table","last_synced_at":"2025-08-07T15:31:24.602Z","repository":{"id":65511451,"uuid":"62313149","full_name":"smallhelm/symbol-table","owner":"smallhelm","description":"A data structure for tracking symbols in a compiler or interpreter.","archived":false,"fork":false,"pushed_at":"2023-03-08T04:38:05.000Z","size":19,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-09T09:21:17.641Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smallhelm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-30T13:34:03.000Z","updated_at":"2023-02-19T08:25:46.000Z","dependencies_parsed_at":"2023-01-26T18:45:24.749Z","dependency_job_id":null,"html_url":"https://github.com/smallhelm/symbol-table","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Fsymbol-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Fsymbol-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Fsymbol-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallhelm%2Fsymbol-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallhelm","download_url":"https://codeload.github.com/smallhelm/symbol-table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228924422,"owners_count":17992693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-10T12:10:28.233Z","updated_at":"2024-12-10T12:10:28.820Z","avatar_url":"https://github.com/smallhelm.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# symbol-table\n\nA data structure for tracking symbols in a compiler or interpreter.\n\n```js\nvar SymbolTable = require(\"symbol-table\");\n\n//create the root scope\nvar s0 = SymbolTable();\n\n//define some symbols\ns0.set(\"a\", 1);\ns0.set(\"b\", 2);\n\n//now enter a sub-scope that inherits s0\nvar s1 = s0.push();\n\n//define/override symbols in the new scope\ns1.set(\"b\", 200);\ns1.set(\"c\", 300);\n\n//s1 inherited \"a\"\ns1.get(\"a\");\n//-\u003e 1\n\n//s1 changed \"b\"\ns1.get(\"b\");\n//-\u003e 200\n//but s0 \"b\" was not touched\ns0.get(\"b\");\n//-\u003e 2\n\n//s1 has \"c\", but s0 does not\ns1.has(\"c\");\n//-\u003e true\ns0.has(\"c\");\n//-\u003e false\n```\n\n## API\n### s = SymbolTable()\nCreates a new symbol table.\n\n### s.has(symbol)\nReturns true if the symbol is in scope.\n\n### value = s.get(symbol)\nReturns the value associated with that symbol in scope. Returns undefined if not found.\n\n### s.set(symbol, value)\nSet 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.\n\n### s.unset(symbol)\nRemove a symbol from a scope\n\n### s2 = s.push()\nReturn a new scope that inherits the current scope.\n\n## Stack\n\nCreate 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.\n\n```js\nvar SymbolTableStack = require(\"symbol-table/stack\");\n\nvar s = SymbolTableStack();\n\ns.set(\"a\", 1);\ns.push();\n\ns.set(\"a\", 2);\ns.get(\"a\");\n//-\u003e 2\n\ns.pop();\n\ns.get(\"a\");\n//-\u003e 1\n```\n\n### has, get, set, unset\nThese all work the same as the symbol table. However, it will always be the scope at the top of the stack.\n\n### table = s.push()\nCreates a new table/scope and pushes it on top of the stack. It also returns the new table.\n\n### table = s.pop()\nPops the current table/scope off the stack.\n\n### i = s.height()\nGet the stack height (initially it's 1)\n\n### i = s.getItsHeight(symbol)\nWhat was the stack height when this symbol was set/defined?\nReturns undefined if the symbol is not found.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallhelm%2Fsymbol-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallhelm%2Fsymbol-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallhelm%2Fsymbol-table/lists"}