Ejemplo n.º 1
0
        public string get_ascent_types() //タイプを遡って纏めて文字列化。listの先頭のみが対象
        {
            string          s         = null;
            Action <YVALUE> printtype = null;

            printtype = (v) =>
            {
                if (v == null)
                {
                    return;
                }
                if (s != null)
                {
                    s += "-";
                }
                s += YDEF.get_name(v.type);
                if (v.list != null && v.list.Count > 0)
                {
                    printtype(v.list[0]);
                }
            };

            printtype(this);

            return(s);
        }
Ejemplo n.º 2
0
        private int _countParamsInBracket(YVALUE v)
        {
            if (v == null || v.list == null || v.list.Count < 2 || v.type != YDEF.get_type(YDEF.sx_expr_bracket))
            {
                return(0);
            }
            //            c  n
            // "()"     : 2->0         n = ((c-2)+1) / 2       c=2 n=0.5...=0
            // "(x)"    : 3->1
            // "(x,y)"  : 5->2
            // "(x,y,z)": 7->3

            int num = ((v.list.Count - 2) + 1) / 2;

            return(num);
        }
Ejemplo n.º 3
0
            public override string ToString()
            {
                string s = null;

                list.ForEach(i => {
                    if (s != null)
                    {
                        s += ",";
                    }
                    if (i.GetType() == typeof(int))
                    {
                        s += YDEF.get_name((int)i);
                    }
                    else
                    {
                        s += i.ToString();
                    }
                });
                return(name + ":" + s);
            }
