Pattern 24Syntax-Directed Interpreter

Purpose

This pattern directly executes source code without building an intermediate representation and without translating it to another language.

The sample implementation for this pattern focuses on building a syntax-directed interpreter for an SQL subset.

Discussion

A syntax-directed interpreter mimics what we do when we trace source code manually. As we step through the code, we parse, validate, and execute instructions. Everything happens in the parser because a syntax-directed interpreter doesn’t create an AST or translate source code to bytecodes or machine code. The interpreter directly feeds off of syntax to execute statements.

The good news is that there are very few “moving parts” in a syntax-directed ...

Get Language Implementation Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.