Regular tree grammar explained

In theoretical computer science and formal language theory, a regular tree grammar is a formal grammar that describes a set of directed trees, or terms.[1] A regular word grammar can be seen as a special kind of regular tree grammar, describing a set of single-path trees.

Definition

A regular tree grammar G is defined by the tuple

G = (N, Σ, Z, P),

where

Derivation of trees

The grammar G implicitly defines a set of trees: any tree that can be derived from Z using the rule set P is said to be described by G.This set of trees is known as the language of G.More formally, the relation ⇒G on the set TΣ(N) is defined as follows:

A tree can be derived in a single step into a tree (in short: t1G t2), if there is a context S and a production such that:

Here, a context means a tree with exactly one hole in it; if S is such a context, S[''t''] denotes the result of filling the tree t into the hole of S.

The tree language generated by G is the language .

Here, TΣ denotes the set of all trees composed from symbols of Σ, while ⇒G* denotes successive applications of ⇒G.

A language generated by some regular tree grammar is called a regular tree language.

Examples

Let G1 = (N11,Z1,P1), where

An example derivation from the grammar G1 is

BListcons(Bool,BList)⇒ cons(false,cons(Bool,BList))⇒ cons(false,cons(true,nil)).

The image shows the corresponding derivation tree; it is a tree of trees (main picture), whereas a derivation tree in word grammars is a tree of strings (upper left table).

The tree language generated by G1 is the set of all finite lists of boolean values, that is, L(G1) happens to equal TΣ1.The grammar G1 corresponds to the algebraic data type declarations (in the Standard ML programming language):

datatype Bool = false | true datatype BList = nil | cons of Bool * BListEvery member of L(G1) corresponds to a Standard-ML value of type BList.

For another example, let, using the nonterminal set and the alphabet from above, but extending the production set by P2, consisting of the following productions:

The language L(G2) is the set of all finite lists of boolean values that contain true at least once. The set L(G2) has no datatype counterpart in Standard ML, nor in any other functional language.It is a proper subset of L(G1).The above example term happens to be in L(G2), too, as the following derivation shows:

BListcons(false,BList)⇒ cons(false,cons(true,BList))⇒ cons(false,cons(true,nil)).

Language properties

If L1, L2 both are regular tree languages, then the tree sets, and L1 \ L2 are also regular tree languages, and it is decidable whether, and whether L1 = L2.

Alternative characterizations and relation to other formal languages

Applications

Applications of regular tree grammars include:

See also

Further reading

Notes and References

  1. 10.1.1.164.5484 . Regular tree grammars as a formalism for scope underspecification .
  2. Web site: Comon . Hubert . Dauchet . Max . Gilleron . Remi . Löding . Christof . Jacquemard . Florent . Lugiez . Denis . Tison . Sophie . Tommasi . Marc . 12 October 2007 . Tree Automata Techniques and Applications . 25 January 2016 .
  3. Book: 10.1145/1007352.1007390 . Alur . R. . Madhusudan. 978-1581138528 . P.. Visibly pushdown languages . Proceedings of the thirty-sixth annual ACM symposium on Theory of computing - STOC '04 . 202–211. 2004 . 7473479 . http://www.cis.upenn.edu/~alur/Stoc04.pdf. Sect.4, Theorem 5,
  4. 10.1145/1516512.1516518. Alur . R. . Madhusudan . P. . Adding nesting structure to words . Journal of the ACM . 56 . 3 . 1–43 . 2009 . 10.1.1.145.9971. 768006 . Sect.7
  5. Helmut. Emmelmann. Code Selection by Regularly Controlled Term Rewriting. Code Generation - Concepts, Tools, Techniques. Springer. Workshops in Computing. 3–29. 1991.
  6. Hubert. Comon. Equational Formulas in Order-Sorted Algebras. Proc. ICALP. 1990.
  7. R.. Gilleron. S.. Tison. M.. Tommasi. Solving Systems of Set Constraints using Tree Automata. 10th Annual Symposium on Theoretical Aspects of Computer Science. Springer. LNCS. 665. 505–514. 1993.
  8. Jochen. Burghardt. Axiomatization of Finite Algebras. Advances in Artificial Intelligence. Springer. LNAI. 2479. 222–234. 3-540-44185-9. 1403.7347. 2002. 2014arXiv1403.7347B.
  9. Smoly . Ziv-Ukelson. Algorithms for Regular Tree Grammar Network Search and Their Application to Mining Human–viral Infection Patterns. 2016. J. of Comp. Bio.. https://www.liebertpub.com/doi/full/10.1089/cmb.2015.0168