The builder, facade, and expression APIs
The process of interpreting an expression is a complicated process, where a lot of classes work together towards the goal. As an application developer, to focus on the task at hand, we might have to expose an API which abstracts away the complexities of lexical analysis, parsing, and AST generation. We normally use the GoF facade pattern in these contexts. But, we will use the GoF builder pattern here, as this creational pattern is more appropriate in situations where we need to create a composite object. Here, we create expressions which are modeled as composites:
public class AbstractBuilder{} public class ExpressionBuilder : AbstractBuilder { public string _expr_string; public ExpressionBuilder(string expr) { _expr_string = expr; } public Exp GetExpression() { try { RDParser p = new RDParser(_expr_string)...