Pattern 24 | Syntax-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 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.