public void HandleAssignment(ASTNode node) { string variableName = node.Descendants[0].Token.Text; int variableScope = SemanticAnalyser.VariableChecker.FindSymbol(node.Descendants[0], node.AppearsInScope); TempTableEntry variableTemp = StaticTemp.GetTempTableEntry(variableName, variableScope); string type = variableTemp.Type; string[] tempAddressBytes = variableTemp.Address.Split(" "); switch (type) { case "int": HandleIntegerAssignment(node, variableScope, tempAddressBytes); break; case "boolean": HandleBooleanAssignment(node, variableScope, tempAddressBytes); break; case "string": HandleStringAssignment(node, variableScope, tempAddressBytes); break; } node.Descendants[0].Visited = true; node.Descendants[1].Visited = true; }
public void HandlePrintIdentifier(ASTNode node) { TempTableEntry staticEntry = StaticTemp.GetTempTableEntry(node.Token.Text, node.ReferenceScope); string variableType = staticEntry.Type; string[] tempAddressBytes = staticEntry.Address.Split(" "); switch (variableType) { case "int": Image.WriteByte("AC"); Image.WriteByte(tempAddressBytes[0]); Image.WriteByte(tempAddressBytes[1]); Image.WriteByte("A2"); Image.WriteByte("01"); Image.WriteByte("FF"); break; case "boolean": HandlePrintBoolean((int)EvaluateBooleanSubtree(node)); break; case "string": HandlePrintString(node); break; } }
public void BackPatch(TempTableEntry variable, string address) { string[] splitAddress = address.Split(" "); for (int i = 0; i < Bytes.GetLength(0); i++) { for (int j = 0; j < Bytes.GetLength(1); j++) { if (j + 1 < Bytes.GetLength(1)) { if ($"{Bytes[i,j]} {Bytes[i, j+1]}" == variable.Address) { Bytes[i, j] = splitAddress[0]; Bytes[i, j + 1] = splitAddress[1]; } } else { if (i + 1 < Bytes.GetLength(0)) { if ($"{Bytes[i,j]} {Bytes[i + 1, 0]}" == variable.Address) { Bytes[i, j] = splitAddress[0]; Bytes[i + 1, 0] = splitAddress[1]; } } } } } // handle inserting the value of the variable into the stack once backpatching has been performed string[] splitValue = variable.Value.Split(" "); for (int i = 0; i < splitValue.Length; i++) { this.WriteByte(splitValue[i]); } variable.BackPatch(address); }