// Parses into function call public int Parse(string[] parts, int start) { // Start with call keyword if (parts[start] != "call") { throw new Exception("Function call starts with '" + parts[start] + " not 'call'!"); } else if (parts[start + 2] != ";") { throw new Exception("Function call does not end with ';'!"); } // Gets declaration FunctionDeclaration tempFD = Reserved.fEx.Find(f => f.funcName == parts[start + 1]); if (tempFD == null) { throw new Exception("Function '" + parts[start + 1] + "' does not exist!"); } else { fd = tempFD; return(start + 3); } }
// Identifies type given and parses into type. expContext is context that it will run on public static IdentifyResponse Identify(string context, string expContext, string[] parts, int start) { // If it is a reserved keyword if (Reserved.reservedKeywords.Contains(parts[start])) { /* Main File */ // If declaring desig if (context == "mainfile" && parts[start] == "desig") { DesigDeclaration dd = new DesigDeclaration(); return(new IdentifyResponse(dd, expContext, dd.Parse(parts, start))); } // If declaring variable else if (context == "mainfile" && parts[start] == "var") { VariableDeclaration vd = new VariableDeclaration(); return(new IdentifyResponse(vd, expContext, vd.Parse(parts, start))); } // If declaring function else if (context == "mainfile" && parts[start] == "func") { FunctionDeclaration fd = new FunctionDeclaration(); return(new IdentifyResponse(fd, expContext, fd.Parse(parts, start))); } // If declaring ruling else if (context == "mainfile" && parts[start] == "rule") { RulingResponse rr = Ruling.IdentifyRuling(parts, start); return(new IdentifyResponse(rr.icmf, expContext, rr.start)); } /* Function */ // If it is a function call else if (context == "function" && parts[start] == "call") { FuncCall fc = new FuncCall(); fc.context = expContext; return(new IdentifyResponse(fc, expContext, fc.Parse(parts, start))); } // If it is a context change else if (context == "function" && parts[start] == "context") { ContextChange cc = new ContextChange(); cc.context = expContext; return(new IdentifyResponse(cc, expContext, cc.Parse(parts, start))); } // If it is a specified command else if (context == "function" && parts[start] == "run") { RunCommand rc = new RunCommand(); rc.context = expContext; return(new IdentifyResponse(rc, expContext, rc.Parse(parts, start))); } /* Variable Assignation */ // If it is a literal else if (context == "variable expression" && parts[start] == "lit") { Literal lit = new Literal(); return(new IdentifyResponse(lit, expContext, lit.Parse(parts, start))); } /* Desig Assignation */ // If it is a literal else if (context == "desig expression" && parts[start] == "lit") { Literal lit = new Literal(); return(new IdentifyResponse(lit, expContext, lit.Parse(parts, start))); } } // Else if it is a Var assignation else if (context == "function" && Reserved.vEx.Exists(vd => vd.varName == parts[start])) { VariableAssignation va = new VariableAssignation(); va.context = expContext; return(new IdentifyResponse(va, expContext, va.Parse(parts, start))); } // Else if it is a Desig assignation else if (context == "function" && Reserved.dEx.Exists(dd => dd.desigName == parts[start])) { DesigAssignation da = new DesigAssignation(); da.context = expContext; return(new IdentifyResponse(da, expContext, da.Parse(parts, start))); } // If it is a variable else if (context == "variable expression" && Reserved.vEx.Exists(v => v.varName == parts[start])) { VarSubExpression vse = new VarSubExpression(); return(new IdentifyResponse(vse, expContext, vse.Parse(parts, start))); } // If it is a variable else if (context == "desig expression" && Reserved.vEx.Exists(v => v.varName == parts[start])) { VarSubExpression vse = new VarSubExpression(); return(new IdentifyResponse(vse, expContext, vse.Parse(parts, start))); } // If it is a desig else if (context == "desig expression" && Reserved.dEx.Exists(d => d.desigName == parts[start])) { DesigSubExpression dse = new DesigSubExpression(); return(new IdentifyResponse(dse, expContext, dse.Parse(parts, start))); } // Nonsensical answer throw new Exception("Inrecognized expression '" + parts[start] + "' in context '" + context + "'"); }