TopFormal GrammarsParse Trees and Ambiguity

Parse Trees and Ambiguity

  1. For our purposes, it is not enough that a grammar specify the set of strings that belong to a language, we also want a grammar to impose grammatical structure on strings since this structure influences the meaning associated with a string.

  2. It is not clear a derivation provides the information we want about grammatical structure since a single string may have many derivations.
  3. Representing structural information as a tree provides a better way to eliminate irrelevant choices about the order of non-terminal expansion.
    Parse Tree
    A parse tree for a sentential form S of a grammar G is a tree in which each node is labeled with an element of ( Vt U Vn ) in such a way that:
    1. The root is labeled with the start symbol,
    2. the nodes of the frontier of the tree (i.e. the leaves of the tree) are labeled with the symbols that form S, and
    3. each interior node is labeled with some non-terminal, N, such that N P and is the string of labels found on the node N's children.
  4. A parse tree for our favorite string and grammar (the old xaxzyy example) is shown in Figure *.

    A parse tree for xaxzyy
     
  5. There are grammars in which certain sentential forms have more than one parse tree.
    Ambiguity
    A grammar G is said to be ambiguous if there is some string in L(G) with two distinct parse trees.

Computer Science 434
Department of Computer Science
Williams College

TopFormal GrammarsParse Trees and Ambiguity