Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Building Programming Language Interpreters

You're reading from   Building Programming Language Interpreters A bottom-up approach to runtimes, execution, and implementation in C++

Arrow left icon
Product type Paperback
Published in Jan 2026
Publisher Packt
ISBN-13 9781837638079
Length 372 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Daniel Ruoso Daniel Ruoso
Author Profile Icon Daniel Ruoso
Daniel Ruoso
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Preface 1. Modeling the Programming Language Runtime Environment
2. Defining the Scope FREE CHAPTER 3. The Blurred Lines Between Native Code, Virtual Machines, and Interpreters 4. Instructions, Concurrency, Inputs, and Outputs 5. Native Types, User Types, and Extension Points 6. Putting It All Together: Making Trade-Off Decisions 7. Modeling the Programming Language Syntax
8. Review of Programming Language Paradigms 9. Values, Containers, and the Language Meta-Model 10. Lexical Scopes 11. Putting It All Together and Creating a Coherent Vision 12. Implementing the Interpreter Runtime
13. Initialization and Entry Point 14. Execution Frames, the Stack, and Continuations 15. Running and Testing Language Operators 16. Interpreting Source Code
17. Lexing: Turning Text into a Stream of Tokens 18. Parsing: Turning a Stream of Tokens into a Parse Tree 19. Analyzing: Turning a Parse Tree into an Abstract Syntax Tree 20. Generating: Turning an Abstract Syntax Tree into Instructions 21. Proving That It Works 22. Unlock Your Exclusive Benefits 23. Other Books You May Enjoy 24. Index

Code as a value

The implementation of the stack machine assumes that all inputs to an operation have to be resolved prior to the execution of the operation. This means the operation tree is traversed using a depth-first traversal until the interpreter finds an operation where all the inputs are resolved.

This is not sufficient, however, to represent more complicated control flow. Let’s look at a conditional operation, using the Python language:

if a == 5:
    something()
else:
    something_else()

A naïve representation of the operation tree would look like the following:

Figure 11.1:  Naïve operation tree for a conditional

Figure 11.1: Naïve operation tree for a conditional

However, if we consider how the stack machine is currently implemented, this would result in both branches of the conditional being evaluated before the condition itself is evaluated. This is not what was intended.

To solve this problem, we need to start by being able to represent the code to be executed in each branch...

lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Building Programming Language Interpreters
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon