Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Graph-structured stack
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{No footnotes|date=January 2022}} In [[computer science]], a '''graph-structured stack''' (GSS) is a [[directed acyclic graph]] where each directed [[Path (graph theory)|path]] represents a [[Stack (data structure)|stack]]. The graph-structured stack is an essential part of [[GLR parser|Tomita's algorithm]], where it replaces the usual [[Stack (data structure)|stack]] of a [[pushdown automaton]]. This allows the algorithm to encode the nondeterministic choices in parsing an [[ambiguous grammar]], sometimes with greater efficiency. In the following diagram, there are four stacks: {7,3,1,0}, {7,4,1,0}, {7,5,2,0}, and {8,6,2,0}. :[[Image:Graph-structured_stack_-_Borneq.png|400px|Graph-structured_stack_-_Borneq.png]] Another way to simulate nondeterminism would be to duplicate the stack as needed. The duplication would be less efficient since vertices would not be shared. For this example, 16 vertices would be needed instead of 9. :[[Image:Stacks_-_Borneq.dot.png|Stacks_-_Borneq.dot.png|350px]] ==Operations== <syntaxhighlight lang="cpp"> GSSnode* GSS::add(GSSnode* prev, int elem) { int prevlevel = prev->level; assert(levels.size() >= prevlevel + 1); int level = prevlevel + 1; if (levels.size() == level) { levels.resize(level + 1); } GSSnode* node = findElemAtLevel(level, elem); if (node == nullptr) { node = new GSSnode(); node->elem = elem; node->level = level; levels[level].push_back(node); } node->add(prev); return node; } </syntaxhighlight> <syntaxhighlight lang="cpp"> void GSS::remove(GSSnode* node) { if (levels.size() > node->level + 1) if (findPrevAtLevel(node->level + 1, node)) throw Exception("Can remove only from top."); for (int i = 0; i < levels[node->level].size(); i++) if (levels[node->level][i] == node) { levels[node->level].erase(levels[node->level].begin() + i); break; } delete node; } </syntaxhighlight> == References == *Masaru Tomita. ''Graph-Structured Stack And Natural Language Parsing''. Annual Meeting of the Association of Computational Linguistics, 1988. [http://www.aclweb.org/anthology/P88-1031] *Elizabeth Scott, Adrian Johnstone ''GLL Parsing'' [http://dotat.at/tmp/gll.pdf gll.pdf] {{DEFAULTSORT:Graph-Structured Stack}} [[Category:Graph data structures]] [[Category:Application-specific graphs]] {{Comp-sci-stub}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Comp-sci-stub
(
edit
)
Template:No footnotes
(
edit
)