Пример #1
0
        //规则:Julie 是一个已婚的女性
        public static IExpression getMarriedWomanExpression()
        {
            IExpression julie   = new TerminalExpression("Julie");
            IExpression married = new TerminalExpression("Married");

            return(new AndExpression(julie, married));
        }
Пример #2
0
        //规则:Robert 和 John 是男性
        public static IExpression getMaleExpression()
        {
            IExpression robert = new TerminalExpression("Robert");
            IExpression john   = new TerminalExpression("John");

            return(new OrExpression(robert, john));
        }
Пример #3
0
        static void Main(string[] args)
        {
            Context            context            = new Context("三加八加九减二乘五除三");
            AbstractExpression abstractExpression = new TerminalExpression();

            abstractExpression.Interpret(context);

            AbstractExpression noabstractExpression = new NonterminalExpression();

            noabstractExpression.Interpret(context);

            Console.WriteLine(context.Statement);
        }