mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-29 15:13:44 +00:00
Update 设计模式 - 解释器.md
小节标题改为中文,重新绘制类图,补充参考资料。
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 184 KiB |
+11
-10
@@ -1,18 +1,15 @@
|
||||
## 解释器(Interpreter)
|
||||
|
||||
### Intent
|
||||
|
||||
### 意图
|
||||
为语言创建解释器,通常由语言的语法和语法分析来定义。
|
||||
|
||||
### Class Diagram
|
||||
|
||||
### 类图
|
||||
- TerminalExpression:终结符表达式,每个终结符都需要一个 TerminalExpression。
|
||||
- Context:上下文,包含解释器之外的一些全局信息。
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/2b125bcd-1b36-43be-9b78-d90b076be549.png"/> </div><br>
|
||||
|
||||
### Implementation
|
||||
<div align="center"> <img src="pics/dp-interpreter.png" width="760px"/> </div><br>
|
||||
|
||||
### 实现
|
||||
以下是一个规则检验器实现,具有 and 和 or 规则,通过规则可以构建一棵解析树,用来检验一个文本是否满足解析树定义的规则。
|
||||
|
||||
例如一棵解析树为 D And (A Or (B C)),文本 "D A" 满足该解析树定义的规则。
|
||||
@@ -110,14 +107,18 @@ public class Client {
|
||||
}
|
||||
```
|
||||
|
||||
```html
|
||||
```text
|
||||
true
|
||||
false
|
||||
```
|
||||
|
||||
### JDK
|
||||
|
||||
### JDK 中的应用
|
||||
- [java.util.Pattern](http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html)
|
||||
- [java.text.Normalizer](http://docs.oracle.com/javase/8/docs/api/java/text/Normalizer.html)
|
||||
- All subclasses of [java.text.Format](http://docs.oracle.com/javase/8/docs/api/java/text/Format.html)
|
||||
- [javax.el.ELResolver](http://docs.oracle.com/javaee/7/api/javax/el/ELResolver.html)
|
||||
|
||||
## 参考资料
|
||||
|
||||
- 弗里曼. Head First 设计模式 [M]. 中国电力出版社, 2007.
|
||||
- Gamma E. 设计模式: 可复用面向对象软件的基础 [M]. 机械工业出版社, 2007.
|
||||
|
||||
Reference in New Issue
Block a user