예제 #1
0
        public void GivenAnApplicationEvaluateTheApplicationCorrectly()
        {
            var application = @"(λx.(λy.x)) (λx.(λy.x))";

            var lambdaExpression = _parser.Parse(application);

            var interpreter = new InterpreterVisitor();
            var events      = new ReductionEventCollector();

            ConnectEvents(interpreter, events);

            lambdaExpression.Accept(interpreter);

            var printVisitor = new NormalFormVisitor();

            interpreter.Result.Accept(printVisitor);

            Assert.Collection(events.Events,
                              e => Assert.Equal("α", e),
                              e => Assert.Equal("β", e));

            Assert.Equal("λy.(λx0.(λx1.x0))", printVisitor.Result);
        }
예제 #2
0
 private static void ConnectEvents(InterpreterVisitor interpreter, ReductionEventCollector events)
 {
     interpreter.AlphaReductionEvent += events.OnAlphaReductionEvent;
     interpreter.BetaReductionEvent  += events.OnBetaReductionEvent;
     interpreter.EtaReductionEvent   += events.OnEtaReductionEvent;
 }