public void CountVariablesInCode() { List <string> variables = new List <string>(); for (int i = 0; i < NumberOfLinesInCode; i++) { variables.AddRange(_code[i].Split(' ')); } for (int i = 0; i < variables.Count; i++) { string str = variables[i]; int num = 1; for (int j = i + 1; j < variables.Count; j++) { if (variables[j] == str) { num++; variables.RemoveAt(j); j--; } } if (str != "") { OperandsInCode.Add(str, num); } } }
public void CountConstNumbers() { List <string> constNumbers = new List <string>(); bool isNumber = false, isNumeral = false; string constNumber = ""; for (int i = 0; i < NumberOfLinesInCode; i++) { string line = _code[i]; for (int j = 0; j < line.Length; j++) { char ch = line[j]; if ((ch >= '0' && ch <= '9') || ch == '.' || ch == '-') { if (ch == '-' && constNumber.Length != 0) { isNumber = false; isNumeral = false; constNumber = null; constNumber = ""; continue; } if (ch >= '0' && ch <= '9') { isNumeral = true; } isNumber = true; constNumber = constNumber.Insert(constNumber.Length, ch.ToString()); if (j == line.Length - 1 && isNumeral && (j - constNumber.Length + 1 == 0 || line[j - constNumber.Length] == ' ')) { j = j - constNumber.Length + 1; _code[i] = _code[i].Remove(j, constNumber.Length); _code[i] = _code[i].Insert(j, " "); line = _code[i]; constNumbers.Add(constNumber); } } else if (isNumber) { if (isNumeral) { if (line[j] == ' ' && (j - constNumber.Length == 0 || line[j - constNumber.Length - 1] == ' ')) { j -= constNumber.Length; _code[i] = _code[i].Remove(j, constNumber.Length); _code[i] = _code[i].Insert(j, " "); line = _code[i]; constNumbers.Add(constNumber); } } isNumber = false; isNumeral = false; constNumber = null; constNumber = ""; } } isNumber = false; isNumeral = false; constNumber = null; constNumber = ""; } for (int i = 0; i < constNumbers.Count; i++) { string str = constNumbers[i]; int num = 1; for (int j = i + 1; j < constNumbers.Count; j++) { if (constNumbers[j] == str) { num++; constNumbers.RemoveAt(j); j--; } } OperandsInCode.Add(str, num); } }
public void CountConstStrings() { List <string> constStrings = new List <string>(); char quote = '\''; bool inQuotes = false; string constString = null; for (int i = 0; i < NumberOfLinesInCode; i++) { string line = _code[i]; for (int j = 0; j < line.Length; j++) { char ch = line[j]; if (inQuotes) { _code[i] = _code[i].Remove(j, 1); _code[i] = _code[i].Insert(j, " "); line = _code[i]; if (ch == quote) { if (constString.Last() == '\\' && constString[constString.Length - 2] != '\\') { constString = constString.Insert(constString.Length, ch.ToString()); continue; } inQuotes = false; constString = constString.Insert(constString.Length, ch.ToString()); constStrings.Add(constString); constString = null; continue; } else { constString = constString.Insert(constString.Length, ch.ToString()); } } else if (ch == '\'' || ch == '"') { constString = ""; constString = constString.Insert(constString.Length, ch.ToString()); quote = ch; inQuotes = true; _code[i] = _code[i].Remove(j, 1); _code[i] = _code[i].Insert(j, " "); line = _code[i]; } } if (inQuotes) { constString = constString.Insert(constString.Length, '\n'.ToString()); } } for (int i = 0; i < constStrings.Count; i++) { string str = constStrings[i]; int num = 1; for (int j = i + 1; j < constStrings.Count; j++) { if (constStrings[j] == str) { num++; constStrings.RemoveAt(j); j--; } } OperandsInCode.Add(str, num); } }