Example #1
0
 public ConsoleInstance()
 {
     screen         = new StringBuilder();
     variableHolder = new Variable <object> ();
     instanceDelegates.WriteText      = WriteTextOnConsoleBuffer;
     instanceDelegates.ActiveInstance = this;
     availableFunctions = new InvokerSet(instanceDelegates);
 }
Example #2
0
 public Command2(Receiver2 receiver)
 {
     Set     = receiver.SetData;
     Execute = receiver.DoIt;
     Redo    = receiver.DoIt;
     Undo    = delegate
     {
         Console.WriteLine("Not Implemented");
     };
 }
Example #3
0
 public Command(Receiver receiver)
 {
     Set = delegate
     {
         Console.WriteLine("Not Implemented - default of XXX used");
         receiver.S = "XXX";
     };
     Execute = receiver.Action;
     Redo    = receiver.Action;
     Undo    = receiver.Reverce;
 }
Example #4
0
        public void InterpretLine(string line)
        {
            string[][] commlist = Tokenizer.Tokenize(line);
            bool       hasret;

            hasret = false;
            int        funcpos, varstart;
            List <int> varpos = new List <int> ();

            foreach (string[] cs in commlist)
            {
                varpos.Clear();
                funcpos  = 0;
                varstart = 1;
                if (cs.Length == 0)
                {
                    continue;
                }
                if (cs.Length == 2)
                {
                    varstart = 1;
                }
                if (cs.Length > 2)
                {
                    if (cs[1] == "=")
                    {
                        hasret   = true;
                        funcpos  = 2;
                        varstart = 3;
                    }
                    else
                    {
                        varstart = 1;
                    }
                }

                /* Fetch the arguments */
                List <VariableTBase> argset = new List <VariableTBase> (cs.Length);
                int i;
                for (i = varstart; i < cs.Length; i++)
                {
                    if ((cs[i][0] == '$') | (cs[i][0] == '#'))
                    {
                        string[]      spl = cs[i].Split('.');
                        VariableTBase vtb;
                        try {
                            vtb = variableHolder;
                            foreach (string g in spl)
                            {
                                vtb = vtb.innerVariables[g];
                            }
                            argset.Add(vtb);
                        } catch (KeyNotFoundException) {
                            WriteTextOnConsoleBuffer("No such variable: " + cs[i]);
                            return;
                        }
                    }
                    else
                    {
                        if (cs[i][0] == '@')
                        {
                            int index1 = cs[i].IndexOf('(');
                            if (index1 == -1 | cs[i][cs[i].Length - 1] != ')')
                            {
                                WriteTextOnConsoleBuffer("Badly formatted input: " + cs[i] + " not valid syntax"); return;
                            }
                            string        nm   = cs[i].Substring(1, index1 - 1);
                            string        text = cs[i].Substring(index1 + 1, cs[i].Length - index1 - 2);
                            VariableTBase vb   = InvokerSet.ParseCreateVariable(nm, text, WriteTextOnConsoleBuffer);
                            if (vb == null)
                            {
                                return;
                            }
                            vb.name = "temp";
                            argset.Add(vb);
                            continue;
                        }
                        int tint;
                        if (int.TryParse(cs[i], out tint))
                        {
                            Variable <int> tmpvar = tint;
                            tmpvar.name = "temp";
                            argset.Add(tmpvar);
                        }
                        else
                        {
                            Variable <string> tmpvar = cs[i];
                            tmpvar.name = "temp";
                            argset.Add(tmpvar);
                        }
                    }
                }

                /* Call the function & set the return value */
                bool debug = true;
                if (!debug)
                {
                    try {
                        VariableTBase o = availableFunctions.Invoke(cs[funcpos], argset.ToArray());
                        if (hasret)
                        {
                            o.name = cs[0];
                            variableHolder.AddInnerVar(o.name, o);
                        }
                    } catch (Exceptions.UserException e) {
                        WriteTextOnConsoleBuffer(e.Message);
                        throw e;
                    } catch (Exception e) {
                        WriteTextOnConsoleBuffer("\n--------\nRuntime error: " + e.Message + "\nProbably bad code. Ask the nearest suitable programmer for help.\n--------");
                        System.Diagnostics.Debug.WriteLine(e.ToString(), "Runnable function errors.");
                        System.Diagnostics.Trace.WriteLine(e.ToString(), "Runnable function errors.");
                        throw e;
                    }
                }
                else
                {
                    VariableTBase o = availableFunctions.Invoke(cs[funcpos], argset.ToArray());
                    if (hasret)
                    {
                        o.name = cs[0];
                        variableHolder.AddInnerVar(o.name, o);
                    }
                }
            }
        }