-
Book Overview & Buying
-
Table Of Contents
Building Programming Language Interpreters
By :
When implementing a parser, the primary concern is having a structure that correctly represents how the syntax of the language is laid out in text. When generating code, however, you need a representation that more precisely describes the semantics of the code.
The term we use for that second structure is abstract syntax tree (AST). It’s referred to as abstract because it’s not yet concrete execution code, nor is it a parse tree.
A parse tree must represent aspects that are specific to the rules of the grammar, even if those end up not being how the code itself is going to be executed. On the other hand, an AST abstracts away grammar-related details.
For instance, the parse tree for the language that I have been building is focused on the messages and the elements that form them. But what the language is actually describing is two different state machines—one for the server and one for the...