示例#1
0
        public bool CheckOne() //no more then return false;
        {
            var s = m_sr.get();

            if (m_sr.m_err == SrcReader.ERR.eof)
            {
                var vtmp = new VALUE();
                vtmp.type = YDEF.EOF;
                add(vtmp);
                end_line();
                return(false);
            }

            int wdlen;
            var v = lexUtil.GetWord(out wdlen, m_c, m_sr.m_src, m_l);

            m_c += wdlen;

            add(v);

            if (v.type == YDEF.ERROR)
            {
                sys.error(string.Format("L:{0}C:{1}>{2}", v.dbg_line, v.dbg_col, v.s));
                return(false);
            }

            if (v.type == YDEF.EOL)
            {
                end_line();
                //m_l++;
                //m_c = 0;
            }

            return(true);
        }
示例#2
0
        private static VALUE find(VALUE v, object[] o)
        {
            var t  = getyp(o);
            var fv = v.FindValueByTravarse(t);

            return(fv);
        }
示例#3
0
        public bool ReplaceValueByTravarse(int itype, VALUE dst) //トラバースして、最初に見つけたのを入れ替える。
        {
            if (itype == type)                                   //自身の入れ替えはNG
            {
                sys.logline("Unexpected. Cannot replace self");
                return(false);
            }
            if (list == null)
            {
                return(false);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].type == itype)
                {
                    list[i] = dst;
                    return(true);
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].ReplaceValueByTravarse(itype, dst))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        public bool CheckOne() //no more then return false;
        {
            if (m_l >= m_lines.Length)
            {
                var vtmp = new VALUE();
                vtmp.type = YDEF.EOF;
                add(vtmp);
                end_line();
                return(false);
            }

            int wdlen;
            var v = lexUtil.GetWord(out wdlen, m_c, m_lines[m_l], m_l);

            m_c += wdlen;

            add(v);

            if (v.type == YDEF.ERROR)
            {
                sys.error(string.Format("L:{0}C:{1}>{2}", v.dbg_line, v.dbg_col, v.s));
                return(false);
            }

            if (v.type == YDEF.EOL)
            {
                end_line();
                m_l++;
                m_c = 0;
            }

            return(true);
        }
示例#5
0
 void add(VALUE v)
 {
     if (m_curline_value == null)
     {
         m_curline_value = new List <VALUE>();
     }
     m_curline_value.Add(v);
 }
示例#6
0
文件: sys.cs 项目: NNNIC/haxe-test
        public static void error(string s, VALUE v = null)
        {
            int line = -1;

            if (v != null)
            {
                line = v.get_dbg_line();
            }

            string es = "ERROR" + (line >= 0 ? "(L:" + (line + 1).ToString() + ")" : "") + ":" + s;

            Console.WriteLine(es);
            throw new SystemException(es);
        }
示例#7
0
 static VALUE any_return(VALUE v, int type, double?n = null, string s = null)
 {
     v.type = type;
     if (n != null)
     {
         v.o = v.n = (double)n;
     }
     if (s != null)
     {
         v.s = s;
         if (v.o == null)
         {
             v.o = v.s;
         }
     }
     if (v.o == null)
     {
         v.o = type;
     }
     return(v);
 }
示例#8
0
 private static bool replace_l(List <VALUE> l, int typ, VALUE dst)
 {
     for (int i = 0; i < l.Count; i++)
     {
         var v = l[i];
         if (v.type == typ)
         {
             l[i] = dst;
             return(true);
         }
     }
     for (int i = 0; i < l.Count; i++)
     {
         var v = l[i];
         var b = replace(v, typ, dst);
         if (b)
         {
             return(true);
         }
     }
     return(false);
 }
示例#9
0
 private static bool replace(VALUE src, int typ, VALUE dst)
 {
     return(src.ReplaceValueByTravarse(typ, dst));
 }
示例#10
0
        private static VALUE find(VALUE v, int typ)
        {
            var fv = v.FindValueByTravarse(typ);

            return(fv);
        }
