public static object ResolveMethods(string Svalue, variables MainVars) { variables mv = new variables(); LineDefiner mld = new LineDefiner(mv); string file = Svalue.Split('(')[0]; string parameters = Svalue.Split('(')[1].TrimEnd(')'); string[] AllLines = File.ReadAllLines($"{file}.txt"); Regex trimmer = new Regex(@"\s\s+"); string s = trimmer.Replace(AllLines[0], " "); GetParameters(s, parameters, mv, MainVars); for (int i = 1; i < AllLines.Length; i++) { s = trimmer.Replace(AllLines[i], " "); s = s.TrimStart(' '); if (AllLines[i].StartsWith("return")) { s = s.Replace("return ", ""); return(mld.GetValue(s, ref i)); } mld.Define(AllLines[i], ref i); } return(""); }
public static string basicOperaticonsSingle(string line, variables vars) { string[] lineSplits = line.Split(' '); string a; string sign = lineSplits[0]; string ans = ""; if (vars.ValueExists(lineSplits[1])) { a = vars.GetValue(lineSplits[1]).TrimStart('*'); } else { a = lineSplits[1].TrimStart('*'); } switch (sign) { case "!": ans = negation(a); break; } return(ans); }
private static void GetParameters(string parameters, string values, variables vars, variables mainVars) { string[] par = parameters.Split(' '); string[] val = values.Split(' '); for (int i = 0; i < par.Length; i++) { vars.SetValue(par[i], (mainVars.ValueExists(val[i])?mainVars.GetValue(val[i]) : val[i])); } }
static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.Unicode; string path = Console.ReadLine(); string[] AllLines = File.ReadAllLines(path); MainVars = new variables(); LineDefiner MainLD = new LineDefiner(MainVars); for (int i = 0; i < AllLines.Length; i++) { MainLD.Define(AllLines[i], ref i); } }
public static string basicOperations(string line, variables vars) { string[] lineSplits = line.Split(' '); string a, b; string sign = lineSplits[1]; string ans = ""; if (vars.ValueExists(lineSplits[0])) { a = vars.GetValue(lineSplits[0]).TrimStart('*'); } else { a = lineSplits[0].TrimStart('*'); } if (vars.ValueExists(lineSplits[2])) { b = vars.GetValue(lineSplits[2]).TrimStart('*'); } else { b = lineSplits[2].TrimStart('*'); } switch (sign) { case "+": ans = Adding(a, b); break; case "-": ans = Subtracting(a, b); break; case "*": ans = Multiply(a, b); break; case "/": ans = Dividing(a, b); break; case "&": ans = And(a, b); break; case "|": ans = Or(a, b); break; case "^": ans = Same(a, b); break; case "<": ans = SmallerThan(a, b); break; case ">": ans = BiggerThan(a, b); break; case "%": ans = mod(a, b); break; } return(ans); }
public LineDefiner(variables var) { this.var = var; }