Exemple #1
0
 public For(CodeData data, List <Syntax> codes, string counter, Expression first, Expression last, Expression step)
 {
     this.data    = data;
     this.codes   = codes;
     this.counter = counter;
     this.first   = first;
     this.last    = last;
     this.step    = step;
 }
Exemple #2
0
 public For(CodeData data,List<Syntax>codes,string counter,Expression first,Expression last,Expression step)
 {
     this.data = data;
     this.codes = codes;
     this.counter = counter;
     this.first = first;
     this.last = last;
     this.step = step;
 }
Exemple #3
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)"));
     }
 }
Exemple #4
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"));
     }
 }
Exemple #5
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)"));
     }
 }
Exemple #6
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)"));
     }
 }
 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"));
 }
 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"));
 }
Exemple #9
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)));
        }
Exemple #10
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);
        }
Exemple #11
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)"));
     }
 }
Exemple #12
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)"));
            }
        }
 public Tree(TokenTree[] tree, CodeData data)
 {
     this.tree = tree;
     this.data = data;
     this.last = tree.Last().GetLast();
 }
        public Tree(string str, CodeData data, int count = 0)
        {
            this.data = data;
            int    column   = data.Column;
            int    line     = data.Line;
            string filename = data.Filename;

            List <TokenTree> list = new List <TokenTree>();
            bool             f    = false;
            int fir = count;
            int las = count;

            for (int i = count; i < str.Length; ++i)
            {
                if (str[i] == '"')
                {
                    list.Add(new Token(str, new CodeData(line, i, data.Filename), i));
                    i = list.Last().GetLast();
                }
                else if (str[i] == '(')
                {
                    if (f)
                    {
                        list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
                    }
                    list.Add(new Tree(str, new CodeData(line, i, data.Filename), i + 1));
                    i = list.Last().GetLast();
                    f = false;
                }
                else if (str[i] == ')')
                {
                    break;
                }
                else if (str[i] == '#')
                {
                    break;
                }
                else if (str[i] == ' ')
                {
                    if (f)
                    {
                        list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
                    }
                    f = false;
                }
                else if (str[i] == '\t')
                {
                    if (f)
                    {
                        list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
                    }
                    f = false;
                }
                else if (f)
                {
                    ++las;
                }
                else
                {
                    f   = true;
                    fir = i;
                    las = i + 1;
                }
            }
            if (f)
            {
                list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
            }
            this.tree = list.ToArray();
            this.last = tree.Count() > 0 ? tree.Last().GetLast() + 1 : 0;
        }
Exemple #15
0
 public While(CodeData data, List <Syntax> codes, Expression cond)
 {
     this.data  = data;
     this.codes = codes;
     this.cond  = cond;
 }
Exemple #16
0
 public static dynamic TypeName(dynamic[] arg, CodeData data)
 {
     return(arg[0].GetType().Name);
 }
Exemple #17
0
 public If(CodeData data, IEnumerable <Tuple <Expression, List <Syntax> > > codes, List <Syntax> elsecode)
 {
     this.data     = data;
     this.codes    = codes;
     this.elsecode = elsecode;
 }
Exemple #18
0
 public static dynamic PrintLine(dynamic[] arg, CodeData data)
 {
     Console.WriteLine(arg[0]);
     return(null);
 }
Exemple #19
0
 public If(CodeData data, IEnumerable<Tuple<Expression, List<Syntax>>> codes,List<Syntax>elsecode)
 {
     this.data = data;
     this.codes = codes;
     this.elsecode = elsecode;
 }
Exemple #20
0
 public static dynamic MakeArray(dynamic[] arg, CodeData data)
 {
     return(arg);
 }
 public Function(Func <dynamic[], CodeData, dynamic> func, Expression[] exprs, CodeData data)
 {
     this.func  = func;
     this.exprs = exprs;
     this.data  = data;
 }
 public Token(string token, CodeData data)
 {
     this.token = token;
     this.data  = data;
     this.last  = data.Column + token.Length;
 }
 public Value(string name, CodeData data)
 {
     this.name = name;
     this.data = data;
 }
        public Tree(string str,CodeData data,int count=0)
        {
            this.data = data;
            int column = data.Column;
            int line = data.Line;
            string filename = data.Filename;

            List<TokenTree> list = new List<TokenTree>();
            bool f = false;
            int fir = count;
            int las = count;

            for (int i = count; i < str.Length; ++i)
            {
                if(str[i]=='"')
                {
                    list.Add(new Token(str, new CodeData(line, i, data.Filename), i));
                    i = list.Last().GetLast();
                }
                else if(str[i]=='(')
                {
                    if (f) list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
                    list.Add(new Tree(str, new CodeData(line, i, data.Filename), i + 1));
                    i = list.Last().GetLast();
                    f = false;
                }
                else if(str[i]==')')
                {
                    break;
                }
                else if(str[i]=='#')
                {
                    break;
                }
                else if(str[i]==' ')
                {
                    if (f) list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
                    f = false;
                }
                else if(str[i]=='\t')
                {
                    if (f) list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
                    f = false;
                }
                else if(f)
                {
                    ++las;
                }
                else
                {
                    f = true;
                    fir = i;
                    las = i + 1;
                }
            }
            if (f) list.Add(new Token(str.Substring(fir, las - fir), new CodeData(line, fir, data.Filename)));
            this.tree = list.ToArray();
            this.last = tree.Count() > 0 ? tree.Last().GetLast() + 1 : 0;
        }
 public Token(string token,CodeData data)
 {
     this.token = token;
     this.data = data;
     this.last = data.Column + token.Length;
 }
 public Tree(TokenTree[] tree, CodeData data)
 {
     this.tree = tree;
     this.data = data;
     this.last = tree.Last().GetLast();
 }
Exemple #27
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));
        }
Exemple #28
0
 public While(CodeData data,List<Syntax>codes,Expression cond)
 {
     this.data = data;
     this.codes = codes;
     this.cond = cond;
 }