interpreter pattern def apply(self)if self conditions evaluate(self tab)return self discounts calculate(self tabreturn implementing the interpreter pattern two types of people use softwarethose who are satisfied with the offering out of the box and those who are willing to tinker and tweak to make the software fit their needs more perfectly the interpreter pattern is interesting only to the people in this second group since they are the people who will be willing to invest the time needed to learn how to use the dsl to make the software fit their needs back in the restaurantone owner will be happy with some basic templates for specialslike two-for-one offerwhile another restaurant owner will want to tweak and expand his offers we can now generalize the basic implementation for the dsl we did previously to create way of solving these problems in the future every expression type gets class (as before)and every class has an interpret method class and an object to store the global context will also be needed this context is passed to the interpret function of the next object in the interpretation stream assume that parsing already took place the interpreter recursively traverses the container object until the answer to the problem is reached class nonterminal(object)def __init__(selfexpression)self expression expression def interpret(self)self expression interpret(class terminal(object)def interpret(self)pass