读书人

解释器方式(Interpreter)-java与模式

发布时间: 2012-11-04 10:42:42 作者: rapoo

解释器模式(Interpreter)---java与模式(例子)

?

一,Interpreter使用面不是很广,描述了一个语言解释器是怎么构成的,在实际应用中,我们可能很少去构造一个语言的解释器.

没在平常使用中发现例子,故以java与模式一书中的例子为例。。。

这个例子是针对 与,或,非提供的一套解析器

?

提供一个实现的环境

?

?//Not操作

?

/** *  * @author wu_quanyin(09817)  * @version 1.0 * @date Jul 9, 2010 10:01:31 PM */public class Client {private static Context ctx;private static Expression exp;public static void main(String[] args) {ctx=new Context();Variable x=new Variable("x");Variable y=new Variable("y");Constant c=new Constant(true);ctx.assign(x, false);ctx.assign(y, true);exp=new Or(new And(c,x),new And(y,new Not(x)));System.out.println(exp.interpret(ctx));}}/**--false*/
??

?

读书人网 >软件架构设计

热点推荐