Pattern 8Parse Tree

Purpose

A parse tree describes how a parser recognized an input sentence.

A parse tree is sometimes called a syntax tree (as opposed to an abstract syntax tree). Despite not being that useful for building interpreters and translators, I’m including this pattern because parse trees are heavily used by development environments and text rewriting systems.

Discussion

Parse trees record the sequence of rules a parser applies as well as the tokens it matches. Interior parse tree nodes represent rule applications, and leaf nodes represent token matches. Parse trees describe sentence structure by grouping input symbols into subtrees. Subtrees represent the structure of phrases (sentence fragments). For example, the following parse ...

Get Language Implementation Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.