void generateRightExpression() { foreach (ITree node in _rightExpression) { 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) { 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 generateRightExpression(Expression left) { LabelTarget label = Expression.Label(typeof(void)); int i = ExpressionsList.GetList().Count; foreach (ITree node in _rightExpression) { 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); } } List <Expression> list = new List <Expression>(); int x = i; while (ExpressionsList.GetList().Count != i) { list.Add(ExpressionsList.GetElement(x)); ExpressionsList.RemoveElement(x); } Expression rigth = Expression.Block(list); var exitLabel = Expression.Label(); var block = Expression.Loop( Expression.IfThenElse( left, rigth, Expression.Break(label)), label); ExpressionsList.AddExpression(block); }
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"); }
public void process(WhileStatment whileStatment) { BoolStatment boolSatment = (BoolStatment)whileStatment.getTokensList()[0]; _leftExpression = IfStatmentProcessor.getLeftExpression((BoolExpression)boolSatment.getTokensList()[0]); if (_leftExpression[0].kind == Constants.IDENTIFIER) { SemanticAnalizer.checkVarible(_leftExpression[0].value); } if (_leftExpression[2].kind == Constants.IDENTIFIER) { SemanticAnalizer.checkVarible(_leftExpression[2].value); } _rightExpression = IfStatmentProcessor.getElseAndThenStatments((StatmentPart)whileStatment.getTokensList()[1]); generate(); }
Expression generateRightExpression(List <object> expression) { int i = ExpressionsList.GetList().Count; foreach (ITree node in expression) { 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); } } List <Expression> list = new List <Expression>() { Expression.Empty() }; int x = i; while (ExpressionsList.GetList().Count != i) { list.Add(ExpressionsList.GetElement(x)); ExpressionsList.RemoveElement(x); } return(Expression.Block(list)); }