Beispiel #1
0
        void processStamentPart(StatmentPart statmentPart)
        {
            StatmentPartProcessor statmentPartProcessor = new StatmentPartProcessor();
            Statment statment = (Statment)statmentPart.getTokensList()[0];

            foreach (ITree node in statment.getTokensList())
            {
                if (node.getMethodName() == Constants.ASSIGNMENT_STATMENT)
                {
                    AssignmentProcessor assignmenterProcessor = new AssignmentProcessor();
                    assignmenterProcessor.process((AssignmentStatment)node);
                }
                else if (node.getMethodName() == Constants.READ_STATMENT)
                {
                    ReaderProcessor readerProcessor = new ReaderProcessor();
                    readerProcessor.process((ReadStatment)node);
                }
                else if (node.getMethodName() == Constants.WRITE_STATMENT)
                {
                    WriterProcessor writeProcessor = new WriterProcessor();
                    writeProcessor.process((WriteStatment)node);
                }
                else if (node.getMethodName() == Constants.IF_STATMENT)
                {
                    IfStatmentProcessor ifStatmentProcessor = new IfStatmentProcessor();
                    ifStatmentProcessor.process((IfStatment)node);
                }
                else if (node.getMethodName() == Constants.WHILE_STATMENT)
                {
                    WhileProcessor whileProcessor = new WhileProcessor();
                    whileProcessor.process((WhileStatment)node);
                }
            }
        }
        void processStamentPart(StatmentPart statmentPart)
        {
            AppDomain             domain                = AppDomain.CurrentDomain;
            AssemblyName          assemblyName          = new AssemblyName(Program.programName);
            AssemblyBuilder       assemblyBuilder       = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave, "./");
            ModuleBuilder         moduleBuilder         = assemblyBuilder.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".exe");
            TypeBuilder           typeBuilder           = moduleBuilder.DefineType("Project.Program", TypeAttributes.Public | TypeAttributes.AutoClass | TypeAttributes.BeforeFieldInit);
            MethodBuilder         methodBuilder         = typeBuilder.DefineMethod("Main", MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.HideBySig);
            StatmentPartProcessor statmentPartProcessor = new StatmentPartProcessor();
            Statment statment = (Statment)statmentPart.getTokensList()[0];

            foreach (ITree node in statment.getTokensList())
            {
                if (node.getMethodName() == Constants.ASSIGNMENT_STATMENT)
                {
                    AssignmentProcessor assignmenterProcessor = new AssignmentProcessor();
                    assignmenterProcessor.process((AssignmentStatment)node);
                }
                else if (node.getMethodName() == Constants.READ_STATMENT)
                {
                    ReaderProcessor readerProcessor = new ReaderProcessor();
                    readerProcessor.process((ReadStatment)node);
                }
                else if (node.getMethodName() == Constants.WRITE_STATMENT)
                {
                    WriterProcessor writeProcessor = new WriterProcessor();
                    writeProcessor.process((WriteStatment)node);
                }
                else if (node.getMethodName() == Constants.IF_STATMENT)
                {
                    IfStatmentProcessor ifStatmentProcessor = new IfStatmentProcessor();
                    ifStatmentProcessor.process((IfStatment)node);
                }
                else if (node.getMethodName() == Constants.WHILE_STATMENT)
                {
                    WhileProcessor whileProcessor = new WhileProcessor();
                    whileProcessor.process((WhileStatment)node);
                }
            }
            ExpressionsList.AddExpression(Expression.Call(typeof(Console).GetMethod("Read")));
            List <Expression> list            = ExpressionsList.GetList();
            BlockExpression   blockExpression = Expression.Block(VarExpressionsList.GetList(), ExpressionsList.GetList());

            Expression.Lambda <Action>(blockExpression).CompileToMethod(methodBuilder);
            assemblyBuilder.SetEntryPoint(methodBuilder);
            typeBuilder.CreateType();
            assemblyBuilder.Save(assemblyName.Name + ".exe");
        }
Beispiel #3
0
        public static List <Object> getElseAndThenStatments(StatmentPart statmentPart)
        {
            List <Object> statments = StatmentPartProcessor.getStatments(statmentPart);

            return(statments);
        }