fbpx
Wikipedia

Graph-structured stack

In computer science, a graph-structured stack (GSS) is a directed acyclic graph where each directed path represents a stack. The graph-structured stack is an essential part of Tomita's algorithm, where it replaces the usual 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}.

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.

Operations Edit

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; } 
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; } 

References Edit

  • Masaru Tomita. Graph-Structured Stack And Natural Language Parsing. Annual Meeting of the Association of Computational Linguistics, 1988. [1]
  • Elizabeth Scott, Adrian Johnstone GLL Parsing gll.pdf

graph, structured, stack, this, article, includes, list, references, related, reading, external, links, sources, remain, unclear, because, lacks, inline, citations, please, help, improve, this, article, introducing, more, precise, citations, january, 2022, lea. This article includes a list of references related reading or external links but its sources remain unclear because it lacks inline citations Please help to improve this article by introducing more precise citations January 2022 Learn how and when to remove this template message In computer science a graph structured stack GSS is a directed acyclic graph where each directed path represents a stack The graph structured stack is an essential part of Tomita s algorithm where it replaces the usual 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 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 Operations EditGSSnode GSS add GSSnode prev int elem int prevlevel prev gt level assert levels size gt 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 gt elem elem node gt level level levels level push back node node gt add prev return node void GSS remove GSSnode node if levels size gt node gt level 1 if findPrevAtLevel node gt level 1 node throw Exception Can remove only from top for int i 0 i lt levels node gt level size i if levels node gt level i node levels node gt level erase levels node gt level begin i break delete node References EditMasaru Tomita Graph Structured Stack And Natural Language Parsing Annual Meeting of the Association of Computational Linguistics 1988 1 Elizabeth Scott Adrian Johnstone GLL Parsing gll pdf This computer science article is a stub You can help Wikipedia by expanding it vte Retrieved from https en wikipedia org w index php title Graph structured stack amp oldid 1076467531, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.