-
Book Overview & Buying
-
Table Of Contents
Building Programming Language Interpreters
By :
Contrary to when we were designing the parse tree, in the case of the AST, it really makes sense to start from the top-level types rather than the details. This is not just a matter of preference—the modeling exercise here aims to describe the semantics of the language at a higher level than what we were working with when parsing.
Therefore, I will start with the definition of the Protocol class, which is the top-level node of the AST:
struct Protocol {
std::shared_ptr<const Agent> client;
std::shared_ptr<const Agent> server;
};
A protocol description has very different interpretations depending on which agent—client or server—you are thinking about. So, the approach I’m taking here is to create entirely independent parts of the tree representing the semantics of the client and the server.
In the parse tree, this was embedded into the syntax, but here, this is the main...