public static void linkFunctionCall(FunctionCall theFunc, int lineNumber, Compiler.Scope currentScope) { Compiler.Function searchedFunc = currentScope.scopeFunctions.getSavedFunction(theFunc.name, lineNumber); if (searchedFunc != null) { Compiler.Variable[] inputVariables = validParameters(PackageUnWrapper.removeSurrondingParanteser(theFunc.parameter), searchedFunc, lineNumber, currentScope); theFunc.targetFunc = searchedFunc; } }
public static bool hasReturnValue(string word, int lineNumber) { Compiler.Function searchedFunc = Camera.main.GetComponent <HelloCompiler>().funcs.getSavedFunction(FunctionParser.getFunctionName(word, lineNumber), lineNumber); if (searchedFunc != null) { return(searchedFunc.hasReturnVariable); } return(false); }
static Compiler.Variable[] validParameters(string trimmedPara, Compiler.Function calledFunction, int lineNumber, Compiler.Scope currentScope) { string[] words = Compiler.WordParser.parseWords(trimmedPara); if (words.Length != 0) { Compiler.Logic[] logicOrder = WordLogic.determineLogicFromWords(words, lineNumber, currentScope); List <List <Compiler.Logic> > packedLogics = convertIntoParameterLogic(words, logicOrder, lineNumber); if (packedLogics != null) { Compiler.Variable[] inputVariables = new Compiler.Variable[packedLogics.Count]; for (int i = 0; i < packedLogics.Count; i++) { inputVariables [i] = ValidSumCheck.checkIfValidSum(packedLogics [i].ToArray(), lineNumber); } foreach (Compiler.Variable v in inputVariables) { if (v.variableType == Compiler.VariableTypes.unkown) { ErrorMessage.sendErrorMessage(lineNumber, "one or several of the input parameters to function: " + calledFunction.name + " are corrupt!"); } } if (calledFunction.inputParameters.Contains(inputVariables.Length)) { return(inputVariables); } } } if (calledFunction.inputParameters.Contains(0)) { return(new Compiler.Variable[0]); } ErrorMessage.sendErrorMessage(lineNumber, "Amount of parameters does not match Expected!"); return(new Compiler.Variable[0]); }
public void BuildLevelSettings(int levelNumber, string settingsFileName) { this.levelNumber = levelNumber; TextAsset asset = Resources.Load <TextAsset> (settingsFileName); if (asset == null) { if (!settingsFileName.StartsWith("-")) { Debug.Log("The levelsettings file \"" + settingsFileName + "\" could not be found. Ignore if you want no settings for level " + levelNumber); } levelSetting = new LevelSetting(); caseHandler = new CaseHandler(1); return; } string[] textRows = asset.text.Split(linebreaks, StringSplitOptions.RemoveEmptyEntries); string taskDescription = ""; string preCode = ""; string startCode = ""; int rowLimit = 100; int numberOfCases = 1; float gameSpeed = -1; string[] smartButtons = new string[0]; List <Compiler.Function> functions = new List <Compiler.Function>(); for (int i = 0; i < textRows.Length; i++) { // Ignore comments if (textRows [i].StartsWith("//")) { continue; } string[] splittedRow = textRows[i].Split(':'); switch (splittedRow[0].ToLower()) { case "taskdescription": taskDescription = JoinSplittedText(splittedRow); break; case "precode": preCode = JoinSplittedText(splittedRow); break; case "startcode": startCode = JoinSplittedText(splittedRow); break; case "rowlimit": bool couldParse = int.TryParse(splittedRow[1], out rowLimit); if (!couldParse) { throw new Exception("The row with rowLimit must have an integer after :"); } break; case "casecount": couldParse = int.TryParse(splittedRow [1].Trim(), out numberOfCases); if (!couldParse) { throw new Exception("The casecount could not be parsed. There must be an integer after :"); } break; case "gamespeed": couldParse = float.TryParse(splittedRow[1], out gameSpeed); if (!couldParse) { throw new Exception("The row with gameSpeed must have a float after :"); } break; case "smartbuttons": smartButtons = splittedRow [1].Trim().Replace(" ", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Automatically add AnswerFunction if there is a smart button with name "svara()" foreach (string buttonName in smartButtons) { if (buttonName == "svara()") { functions.Add(new AnswerFunction()); } } break; case "functions": string[] functionsNames = splittedRow [1].Trim().Replace(" ", "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Use reflection to get an instance of compiler function class from string foreach (string functionName in functionsNames) { Type type = Type.GetType(functionName); if (type == null) { throw new Exception("Function name: \"" + functionName + "\" could not be found."); } Compiler.Function function = (Compiler.Function)Activator.CreateInstance(type); functions.Add(function); } break; default: Debug.Log("Row number " + i + " could not be parsed"); break; } } levelSetting = new LevelSetting(taskDescription, preCode, startCode, rowLimit, numberOfCases, gameSpeed, smartButtons, functions.ToArray()); // this should perhaps be moved somewhere else //caseHandler = new CaseHandler (numberOfCases); }
public override string CallFunction(Compiler.Function function) { return("function " + function.gameName.Replace(":", "/")); }
public override string DefineFunction(Compiler.Function function) { throw new NotImplementedException(); }
public abstract string CallFunction(Compiler.Function function);
public abstract string DefineFunction(Compiler.Function function);
public override string CallFunction(Compiler.Function function) { return("function " + function.gameName); }