示例#11
0
        public List <List <VALUE> > PreProcess(List <List <VALUE> > src)
        {
            Hashtable ht = new Hashtable(); //変数用

            var out_list = new List <List <VALUE> >();

            bool bIfZone = false;
            bool?bIfTree = null;

            foreach (var l in src)
            {
                if (l.Count == 0)
                {
                    continue;
                }
                VALUE v0 = l[0];
                if (v0.IsType(getyp(YDEF.sx_prepro_setence)))   //#if #elif #else #endif
                {
                    if (v0.IsType(getyp(YDEF.sx_pif_sentence))) //#if
                    {
                        if (bIfZone)
                        {
                            sys.error("Not supported Dual #if");
                        }
                        bIfZone = true;
                        var func = find(v0, YDEF.sx_function);
                        if (func == null)
                        {
                            sys.error("Can not find function for #if", v0);
                        }
                        bIfTree = runtime.PreProcessFunction.Execute(func);
                        continue;
                    }
                    if (v0.IsType(getyp(YDEF.sx_pelif_sentence)))//#elif
                    {
                        if (!bIfZone)
                        {
                            sys.error("Preceed #if does not exist", v0);
                        }
                        if (bIfTree == true)
                        {
                            bIfTree = null;
                        }
                        if (bIfTree == null)
                        {
                            sys.logline("skip");
                        }
                        var func = find(v0, YDEF.sx_function);
                        if (func == null)
                        {
                            sys.error("Can not find function for #elif", v0);
                        }
                        bIfTree = runtime.PreProcessFunction.Execute(func);
                        continue;
                    }
                    if (v0.IsType(getyp(YDEF.sx_pelse_sentence)))//else
                    {
                        if (!bIfZone)
                        {
                            sys.error("Preceed #if does not exist", v0);
                        }
                        if (bIfTree == true)
                        {
                            bIfTree = null;
                        }
                        if (bIfTree == null)
                        {
                            sys.logline("skip");
                        }
                        else
                        {
                            bIfTree = true;
                        }
                        continue;
                    }
                    if (v0.IsType(getyp(YDEF.sx_pendif_sentence)))//endif
                    {
                        if (!bIfZone)
                        {
                            sys.error("Preceed #if does not exist", v0);
                        }
                        bIfZone = false;
                        bIfTree = null;
                        continue;
                    }

                    if (v0.IsType(getyp(YDEF.sx_pset_sentence)))//set
                    {
                        //#set will process later.
                    }
                    else //以外はエラー
                    {
                        sys.error("Unexpected", v0);
                    }
                }

                if (bIfZone == false || (bIfZone == true && bIfTree == true))
                {
                    if (v0.IsType(getyp(YDEF.sx_pset_sentence)))
                    {
                        var varv = find(v0, YDEF.VAR);
                        if (varv == null)
                        {
                            sys.error("Cannot find set variable", v0);
                        }
                        var rest = find(v0, YDEF.REST);
                        if (rest == null)
                        {
                            sys.error("Cannot find set rest", v0);
                        }
                        ht[varv.GetString()] = rest;
                        continue;
                    }
                    var findvar = find_l(l, YDEF.VAR);
                    if (findvar != null)
                    {
                        var key = findvar.GetString();
                        if (ht.ContainsKey(key))
                        {
                            if (!replace_l(l, YDEF.VAR, (VALUE)ht[key]))
                            {
                                sys.error("Cannot converted", v0);
                            }
                        }
                        else
                        {
                            sys.error(key + " has not been defined", v0);
                        }
                    }

                    var newl = l;
                    YDEF.insert_rest_children_if_use(ref newl);
                    out_list.Add(newl);
                }
            }
            //dbg_out_list = out_list;
            return(out_list);
        }
示例#12
0
 void add(VALUE v)
 {
     m_value_list.Add(v);
 }
示例#13
0
 // -- util for this clas --
 static VALUE err_return(VALUE v, string s)
 {
     v.type = YDEF.ERROR;
     v.o    = v.s = s;
     return(v);
 }
