Context-Free Grammars & Derivations

the yield of a parse tree

If a parse tree is a picture of how a string was built, the yield is the string itself, read straight off the bottom edge. Run your finger along all the leaves from left to right and write down what you see: that sequence of terminals is the yield, also called the tree's frontier. The tree shows the structure; the yield is the flat sentence that structure produces.

Formally, the yield of a parse tree is the string obtained by concatenating the leaf labels in left-to-right order. In a parse tree of a context-free grammar the leaves are terminals (or the empty string ε from rules of the form A → ε, which contribute nothing), so the yield is always a string over the terminal alphabet Σ (Sigma). For instance, a tree rooted at S whose leaves spell, left to right, a, a, b, b has yield 'aabb'. Crucially, MANY different trees can have the same yield while having different internal shapes — that is exactly the situation of ambiguity.

The yield is the bridge between the structural world of trees and the flat world of strings and languages. A string w is in the language generated by a grammar precisely when there exists a parse tree, rooted at the start symbol, whose yield is w. So the language of a CFG can be defined as the set of all yields of all valid parse trees rooted at S. Watch the wording: the yield is read only off the LEAVES (the terminals), not off internal nodes; the variables labelling internal nodes are part of the structure but never part of the yield.

A tree with root S, internal node A, and leaves (reading left to right) a, b, a has yield 'aba'. The variable labels S and A are NOT part of the yield — only the terminal leaves are read.

The yield = the leaf labels concatenated left to right; w is in the language iff some tree rooted at S yields w.

The yield is read only off the LEAVES (terminals). Two different parse trees can share the same yield — that, by definition, is what makes a grammar ambiguous.

Also called
frontierleaf string葉串邊界字串