public void ShouldCreateIntFunction()
        {
            var dm = new NPCompiler().CompileMethod("funcao inteiro principal() fim");

            Assert.AreEqual(typeof(int), dm.ReturnType);
            Assert.AreEqual("principal", dm.Name);
        }
        public void Should_Load_Args()
        {
            var result = new NPCompiler()
                .CompileMethod("funcao inteiro soma(inteiro x) retorne x fim")
                .Invoke(null, new object[]{20});

            Assert.AreEqual(20, result);
        }
        public void Should_Create_Function_Returning_Value()
        {
            var dm = new NPCompiler().CompileMethod("funcao inteiro soma(inteiro a, inteiro b) retorne 1 fim");

            var result = dm.Invoke(null, new object[] {1, 1});

            Assert.AreEqual(1, result);
        }
        public void Should_Create_Function_Returning_Value()
        {
            var dm = new NPCompiler().CompileMethod("funcao inteiro soma() retorne 8 + 2 fim");

            var result = dm.Invoke(null, null);

            Assert.AreEqual(10, result);
        }         
        public void Should_Add_Int_Locals()
        {
            var result = new NPCompiler()
				.CompileMethod("funcao inteiro soma() variavel inteiro x = 20, y = 20 retorne x + y fim")
                .Invoke(null, null);

            Assert.AreEqual(40, result);
        }
        public void ShouldCreateIntFunctionParams()
        {
            var dm = new NPCompiler().CompileMethod("funcao inteiro soma(inteiro a, inteiro b) fim");            

            Assert.AreEqual(typeof(int), dm.ReturnType);
            Assert.AreEqual("soma", dm.Name);

            var parameters = dm.GetParameters();

            Assert.AreEqual(2, parameters.Length);

            Assert.AreEqual(typeof(int), parameters[0].ParameterType);
            Assert.AreEqual(typeof(int), parameters[0].ParameterType);
        }
        public void Should_Execute_Arithmetic_Function()
        {
            var result = new NPCompiler()
                .CompileMethod("funcao inteiro calc() retorne 2*5+10-9+4/2 fim")
                .Invoke(null, null);

            Assert.AreEqual(13, result);

            var result2 = new NPCompiler()
                .CompileMethod("funcao inteiro calc() retorne 2*(5+10)-9+4/2 fim")
                .Invoke(null, null);

            Assert.AreEqual(23, result2);
        }
Beispiel #8
0
 public NPortugol2()
 {
     _compiler = new NPCompiler();
 }
Beispiel #9
0
 public NPortugol2(string script)
 {
     _script = script;
     _compiler = new NPCompiler();
 }
Beispiel #10
0
        public void Hello()
        {
            var method = @"funcao inteiro soma() retorne 1 + 1 fim";

            var dm = new NPCompiler().CompileMethod(method);

            var result = dm.Invoke(null, null);

            Assert.AreEqual(2, (int) result);
        }