Mike Liu 2207ea4ce9
Translation zh (#1646)
* add state and callback pattern

* add command and template-method pattern

* add iterator pattern

* add bridege and DI pattern

* fix issue #1600

* add converter,proxy,visitor pattern

* add caching,composite,delegation,dirty-flag,interpreter patterns

* add dao and producer-consumer

* add dto and provate class data pattern

* fix #1646 png path problems

* fix #1646 composite png path case problem

Co-authored-by: Mike <admin@xiaod.info>
Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
2021-02-08 21:07:48 +05:30
..
2021-02-08 21:07:48 +05:30

layout, title, folder, permalink, categories, tags
layout title folder permalink categories tags
pattern Interpreter interpreter /patterns/interpreter/ Behavioral
Gang of Four

目的

给定一种语言,请定义其语法的表示形式,以及使用该表示形式来解释该语言中的句子的解释器。

类图

alt text

适用性

有一种要解释的语言时,请使用解释器模式,并且可以将语言中的语句表示为抽象语法树。解释器模式在以下情况下效果最佳

  • 语法很简单。 对于复杂的语法,语法的类层次结构变得庞大且难以管理。 在这种情况下,解析器生成器之类的工具是更好的选择。 他们可以在不构建抽象语法树的情况下解释表达式,这可以节省空间并可能节省时间
  • 效率不是关键问题。 通常,最有效的解释器不是通过直接解释解析树来实现的,而是先将其转换为另一种形式。 例如,正则表达式通常会转换为状态机。 但是即使这样,翻译器也可以通过解释器模式实现,因此该模式仍然适用。

真实世界例子

鸣谢