Behavioral

Interpreter

Description

Given a language, defines a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

Where to use

  • SQL Parsers.
  • \n
  • Mathematical expression evaluators.

Real World Example

An app that calculates '5 + 10 * 2'. It parses the string into an expression tree and evaluates it.

Code Example

class Interpreter:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Interpreter')