interpreter pattern finallythe interpreter pattern can be used to decide if certain tab qualifies for any specials firstthe tab and item classes are definedfollowed by the classes needed for the grammar thensome sentences in the grammar are implemented and tested using test tabs note that we hard code the types in this example so the code can be runusuallythose are the types of things you would like to store in some file or database import datetime class rule(object)def __init__(selfconditionsdiscounts)self conditions conditions self discounts discounts def evaluate(selftab)if self conditions evaluate(tab)return self discounts calculate(tabreturn class conditions(object)def __init__(selfexpression)self expression expression def evaluate(selftab)return self expression evaluate(tabclass and(object)def __init__(selfexpression expression )self expression expression self expression expression def evaluate(selftab)return self expression evaluate(taband self expression evaluate(tabclass or(object)def __init__(selfexpression expression )self expression expression self expression expression