Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

page_util_norm_peg(n) [mojave man page]

page_util_norm_peg(n)					      Parser generator tools					     page_util_norm_peg(n)

__________________________________________________________________________________________________________________________________________________

NAME
page_util_norm_peg - page AST normalization, PEG SYNOPSIS
package require page::util::norm_peg ?0.1? package require snit ::page::util::norm::peg tree _________________________________________________________________ DESCRIPTION
This package provides a single utility command which takes an AST for a parsing expression grammar and normalizes it in various ways. The result is called a Normalized PE Grammar Tree. Note that this package can only be used from within a plugin managed by the package page::pluginmgr. API
::page::util::norm::peg tree This command assumes the tree object contains for a parsing expression grammar. It normalizes this tree in place. The result is called a Normalized PE Grammar Tree. The following operations are performd [1] The data for all terminals is stored in their grandparental nodes. The terminal nodes and their parents are removed. Type information is dropped. [2] All nodes which have exactly one child are irrelevant and are removed, with the exception of the root node. The immediate child of the root is irrelevant as well, and removed as well. [3] The name of the grammar is moved from the tree node it is stored in to an attribute of the root node, and the tree node removed. The node keeping the start expression separate is removed as irrelevant and the root node of the start expression tagged with a marker attribute, and its handle saved in an attribute of the root node for quick access. [4] Nonterminal hint information is moved from nodes into attributes, and the now irrelevant nodes are deleted. Note: This transformation is dependent on the removal of all nodes with exactly one child, as it removes the all 'Attribute' nodes already. Otherwise this transformation would have to put the information into the grandparental node. The default mode given to the nonterminals is value. Like with the global metadata definition specific information is moved out out of nodes into attributes, the now irrelevant nodes are deleted, and the root nodes of all definitions are tagged with marker attributes. This provides us with a mapping from nonterminal names to their defining nodes as well, which is saved in an attribute of the root node for quick reference. At last the range in the input covered by a definition is computed. The left extent comes from the terminal for the nontermi- nal symbol it defines. The right extent comes from the rightmost child under the definition. While this not an expression tree yet the location data is sound already. [5] The remaining nodes under all definitions are transformed into proper expression trees. First character ranges, followed by unary operations, characters, and nonterminals. At last the tree is flattened by the removal of superfluous inner nodes. The order matters, to shed as much nodes as possible early, and to avoid unnecessary work later. BUGS, IDEAS, FEEDBACK This document, will undoubtedly contain bugs and other problems. Please report such in the category page of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have. KEYWORDS
PEG, graph walking, normalization, page, parser generator, text processing, tree walking CATEGORY
Page Parser Generator COPYRIGHT
Copyright (c) 2007 Andreas Kupries <andreas_kupries@users.sourceforge.net> page 1.0 page_util_norm_peg(n)

Check Out this Related Man Page

grammar::me::util(n)					   Grammar operations and usage 				      grammar::me::util(n)

__________________________________________________________________________________________________________________________________________________

NAME
grammar::me::util - AST utilities SYNOPSIS
package require Tcl 8.4 package require grammar::me::util ?0.1? ::grammar::me::util::ast2tree ast tree ?root? ::grammar::me::util::ast2etree ast mcmd tree ?root? mcmd lc location mcmd tok from ?to? ::grammar::me::util::tree2ast tree ?root? _________________________________________________________________ DESCRIPTION
This package provides a number of utility command for the conversion between the various representations of abstract syntax trees as speci- fied in the document grammar::me_ast. ::grammar::me::util::ast2tree ast tree ?root? This command converts an ast from value to object representation. All nodes in the ast will be converted into nodes of this tree, with the root of the AST a child of the node root. If this node is not explicitly specified the root of the tree is used. Existing content of tree is not touched, i.e. neither removed nor changed, with the exception of the specified root node, which will gain a new child. ::grammar::me::util::ast2etree ast mcmd tree ?root? This command is like ::grammar::me::util::ast2tree, except that the result is in the extended object representation of the input AST. The source of the extended information is the command prefix mcmd. It has to understand two methods, lc, and tok, with the semantics specified below. mcmd lc location Takes the location of a token given as offset in the input stream and return a 2-element list containing the associated line number and column index, in this order. mcmd tok from ?to? Takes one or two locations from and to as offset in the input stream and returns a Tcl list containing the specified part of the input stream. Both location are inclusive. If to is not specified it will default to the value of from. Each element of the returned list is a list containing the token, its associated lexeme, the line number, and column index, in this order. Both the ensemble command ::grammar::me::tcl provided by the package grammar::me::tcl and the objects command created by the package ::grammar::me::cpu fit the above specification. ::grammar::me::util::tree2ast tree ?root? This command converts an ast in (extended) object representation into a value and returns it. If a root node is specified the AST is generated from that node downward. Otherwise the root of the tree object is used as the starting point. BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category gram- mar_me of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. KEYWORDS
abstract syntax tree, syntax tree, tree COPYRIGHT
Copyright (c) 2005 Andreas Kupries <andreas_kupries@users.sourceforge.net> grammar_me 0.1 grammar::me::util(n)
Man Page