设计模式 - 解释器模式
定义
Given a language, define a represention for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
UML

实例
正则表达式,四则运算,中文转自然数,机器人控制指令,SQL解析,计算器,
- 重复发生的问题可以用一种简单的语言来表达。
- 可以将一个需要解释执行的语言中的句子表示为一个抽象语法树。
比较
| 比较 | 解释器模式 | 备注 | 
|---|---|---|
| 适配器模式 | 解释器要预先知道语法规则 | 适配器不需要先知道适配的规则 | 

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号