作者名:Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
本章字數:98字
更新時間:2021-06-25 20:52:37
Applicability and examples
The interpreter pattern can be used whenever an expression should be interpreted and transformed to its internal representation. The pattern cannot be applied to complex grammars since the internal representation is based on a composite pattern.
Java implements the interpreter pattern in java.util.Parser and it is used to interpret regular expressions. First, when a regular expression is interpreted, a matcher object is returned. The matcher uses the internal structure that was created by the pattern class based on the regular expression:
Pattern p = Pattern. compile("a*b"); Matcher m = p.matcher ("aaaaab"); boolean b = m.matches();