<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Graph-structured_stack</id>
	<title>Graph-structured stack - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Graph-structured_stack"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Graph-structured_stack&amp;action=history"/>
	<updated>2026-04-14T02:45:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Graph-structured_stack&amp;diff=401555&amp;oldid=prev</id>
		<title>imported&gt;David Eppstein: better cat</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Graph-structured_stack&amp;diff=401555&amp;oldid=prev"/>
		<updated>2022-03-11T07:46:57Z</updated>

		<summary type="html">&lt;p&gt;better cat&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{No footnotes|date=January 2022}}&lt;br /&gt;
&lt;br /&gt;
In [[computer science]], a &amp;#039;&amp;#039;&amp;#039;graph-structured stack&amp;#039;&amp;#039;&amp;#039; (GSS) is a [[directed acyclic graph]] where each directed [[Path (graph theory)|path]] represents a [[Stack (data structure)|stack]].&lt;br /&gt;
The graph-structured stack is an essential part of [[GLR parser|Tomita&amp;#039;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. &lt;br /&gt;
&lt;br /&gt;
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}.&lt;br /&gt;
:[[Image:Graph-structured_stack_-_Borneq.png|400px|Graph-structured_stack_-_Borneq.png]]&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
:[[Image:Stacks_-_Borneq.dot.png|Stacks_-_Borneq.dot.png|350px]]&lt;br /&gt;
&lt;br /&gt;
==Operations==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
GSSnode* GSS::add(GSSnode* prev, int elem)&lt;br /&gt;
{&lt;br /&gt;
	int prevlevel = prev-&amp;gt;level;&lt;br /&gt;
	assert(levels.size() &amp;gt;= prevlevel + 1);&lt;br /&gt;
	int level = prevlevel + 1;&lt;br /&gt;
	if (levels.size() == level)&lt;br /&gt;
	{&lt;br /&gt;
		levels.resize(level + 1);&lt;br /&gt;
	}&lt;br /&gt;
	GSSnode* node = findElemAtLevel(level, elem);&lt;br /&gt;
	if (node == nullptr)&lt;br /&gt;
	{&lt;br /&gt;
		node = new GSSnode();&lt;br /&gt;
		node-&amp;gt;elem = elem;&lt;br /&gt;
		node-&amp;gt;level = level;		&lt;br /&gt;
		levels[level].push_back(node);&lt;br /&gt;
	}&lt;br /&gt;
	node-&amp;gt;add(prev);&lt;br /&gt;
	return node;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
void GSS::remove(GSSnode* node)&lt;br /&gt;
{&lt;br /&gt;
	if (levels.size() &amp;gt; node-&amp;gt;level + 1)&lt;br /&gt;
		if (findPrevAtLevel(node-&amp;gt;level + 1, node)) throw Exception(&amp;quot;Can remove only from top.&amp;quot;);&lt;br /&gt;
	for (int i = 0; i &amp;lt; levels[node-&amp;gt;level].size(); i++)&lt;br /&gt;
		if (levels[node-&amp;gt;level][i] == node)&lt;br /&gt;
		{&lt;br /&gt;
			levels[node-&amp;gt;level].erase(levels[node-&amp;gt;level].begin() + i);&lt;br /&gt;
			break;&lt;br /&gt;
		}&lt;br /&gt;
	delete node;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*Masaru Tomita. &amp;#039;&amp;#039;Graph-Structured Stack And Natural Language Parsing&amp;#039;&amp;#039;. Annual Meeting of the Association of Computational Linguistics, 1988. [http://www.aclweb.org/anthology/P88-1031]&lt;br /&gt;
*Elizabeth Scott, Adrian Johnstone &amp;#039;&amp;#039;GLL Parsing&amp;#039;&amp;#039; [http://dotat.at/tmp/gll.pdf gll.pdf]&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Graph-Structured Stack}}&lt;br /&gt;
[[Category:Graph data structures]]&lt;br /&gt;
[[Category:Application-specific graphs]]&lt;br /&gt;
&lt;br /&gt;
{{Comp-sci-stub}}&lt;/div&gt;</summary>
		<author><name>imported&gt;David Eppstein</name></author>
	</entry>
</feed>