示例#1
0
        internal static List <YVALUE> Compile(List <string> multiple_srces)
        {
            var engine = new yengine();

            // 終末記号に分類
            var lex_output = new List <List <YVALUE> >();

            for (int i = 0; i < multiple_srces.Count; i++)
            {
                lex_output.AddRange(engine.Lex(multiple_srces[i], i));
            }

            //スペース・コメント削除。"文字列"以外大文字化。
            engine.Normalize(ref lex_output);
            sys.logline("\n*lex_output done");

            YDEF_DEBUG.DumpList(lex_output, true);

            //改行を無くしBOFとEOFを追加
            var one_line = engine.Del_LF_And_Add_BOF_EOF(lex_output);

            //実行用リスト作成(解析)
            var analyzed = engine.Interpret(one_line);
            var executable_value_list = analyzed[0];


            //ダンプ
            sys.logline("\n[executable_value_list] done\n");

            YDEF_DEBUG.PrintListValue(executable_value_list);

            sys.logline("\n");

            //リストの整合性テスト
            List <int> errorline;

            if (YDEF_DEBUG.IsExecutable(executable_value_list, out errorline))
            {
                sys.logline("スクリプト実行準備完了");
            }
            else
            {
                string s = null;
                errorline.ForEach(i =>
                {
                    if (s != null)
                    {
                        s += ",";
                    }
                    s += (i + 1);
                });
                sys.error("スクリプト実行不可、次を確認:" + s);
            }

            //最適化
            executable_value_list = preruntime.process.Convert(executable_value_list);

            return(executable_value_list);
        }
示例#2
0
        public void filesAdd(string filename)
        {
            var i = new Item();

            i.filename = filename;
            i.hash     = YDEF_DEBUG.GetFilenameHash(filename);
            files.Add(i);
        }
示例#3
0
 internal static void log_stopinfo()
 {
     logline(YDEF_DEBUG.RuntimeErrorInfo(), true);
 }
示例#4
0
 private static bool _check_syntax(List <YVALUE> list, YDEF.TreeSet ts)
 {
     for (var i = 0; i < list.Count; i++) // 走査
     {
         if (_isMatchAndMake(list, i, ts))
         {
             if (slagtool.sys.DEBUGLEVEL == 1)
             {
                 //sys.logline("match ..." + ": list[" + i + "] " + ts.ToString());
             }
             else
             {
                 sys.logline("\n match ..." + ": list[" + i + "] " + ts.ToString() + ">\n" + YDEF_DEBUG.PrintValue(list[i]));
             }
             return(true);
         }
     }
     return(false);
 }
示例#5
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);
        }
示例#6
0
        public static bool Analyze(List <YVALUE> src, out List <YVALUE> dst)
        {
            int stopmatch_count     = 0;
            int max_stopmatch_count = 0; //計測用

            m_match_count = 0;
            dst           = new List <YVALUE>(src);

            var vp = new ValProvider();

            vp.Init(dst);

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

                var save_match_count = m_match_count;

                vp.Update();

                if (vp.IsDone())
                {
                    dst = vp.GetResult();
                    break;
                }

                if (save_match_count == m_match_count)
                {
                    if (stopmatch_count == MATCHLIMIT - 1)
                    {
                        sys.logline("it will be reached to the limit of match "); //for debug
                        util.SetDebugLevel(2);
                    }

                    if (stopmatch_count++ > MATCHLIMIT)
                    {
                        if (m_latest_analyze_target != null)
                        {
                            sys.logline("========================", true);
                            sys.logline("=  最終分析ターゲット  =", true);
                            YDEF_DEBUG.PrintLineAndCol(m_latest_analyze_target, true); sys.logline(null, true);
                            YDEF_DEBUG.PrintListValue(m_latest_analyze_target, true);
                            sys.logline("========================", true);
                            sys.error("YANALYZER_ERROR:以下を確認せよ:\n" + YDEF_DEBUG.GetStringListValue(m_latest_analyze_target) + "\n--" + YDEF_DEBUG.ErrorHint(m_latest_analyze_target) + "\n--");
                        }
                        sys.error("YANALYZER_ERRORR:不明エラー");
                    }

                    max_stopmatch_count = Math.Max(stopmatch_count, max_stopmatch_count); //計測
                }
                else
                {
                    stopmatch_count = 0;
                }
            }
            vp = null;

            //sys.logline("整合カウンタ(max_stopmatch_count)がMAXに達した。カウンタを増やせ。現在値:" + max_stopmatch_count);

            return(true);
        }