Ejemplo n.º 4
0
        public bool IsExecuable(List <List <YVALUE> > list, out int errorline)
        {
            errorline = -1;
            var roottype = YDEF.get_syntax_root();

            foreach (var l in list)
            {
                if (l.Count > 0)
                {
                    var typ = l[0].type;
                    if (typ == roottype)
                    {
                        continue;                  //最終形態でOK
                    }
                    errorline = l[0].get_dbg_line();
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        public static bool IsExecutable(List <YVALUE> list, out List <int> errorline)
        {
            errorline = null;
            if (list.Count == 1 && list[0].IsType(YDEF.get_type(YDEF.sx_main_block)))
            {
                return(true);
            }

            List <int> errlist = new List <int>();

            for (var i = save_startIndex; i < save_endindex; i++)
            {
                var v = list[i];
                if (v.type == YDEF.BOF || v.type == YDEF.EOF)
                {
                    continue;
                }
                if (v.type < (int)TOKEN.MAX)
                {
                    var el = v.get_dbg_line();
                    errlist.Add(el);
                    continue;
                }
                if (
                    v.IsType(YDEF.sx_sentence_block) || v.IsType(YDEF.sx_sentence_list) || v.IsType(YDEF.sx_sentence)
                    )
                {
                    continue;
                }
                else
                {
                    var el = v.get_dbg_line();
                    errlist.Add(el);
                    continue;
                }
            }

            errorline = errlist.Distinct().ToList();

            return(errlist.Count == 0);
        }
Ejemplo n.º 6
0
        public override string ToString()
        {
            string s = null;

            s += type.ToString() + ":" + YDEF.get_name(type);
            s += ":" + (o != null ? o.ToString() : "null") + ">";

            string q = null;

            if (list != null && list.Count > 0)
            {
                foreach (var i in list)
                {
                    if (!string.IsNullOrEmpty(i.s))
                    {
                        if (q != null)
                        {
                            q += ",";
                        }
                        q += i.s;
                    }
                    else if (i.o != null)
                    {
                        if (q != null)
                        {
                            q += ",";
                        }
                        q += o.GetType();
                    }
                }
            }

            if (q != null)
            {
                s += q;
            }

            return(s);
        }
Ejemplo n.º 7
0
        public bool IsType(object[] o)
        {
            int tp = YDEF.get_type(o);

            return(IsType(tp));
        }
Ejemplo n.º 8
0
        public YVALUE FindValueByTravarse(object[] o) //指定タイプをトラバースして検索 (listを辿りながら)
        {
            var type = YDEF.get_type(o);

            return(FindValueByTravarse(type));
        }
Ejemplo n.º 9
0
        public bool IsType(string s)
        {
            int tp = YDEF.get_type(s);

            return(IsType(tp));
        }
Ejemplo n.º 10
0
 public string get_type_name()
 {
     return(YDEF.get_name(type));
 }
Ejemplo n.º 11
0
 private static int getyp(object[] o)
 {
     return(YDEF.get_type(o));
 }
Ejemplo n.º 12
0
 // -- util --
 private static string gn(object[] o)
 {
     return(YDEF.get_name(o));
 }
Ejemplo n.º 13
0
        //public class TokenProvider
        //{
        //    List<string> m_separators;
        //    List<YVALUE> m_target;
        //    List<YVALUE> m_subtarget;
        //    int          m_index;
        //    int?         m_sample_start;
        //    int?         m_sample_end;

        //    public void Init(List<YVALUE> l, int ob, int cb)
        //    {
        //        m_separators = new List<string>(lexPrimitive.operators_all);
        //        m_separators.Add("NEW");
        //        m_separators.Add(";");
        //        m_target = extruct_list(l,ob,cb);
        //        m_index = 0;
        //    }

        //    public bool Update() // return true if done
        //    {
        //        /*
        //           アップデート毎に1つ要素を指定して解析へ
        //           m_index       : 1回のアップデートで1つ進行
        //           m_subtarget   : 解析対象=m_targetの要素のm_sample_start番目からm_sample_end番目まで
        //        */
        //        m_subtarget = null;
        //        m_sample_start=null;
        //        m_sample_end  =null;

        //        int cnt = 0;
        //        for(int i = 0; i<m_target.Count; i++)
        //        {
        //            var v = m_target[i];
        //            var bSep = m_separators.Contains(v.s);
        //            if (cnt == m_index)
        //            {
        //                if (m_subtarget==null) m_subtarget = new List<YVALUE>();
        //                if (!bSep)
        //                {
        //                    m_subtarget.Add(v);
        //                    if (m_sample_start==null) m_sample_start = i;
        //                    m_sample_end = i;
        //                }
        //            }
        //            if (bSep) cnt++;
        //        }

        //        m_index++;

        //        if (m_subtarget!=null)
        //        {
        //            if (m_subtarget.Count>0)
        //            {
        //                _analyze(ref m_subtarget);
        //                replace_list(ref m_target,(int)m_sample_start,(int)m_sample_end, m_subtarget);
        //            }
        //            return false; //continue;
        //        }
        //        else
        //        {
        //            return true; // done
        //        }
        //    }

        //    public List<YVALUE> GetResult()
        //    {
        //        return m_target;
        //    }
        //}

        //public class TokenProvider_prefix //前置演算子
        //{
        //    List<string> m_operators;
        //    List<string> m_operators_prefix;
        //    List<YVALUE> m_target;
        //    List<YVALUE> m_subtarget;
        //    int          m_index;
        //    int?         m_sample_start;
        //    int?         m_sample_end;

        //    public void Init(List<YVALUE> l, int ob, int cb)
        //    {
        //        m_operators = new List<string>(lexPrimitive.operators_binary);
        //        m_operators.AddRange(lexPrimitive.operators_ternay);

        //        m_operators_prefix = new List<string>(lexPrimitive.operators_prefix);

        //        m_target = extruct_list(l,ob,cb);
        //        m_index = 0;
        //    }

        //    public bool Update() // return true if done
        //    {
        //        m_subtarget = null;
        //        m_sample_start=null;
        //        m_sample_end  =null;

        //        for(int i = m_index; i<m_target.Count; i++)
        //        {
        //            var v = m_target[i];
        //            var bPreOp = m_operators_prefix.Contains(v.s); //前置演算子?
        //            if (bPreOp)
        //            {
        //                if (i==0) //先頭でかつexprが後続
        //                {
        //                    if (isExpr(i+1))
        //                    {
        //                        m_sample_start= i;
        //                        m_sample_end  = i+1;
        //                    }
        //                    else
        //                    {
        //                        throw new SystemException("This operator follows something.");
        //                    }
        //                }
        //                else //直前が他のオペレータでかつexprが後続
        //                {
        //                    if (isOtherOp(i-1))
        //                    {
        //                        if (isExpr(i+1))
        //                        {
        //                            m_sample_start = i;
        //                            m_sample_end   = i+1;
        //                        }
        //                        else
        //                        {
        //                            throw new SystemException("This operator follows something.");
        //                        }
        //                    }
        //                }
        //            }

        //            m_index++;

        //            if (m_sample_start!=null)
        //            {
        //                m_subtarget = new List<YVALUE>();
        //                for(int j = (int)m_sample_start; j<= (int)m_sample_end; j++) m_subtarget.Add(m_target[j]);
        //                _analyze(ref m_subtarget);
        //                replace_list(ref m_target,(int)m_sample_start,(int)m_sample_end, m_subtarget);
        //                return false;
        //            }

        //        }
        //        return true;
        //    }

        //    public List<YVALUE> GetResult()
        //    {
        //        return m_target;
        //    }
        //    // --
        //    private bool isExpr(int i)
        //    {
        //        if (i<0 || i>=m_target.Count) return false;
        //        return m_target[i].IsType(YDEF.sx_expr);
        //    }
        //    private bool isOtherOp(int i)
        //    {
        //        if (i<0 || i>=m_target.Count) return false;
        //        return m_operators.Contains(m_target[i].s);
        //    }
        //}

        //public class TokenProvider_postfix //後置演算子
        //{
        //    List<string> m_operators;
        //    List<string> m_operators_postfix;
        //    List<YVALUE> m_target;
        //    List<YVALUE> m_subtarget;
        //    int          m_index;
        //    int?         m_sample_start;
        //    int?         m_sample_end;

        //    public void Init(List<YVALUE> l, int ob, int cb)
        //    {
        //        m_operators = new List<string>(lexPrimitive.operators_binary);
        //        m_operators.AddRange(lexPrimitive.operators_ternay);

        //        m_operators_postfix = new List<string>(lexPrimitive.operators_postfix);

        //        m_target = extruct_list(l,ob,cb);
        //        m_index = 0;
        //    }

        //    public bool Update() // return true if done
        //    {
        //        m_subtarget = null;
        //        m_sample_start=null;
        //        m_sample_end  =null;

        //        for(int i = m_index; i<m_target.Count; i++)
        //        {
        //            var v = m_target[i];
        //            var bPreOp = m_operators_postfix.Contains(v.s); //後置演算子?
        //            if (bPreOp)
        //            {
        //                if (isExpr(i-1))
        //                {
        //                    m_sample_start = i-1;
        //                    m_sample_end   = i;
        //                }
        //                else
        //                {
        //                    throw new SystemException("This operator follows something.");
        //                }
        //            }

        //            if (m_sample_start!=null)
        //            {
        //                m_subtarget = new List<YVALUE>();
        //                for(int j = (int)m_sample_start; j<= (int)m_sample_end; j++) m_subtarget.Add(m_target[j]);
        //                _analyze(ref m_subtarget);
        //                replace_list(ref m_target,(int)m_sample_start,(int)m_sample_end, m_subtarget);
        //                return false;
        //            }

        //            m_index++;
        //        }
        //        return true;
        //    }

        //    public List<YVALUE> GetResult()
        //    {
        //        return m_target;
        //    }
        //    // --
        //    private bool isExpr(int i)
        //    {
        //        if (i<0 || i>=m_target.Count) return false;
        //        return m_target[i].IsType(YDEF.sx_expr);
        //    }
        //    private bool isOtherOp(int i)
        //    {
        //        if (i<0 || i>=m_target.Count) return false;
        //        return m_operators.Contains(m_target[i].s);
        //    }
        //}
        #endregion 優先要素抽出

        #region  解析
        private static bool _analyze(ref List <YVALUE> dst)
        {
            m_latest_analyze_target = dst;
            if (slagtool.sys.DEBUGLEVEL >= 2)
            {
                sys.logline("==================");
                sys.logline("= Analyze target =");
                YDEF_DEBUG.PrintLineAndCol(dst); sys.logline();
                YDEF_DEBUG.PrintListValue(dst);
                sys.logline("==================");
            }
            var syntax_order = YDEF.get_syntax_order();

            bool bNeedLoop = false;

            for (var loop = 0; loop <= LOOPMAX; loop++)
            {
                if (loop == LOOPMAX)
                {
                    sys.error("Analyze LoopMax:2");
                }

                bNeedLoop = false;
                for (int i = 0; i < syntax_order.Count; i++)
                {
                    var syntax = syntax_order[i];
                    var tslist = YDEF.get_syntax_set(syntax);

                    if (slagtool.sys.DEBUGLEVEL == 3)
                    {
                        sys.logline(syntax[0].ToString());
                    }

                    foreach (var ts in tslist)
                    {
                        if (_check_syntax(dst, ts))
                        {
                            m_match_count++;

                            bNeedLoop = true;
                            break;
                        }
                    }
                    if (bNeedLoop)
                    {
                        break;            //最初から
                    }
                }

                if (bNeedLoop)
                {
                    continue;
                }
                else
                {
                    if (slagtool.sys.DEBUGLEVEL >= 2)
                    {
                        YDEF_DEBUG.DumpLine_detail(dst, true);
                    }
                    return(true);
                }
            }
            return(false);
        }