Esempio n. 1
0
 public static dynamic IntParse(dynamic[] arg, CodeData data)
 {
     try
     {
         return(int.Parse(arg[0]));
     }
     catch (Exception)
     {
         throw new Exception(data.ExceptionMessage("invalid argument type"));
     }
 }
Esempio n. 2
0
 public static dynamic OperatorLeftShift(dynamic[] arg, CodeData data)
 {
     try
     {
         return(arg[0] << arg[1]);
     }
     catch (Exception)
     {
         throw new Exception(data.ExceptionMessage("operator<< error(dont use with those types)"));
     }
 }
Esempio n. 3
0
 public static dynamic OperatorBitNot(dynamic[] arg, CodeData data)
 {
     try
     {
         return(!arg[0]);
     }
     catch (Exception)
     {
         throw new Exception(data.ExceptionMessage("operator! error(dont use with those types)"));
     }
 }
Esempio n. 4
0
 public static dynamic ArrayAccess(dynamic[] arg, CodeData data)
 {
     try
     {
         return(arg[0][arg[1]]);
     }
     catch (Exception exp)
     {
         throw new Exception(data.ExceptionMessage("at error(privided error type)"));
     }
 }
Esempio n. 5
0
 public Token(string str, CodeData data, int count)
 {
     for (int i = 1; i < str.Length; ++i)
     {
         if (str[i + count] == '"')
         {
             this.token = str.Substring(count, i + 1);
             this.data  = data;
             this.last  = count + i;
             return;
         }
     }
     throw new Exception(data.ExceptionMessage("termination of string literal was not found"));
 }
Esempio n. 6
0
        public dynamic ValueEval(Dictionary <string, dynamic> local, ScriptRunner runner)
        {
            dynamic val = 0;

            if (local.TryGetValue(name, out val))
            {
                return(val);
            }
            if (runner.Global.TryGetValue(name, out val))
            {
                return(val);
            }
            throw new Exception(data.ExceptionMessage(string.Format("valuename {0} was not found in this scope.", name)));
        }
Esempio n. 7
0
        /// <summary>
        /// エントリーポイントから実行します
        /// </summary>
        /// <param name="entry_point">エントリーポイントです</param>
        /// <param name="argument">エントリーポイントに渡される引数です</param>
        /// <returns>実行の結果の返り値です</returns>
        public dynamic ScriptRun(string entry_point, dynamic[] argument)
        {
            Tuple <int, Func <dynamic[], CodeData, dynamic> > v;

            if (!function.TryGetValue(entry_point, out v))
            {
                throw new Exception(CodeData.ExceptionMessage(string.Format("entrypoint {0} was not found", entry_point), filename, 0, 0));
            }
            if (v.Item1 >= 3 || v.Item1 < 0)
            {
                throw new Exception(CodeData.ExceptionMessage(string.Format("entry point {0} parameter is invalid"), filename, 0, 0));
            }
            return(v.Item2(new dynamic[] { argument, argument.Length }, new CodeData(0, 0, Filename)));
        }
Esempio n. 8
0
        public static dynamic OperatorMulti(dynamic[] arg, CodeData data)
        {
            dynamic ret = arg[0];

            try
            {
                foreach (var v in arg.Skip(1))
                {
                    ret *= v;
                }
            }
            catch (Exception)
            {
                throw new Exception(data.ExceptionMessage("operator* error(dont use with those types)"));
            }
            return(ret);
        }
