public void process(ReadStatment readStatment) { try { VaribleStatment varibleStatment = (VaribleStatment)readStatment.getTokensList()[0]; _isArray = false; _identifier = (Token)varibleStatment.getTokensList()[0]; SemanticAnalizer.initVarible(_identifier.value); } catch//для массива { _isArray = true; List <Token> tokens = AssignmentProcessor.getMathExpression((MathStatment)readStatment.getTokensList()[0]); _identifier = tokens[0]; if (tokens.Count == 1) { if (tokens[0].kind == Constants.CONST_INT) { SemanticAnalizer.readAndWriteToConts(); } _isArray = false; } else if (tokens.Count == 4 && (tokens[1].kind == Constants.BRACKET_L) && (tokens[3].kind == Constants.BRACKET_R)) { _isArray = true; _elementIndex = tokens[2]; } else { SemanticAnalizer.InvalidIdentifier(); } } generate(); }
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); } } }
public static List <Token> getLeftExpression(BoolExpression boolExpression) { List <Token> leftExpression = new List <Token>(); foreach (Object token in boolExpression.getTokensList()) { leftExpression.AddRange(AssignmentProcessor.getFactor(token)); } return(leftExpression); }
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"); }
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)); }