Skip to Main Content
Language Implementation Patterns
book

Language Implementation Patterns

by Terence Parr
December 2009
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 2m
English
Pragmatic Bookshelf
Content preview from Language Implementation Patterns

Building Abstract Syntax Trees

Rather than simply taking what the parser can give us for free (parse trees), let’s take a second to design what we actually want in an IR. The critter that we end up with is called an abstract syntax tree (AST).

To figure out what ASTs should look like, let’s start with a list of design guidelines. An IR tree should be the following:

  • Dense: No unnecessary nodes

  • Convenient: Easy to walk

  • Meaningful: Emphasize operators, operands, and the relationship between them rather than artifacts from the grammar

The first two points imply that it should be easy and fast to identify patterns in the tree. Language applications that use intermediate trees usually make multiple passes over the trees in order to analyze or build ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Implementation Patterns

Implementation Patterns

Kent Beck

Publisher Resources

ISBN: 9781680500097Errata Page