private List <List <string> > ProcessBinaryOperator(List <List <string> > _currentCode, string _operator) { List <string> newLine = new List <string>(); string operand2 = constantsAndIdentifiersStack.Pop(); string operand1 = constantsAndIdentifiersStack.Pop(); newLine.Add("Dim"); string newVariableName = VariablesManager.GetNewVariable(); newLine.Add(newVariableName); newLine.Add("As"); newLine.Add("Variant"); List <string> newLine2 = new List <string> { newVariableName, "=", operand1, _operator, operand2 }; _currentCode.Add(newLine); _currentCode.Add(newLine2); constantsAndIdentifiersStack.Push(newVariableName); return(_currentCode); }
public List <List <string> > ConvertToBasic(List <List <string> > _rpnByLines) { VariablesManager.Reset(); List <string> rpn = new List <string>(); foreach (List <string> line in _rpnByLines) { foreach (string word in line) { rpn.Add(word); } } List <List <string> > result = new List <List <string> >(); // Индекс элемента в rpn int i = -1; for (int j = 0; j < _rpnByLines.Count; ++j) { for (int k = 0; k < _rpnByLines[j].Count; ++k) { i++; string element = rpn[i]; if (IsIdentifier(element) || IsConstant(element) || IsNumber(element)) { constantsAndIdentifiersStack.Push(element); continue; } if (element == "НФ") { result = ProcessFunctionBeginning(result, rpn); } else if (element == "КФ") { result = ProcessFunctionEnd(i, rpn, result); } else if (element == "КО") { result = ProcessVariableDeclaration(i, rpn, result); } else if (element == "УПЛ") { result = ProcessIfStatement(j, k, _rpnByLines, result); } else if (element == "БП") { result = ProcessUnconditionalJump(i, rpn, result); } else if (IsBinaryOperator(element)) { result = ProcessBinaryOperator(result, element); } else if (element[element.Length - 1] == ':') { result.Add(new List <string> { element }); } else if (element == "=") { result = ProcessAssignmentOperator(result); } } } return(result); }