Esempio n. 9
0
 public static dynamic OperatorLogicOr(dynamic[] arg, CodeData data)
 {
     try
     {
         foreach (var v in arg)
         {
             if (v)
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception)
     {
         throw new Exception(data.ExceptionMessage("operator|| error(dont use with those types)"));
     }
 }
Esempio n. 10
0
        public dynamic Run(ref Dictionary <string, dynamic> local, ScriptRunner runner)
        {
            dynamic first = this.first.ValueEval(local, runner);
            dynamic last  = this.last.ValueEval(local, runner);
            dynamic step  = this.step.ValueEval(local, runner);

            if (local.ContainsKey(counter))
            {
                throw new Exception(data.ExceptionMessage(string.Format("valuename {0} has been defined in this scopr", counter)));
            }
            for (var d = first; d != last; d += step)
            {
                local[counter] = d;
                runner.Run(codes, local);
                d = local[counter];
            }
            local.Remove(counter);
            return(null);
        }
Esempio n. 11
0
        public static dynamic OperatorEqual(dynamic[] arg, CodeData data)
        {
            dynamic v = arg[0];

            try
            {
                foreach (var u in arg.Skip(1))
                {
                    if (v != u)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                throw new Exception(data.ExceptionMessage("operator= error(dont use with those types)"));
            }
        }
Esempio n. 12
0
        Tuple <List <Syntax>, int, ReturnFlag> SyntaxParse(
            IEnumerable <TokenTree> trees,
            string filename,
            Dictionary <string, Func <dynamic[], ScriptRunner, dynamic> > system_command,
            IEnumerable <Func <string, Expression> > literal_checker)
        {
            List <Syntax> code = new List <Syntax>();
            int           i    = 0;
            int           skip = 0;

            foreach (var token in trees)
            {
                ++i;
                if (skip > 0)
                {
                    --skip;
                    continue;
                }
                var vec = token.GetTree();

                if (vec.Length == 0)
                {
                    continue;
                }
                var com = vec[0].GetToken();
                if (com == null)
                {
                    throw new Exception(CodeData.ExceptionMessage("invalid command", filename, i, 0));
                }
                Func <dynamic[], ScriptRunner, dynamic> sys;
                if (system_command.TryGetValue(com, out sys))
                {
                    var ar = from e in vec.Skip(1) select ExpressionParse(e, literal_checker);

                    var v = from e in ar select e.ValueEval(new Dictionary <string, dynamic>(), this);

                    sys(v.ToArray(), this);
                    continue;
                }
                if (com == "for")
                {
                    SyntaxParseFor(ref i, ref skip, code, token, vec, trees, filename, system_command, literal_checker);
                }

                else if (com == "next")
                {
                    return(Tuple.Create(code, i, ReturnFlag.Next));
                }
                else if (com == "while")
                {
                    SyntaxParsingWhile(ref i, ref skip, code, token, vec, trees, filename, system_command, literal_checker);
                }
                else if (com == "loop")
                {
                    return(Tuple.Create(code, i, ReturnFlag.Loop));
                }
                else if (com == "if")
                {
                    SyntaxParsingIf(ref i, ref skip, code, token, vec, trees, filename, system_command, literal_checker);
                }
                else if (com == "elif")
                {
                    return(Tuple.Create(code, i, ReturnFlag.Elif));
                }
                else if (com == "else")
                {
                    return(Tuple.Create(code, i, ReturnFlag.Else));
                }
                else if (com == "endif")
                {
                    return(Tuple.Create(code, i, ReturnFlag.Endif));
                }
                else if (com == "def")
                {
                    SyntaxParsingDef(ref i, ref skip, code, token, vec, trees, filename, system_command, literal_checker);
                }
                else if (com == "let")
                {
                    SyntaxParsingLet(ref i, ref skip, code, token, vec, trees, filename, system_command, literal_checker);
                }
                else if (com == "global")
                {
                    SyntaxParsingGlobal(ref i, ref skip, code, token, vec, trees, filename, system_command, literal_checker);
                }
                else if (com == "return")
                {
                    Expression expr = vec.Length == 1 ? new Literal(null) : ExpressionParse(new Tree(vec.Skip(1).ToArray(), vec[1].GetData()), literal_checker);
                    code.Add(new Return(expr));
                }
                else
                {
                    code.Add(new Expr(ExpressionParse(token, literal_checker)));
                }
            }
            return(Tuple.Create(code, i, ReturnFlag.None));
        }