示例#14
0
        public static VALUE GetWord(out int wdlen, int col, string i_line, int dbg_line = -1)
        {
            var v = new VALUE();

            v.type     = YDEF.UNKNOWN;
            v.dbg_col  = col;
            v.dbg_line = dbg_line;

            wdlen = 0;
            if (string.IsNullOrEmpty(i_line))
            {
                wdlen = 1; return(any_return(v, YDEF.EOL));
            }

            var line = i_line.TrimEnd();

            if (string.IsNullOrEmpty(line) || col >= line.Length)
            {
                wdlen = 1; return(any_return(v, YDEF.EOL));
            }

            var ls = i_line.Substring(col);

            if (string.IsNullOrEmpty(ls))
            {
                wdlen = 1;  return(any_return(v, YDEF.EOL));
            }

            //コメントは全部
            if (ls.StartsWith(YDEF.CMTSTR))
            {
                wdlen = ls.Length;
                return(any_return(v, YDEF.CMT, null, ls));
            }

            //コメント /* */で囲まれた部分


            //ダブルクォーテーションで囲まれた文字列はそのまま
            if (ls.StartsWith(YDEF.DQ))
            {
                if (ls.Length > 1)
                {
                    var idx = ls.IndexOf(YDEF.DQ, 1);
                    if (idx < 0)
                    {
                        return(err_return(v, "End of Double Quatation is not found:1"));
                    }
                    wdlen = idx + 1;
                    return(any_return(v, YDEF.QSTR, null, ls.Substring(0, idx + 1)));
                }
                else
                {
                    return(err_return(v, "End of Double Quation is not found:2"));
                }
            }

            //連続したスペース・タブはそのまま
            if (ls[0] <= ' ')
            {
                for (var i = 0; i < ls.Length; i++)
                {
                    if (ls[i] == '\x0a')
                    {
                        if (i > 0)
                        {
                            wdlen = i;
                            return(any_return(v, YDEF.SP, null, " "));
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (ls[i] > ' ')
                    {
                        wdlen = i;
                        return(any_return(v, YDEF.SP, null, " "));
                    }
                }
                if (wdlen == 0)
                {
                    wdlen = 1;
                }
                return(any_return(v, YDEF.EOL));
            }

            //数字
            if (IsNumberElement(ls[0], true))
            {
                wdlen = 0;
                string s = "" + ls[0];
                for (int i = 1; i < ls.Length; i++)
                {
                    if (IsNumberElement(ls[i]))
                    {
                        s += ls[i];
                    }
                    else
                    {
                        wdlen = i;
                        break;
                    }
                }
                if (wdlen == 0)
                {
                    wdlen = ls.Length;
                }
                double d;
                if (double.TryParse(s, out d))
                {
                    return(any_return(v, YDEF.NUM, d, s));
                }
                else
                {
                    if (s == ".")
                    {
                        return(any_return(v, YDEF.SYM, null, s));
                    }
                    return(err_return(v, s));
                }
            }

            //名前
            if (IsNameElement(ls[0]))
            {
                wdlen = 0;
                string s = "" + ls[0];
                for (int i = 1; i < ls.Length; i++)
                {
                    if (IsNameElement(ls[i], true))
                    {
                        s += ls[i];
                    }
                    else
                    {
                        wdlen = i;
                        break;
                    }
                }
                if (wdlen == 0)
                {
                    wdlen = ls.Length;
                }
                return(any_return(v, YDEF.STR, null, s));
            }
            if (ls[0] == '@' || ls[0] == '#')
            {
                if (ls.Length == 1 || !IsNameElement(ls[1]))
                {
                    return(err_return(v, "variable or predefine name error"));
                }
                wdlen = 0;
                string s = "" + ls[0] + ls[1];
                for (int i = 2; i < ls.Length; i++)
                {
                    if (IsNameElement(ls[i], true))
                    {
                        s += ls[i];
                    }
                    else
                    {
                        wdlen = i;
                        break;
                    }
                }
                if (wdlen == 0)
                {
                    wdlen = ls.Length;
                }
                return(any_return(v, (ls[0] == '@') ? YDEF.VAR : YDEF.PRE, null, s));
            }

            //その他 記号とみなす
            wdlen = 1;

            return(any_return(v, YDEF.SYM, null, "" + ls[0]));
        }
示例#15
0
        private static bool _isMatchAndMake(List <VALUE> list, int index, YDEF.TreeSet ts)
        {
            Func <int, VALUE> get = (n) => {
                if (n >= list.Count)
                {
                    return(null);
                }
                return(list[n]);
            };
            List <VALUE> args         = new List <VALUE>();
            int          removelength = ts.list.Count;

            for (int i = 0; i < ts.list.Count; i++)
            {
                var v = get(index + i);
                if (v == null)
                {
                    return(false);
                }

                if (i == 0 && ts.list.Count == 1 && v.IsType(ts.type))
                {
                    return(false);                                               //既に変換済み
                }
                var o = ts.list[i];
                if (o.GetType() == typeof(string))
                {
                    if (v.GetString() != (string)o)
                    {
                        return(false);
                    }
                }
                else
                {
                    var tstype = (int)o;
                    if (tstype == YDEF.REST) // ※RESTは特殊処理。EOLまでのすべて(除EOL)が入る
                    {
                        removelength--;      //本VALUE分を事前に引く

                        var restv = new VALUE();
                        restv.type = YDEF.REST;
                        restv.list = new List <VALUE>();

                        for (int j = index + i; j < list.Count; j++)
                        {
                            var v2 = get(j);
                            if (v2 != null && !v2.IsType(YDEF.EOL))
                            {
                                restv.list.Add(v2);
                                removelength++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        args.Add(restv);
                        break;
                    }
                    else
                    {
                        if (!v.IsType(tstype))
                        {
                            return(false);
                        }
                    }
                }
                args.Add(v);
            }

            //Yes, they match! then Make it.

            var makefunc = (Func <int, VALUE[], int[], VALUE>)ts.make_func;

            var newv = ts.make_func(ts.type, args.ToArray(), ts.make_index.ToArray());

            list.RemoveRange(index, removelength);
            list.Insert(index, newv);

            return(true);
        }