static void CALL_Execute(SIL_Action action) { SILFunction function = (SILFunction)action.ParsingArgs[0]; ISILObject value = function.Value; action.ExecutionArgs = new object[] { value }; }
public static void Execute() { SILFunction mainFunction = new SILFunction("Main", new ISILObject[] {}); SIL_Action action = new SIL_Action(ActionType.CALL, new object[] { mainFunction }, 0, "Main"); action.OnAction += new SIL_Action.Action(action_OnAction); executeSymbols_[action.ActionType](action); //first execute internal logic action.Execute(); //lin action with GUI }
static void WHILE_Execute(SIL_Action action) { while ((int)((SILInteger)((ISILObject)action.ParsingArgs[0]).Value) > 0) { Queue <SIL_Action> nestedActions = new Queue <SIL_Action>((Queue <SIL_Action>)action.ParsingArgs[1]); while (nestedActions.Count > 0) { SIL_Action nestedAction = nestedActions.Dequeue(); executeSymbols_[nestedAction.ActionType](nestedAction); //first execute internal logic nestedAction.Execute(); //lin action with GUI } } }
/// <summary> /// Converts a line of code in SIL Action /// </summary> /// <param name="line">full unedited line</param> /// <returns>new SIL_Action object</returns> public static Queue <SIL_Action> Parse(string source, Compiler.Action exeAction) { sourceLines_ = source.Split('\n'); exeAction_ = exeAction; Queue <SIL_Action> actions = new Queue <SIL_Action>(); for (int i = 0; i < sourceLines_.Length; i++) { SIL_Action action = Parser.ParseNext("Main", ref i); if (action != null) { actions.Enqueue(action); } } return(actions); }
static void FOR_Execute(SIL_Action action) { //execute first LET statement once SIL_Action LETAction = (SIL_Action)action.ParsingArgs[0]; executeSymbols_[ActionType.LET](LETAction); //first execute internal logic LETAction.Execute(); while ((int)((SILInteger)((ISILObject)action.ParsingArgs[1]).Value) > 0) { Queue <SIL_Action> nestedActions = new Queue <SIL_Action>((Queue <SIL_Action>)action.ParsingArgs[2]); while (nestedActions.Count > 0) { SIL_Action nestedAction = nestedActions.Dequeue(); executeSymbols_[nestedAction.ActionType](nestedAction); //first execute internal logic nestedAction.Execute(); //lin action with GUI } } }
static void PRINT_Execute(SIL_Action action) { //if there is arithmetic involved it needs to be executed here //At the moment no variables or arithmetic exists so we just build a single string to print string textToPrint = ""; foreach (object arg in action.ParsingArgs) { if (arg.GetType() == typeof(string)) { textToPrint += (string)arg; } if (arg is ISILObject) { ISILObject silObj = (ISILObject)arg; int n = (SILInteger)silObj.Value; textToPrint += n.ToString(); } } action.ExecutionArgs = new string[] { textToPrint }; }
static SIL_Action ParseNext(string functionspace, ref int lineNumber) { string line = sourceLines_[lineNumber].Trim(); while ((line == "" || (line.Length >= 2 ? line.Substring(0, 2) == "//" : false)) && lineNumber < sourceLines_.Length) { lineNumber++; line = sourceLines_[lineNumber].Trim(); } if (lineNumber == sourceLines_.Length) { return(null); } string[] symbols = line.Split(' '); if (!parserSymbols_.ContainsKey(symbols[0])) { throw new Exception(string.Format("Unidentified command: {0}%{1}", symbols[0], lineNumber)); } object[] paramters = null; //We catch internal exception here and format it for future display in GUI try { ActionType actionType = parserSymbols_[symbols[0]]( functionspace, line, ref paramters, ref lineNumber); SIL_Action action = new SIL_Action(actionType, paramters, lineNumber, functionspace); action.OnAction += new SIL_Action.Action(exeAction_); return(action); } catch (Exception parseSymbolException) { throw new Exception(string.Format("{0}%{1}", parseSymbolException.Message, lineNumber)); } }
static void READ_Execute(SIL_Action action) { action.ExecutionArgs = action.ParsingArgs; }
static void DRAWLINE_Execute(SIL_Action action) { action.ExecutionArgs = action.ParsingArgs; }
static void NEXT_Execute(SIL_Action action) { //--- }
static void WEND_Execute(SIL_Action action) { //--- }
static void LET_Execute(SIL_Action action) { ISILObject varOrArrElement = (ISILObject)action.ParsingArgs[0]; varOrArrElement.Value = ((ISILObject)action.ParsingArgs[1]).Value; }
static void ENDIF_Execute(SIL_Action action) { //--- }
/// <summary> /// FOR is basically 2 actions: LET and WHILE combined with incrementing equation /// </summary> /// <param name="unparsedArgs"></param> /// <param name="parsedArgs"></param> /// <param name="lineNumber"></param> /// <returns></returns> static ActionType FOR_Parse(string functionspace, string unparsedArgs, ref object[] parsedArgs, ref int lineNumber) { //FOR i = 3, i < 10, i = i + 1 //remove the FOR word string parameters = unparsedArgs.Substring(4, unparsedArgs.Length - 4); //validate and decompose the string string[] split = parameters.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (split.Length < 3) { throw new Exception("Incorrect syntax! Use \"FOR variable, condition, increment\""); } parsedArgs = new object[3]; Queue <SIL_Action> actions_ = new Queue <SIL_Action>(); //Create LET statement object[] parsedArgsLET = null; parserSymbols_["LET"]( functionspace, "LET " + split[0], //we have to add "LET " string in front for parser to recognize this command as LET ref parsedArgsLET, ref lineNumber); SIL_Action LETaction = new SIL_Action(ActionType.LET, parsedArgsLET, lineNumber, functionspace); LETaction.OnAction += new SIL_Action.Action(exeAction_); parsedArgs[0] = LETaction; //Parse condition try { SILEquation condition = (SILEquation)ExpressionParse(functionspace, split[1], new List <ISILObject>()); parsedArgs[1] = condition; } catch (Exception conidtionEx) { throw conidtionEx; throw new Exception("Condition must be an equation"); } //Parse increment object[] parsedArgsINCREMENT = null; parserSymbols_["LET"]( functionspace, "LET " + split[2], ref parsedArgsINCREMENT, ref lineNumber); SIL_Action INCREMENTaction = new SIL_Action(ActionType.LET, parsedArgsINCREMENT, lineNumber, functionspace); INCREMENTaction.OnAction += new SIL_Action.Action(exeAction_); //Parse everythig inside FOR block SIL_Action action; do { lineNumber++; if (lineNumber >= sourceLines_.Length) { throw new Exception("NEXT expected!"); } action = ParseNext(functionspace, ref lineNumber); if (action != null) { actions_.Enqueue(action); } } while (action.ActionType != ActionType.NEXT); //Add increment action last actions_.Enqueue(INCREMENTaction); parsedArgs[2] = actions_; return(ActionType.FOR); }
static void ENDFUNCTION_Execute(SIL_Action action) { }
static void FUNCTION_Execute(SIL_Action action) { //--- }
static void DECLARE_Execute(SIL_Action action) { //--- }
static void ARRAY_Execute(SIL_Action action) { SILArray array = (SILArray)action.ParsingArgs[0]; array.Allocate(); }
static void INTEGER_Execute(SIL_Action action) { string silVar = (string)action.ParsingArgs[0]; SymbolTable.Add(silVar); }
static void RETURN_Execute(SIL_Action action) { ISILObject returnValue = (ISILObject)action.ParsingArgs[0]; action.ExecutionArgs = new object[] { returnValue.Value }; }
internal static void Execute(SIL_Action action) { executeSymbols_[action.ActionType](action); action.Execute(); }