Beispiel #1
0
        __minor(instance continuous)
        {
            instance Gen::Stack <BacktrackRange> capt_ch = new Gen::Stack <BacktrackRange>();

            while (capt_ch.Count != this.max)
            {
                capt_ch.Push(new BacktrackRange(s));
                if (!node.Read(s))
                {
                    capt_ch.Pop().Restore(s);
                    break;
                }
            }

            while (capt_ch.Count >= this.min)
            {
                s.Success = true;
                return(null);

                if (capt_ch.Count == 0)
                {
                    break;
                }
                capt_ch.Pop().Restore(s);
            }

            s.Success = false;
            break return(null);
        }
Beispiel #2
0
            public Evaluator(Status s, INode node)
            {
                this.node     = node;
                this.s        = s;
                this.st_indef = new Gen::Stack <StatusInfo>();

                this.index0 = this.s.Index;
            }
Beispiel #3
0
        public ITester Read_Nondeterm(Status s)
        {
            switch (continuous_state)
            {
            default: throw new System.Exception("この関数の実行は終了しています。");

            case 0: break;

            case 1: goto R3;

            case 2: goto R4;
            }
#pragma warning disable 164
            capt_ch = new Gen::Stack <BacktrackRange>();
            L12 : if (!(capt_ch.Count != this.max))
            {
                goto L13;
            }
            s.Success = true;
            capt_ch.Push(new BacktrackRange(s));
            continuous_state = 1; return(node.GetTester());

            R3 :;

            if (!(!s.Success))
            {
                goto L16;
            }
            capt_ch.Pop().Restore(s);
            goto L13;
            L16 :;
            goto L12;
            L13 :;

            L14 : if (!(capt_ch.Count >= this.min))
            {
                goto L15;
            }
            s.Success        = true;
            continuous_state = 2; return(null);

            R4 :;

            if (capt_ch.Count == 0)
            {
                goto L15;
            }
            capt_ch.Pop().Restore(s);
            goto L14;
            L15 :;

            s.Success        = false;
            continuous_state = -1; return(null);

#pragma warning restore 164
        }
Beispiel #4
0
        /// <summary>
        /// 指定した Status を使用して matching を実行します。
        /// </summary>
        /// <param name="s">読み取りに使用する Status を指定します。
        /// ITester-Stack が空である事を想定しています。
        /// 中に何かある場合にはそれを別の所に待避して、new Stack を設定しておいて下さい。
        /// </param>
        /// <param name="node">要求するパターンを表現する構成体を指定します。</param>
        /// <returns>マッチングに成功した場合に true を返します。
        /// それ以外の場合に false を返します。</returns>
        internal bool match(Status s, INode node)
        {
            Gen::Stack <StatusInfo> st_indef = new Gen::Stack <StatusInfo>();

            s.Push(node.GetTester());
            while (true)
            {
                ITester test = s.Tester.Read(s);

                if (!s.Success)
                {
                    // a. Node 失敗
                    //-------------------
                    // 全体 失敗
                    if (s.IsRoot)
                    {
                        // * INDEFINICITY *
                        if (st_indef.Count == 0)
                        {
                            return(false);
                        }
                        st_indef.Pop().Restore(s);
                    }
                    else
                    {
                        s.Pop();
                    }
                }
                else if (test != null)
                {
                    // b. 入れ子 Node
                    //-------------------
                    s.Push(test);
                }
                else
                {
                    // c. 成功 (Node 終了)
                    //-------------------
                    // 全体 成功
                    if (s.IsRoot)
                    {
                        return(true);
                    }

                    if (s.Tester.Indefinite)
                    {
                        // * INDEFINICITY *
                        st_indef.Push(new StatusInfo(s));
                    }

                    s.Pop();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// スタックの各要素を変換した新しいスタックを作成します。
        /// </summary>
        /// <typeparam name="T">変換前の要素の型を指定します。</typeparam>
        /// <typeparam name="U">変換後の要素の型を指定します。</typeparam>
        /// <param name="stack">変換前の要素を格納したスタックを指定します。</param>
        /// <param name="converter">要素の変換に使用するデリゲートを指定します。</param>
        /// <returns>要素を変換して出来たスタックを返します。</returns>
        public static Gen::Stack <U> ConvertAll <T, U>(this Gen::Stack <T> stack, Converter <T, U> converter)
        {
            T[] values = stack.ToArray();

            Gen::Stack <U> ret = new Gen::Stack <U>(values.Length);

            for (int i = values.Length - 1; i >= 0; i--)
            {
                ret.Push(converter(values[i]));
            }
            return(ret);
        }
Beispiel #6
0
        /// <summary>
        /// 同じ内容を持つスタックのインスタンスを作成します。
        /// </summary>
        /// <typeparam name="T">スタックの要素の型を指定します。</typeparam>
        /// <param name="stack">コピー元のスタックを指定します。</param>
        /// <returns>指定したスタックと同じ内容を持つ、新しいスタックを返します。</returns>
        public static Gen::Stack <T> Clone <T>(this Gen::Stack <T> stack)
        {
            T[] values = stack.ToArray();

            Gen::Stack <T> ret = new Gen::Stack <T>(values.Length);

            for (int i = values.Length - 1; i >= 0; i--)
            {
                ret.Push(values[i]);
            }
            return(ret);
        }
Beispiel #7
0
 private static void PrintStack(Gen::Stack <int> st)
 {
     System.Console.Write("content of st: ");
     int[] starr = st.ToArray();
     for (int i = starr.Length - 1; i >= 0; i--)
     {
         int val = starr[i];
         System.Console.Write("{0}, ", val);
     }
     //foreach(int val in st)System.Console.Write("{0}, ",val);
     System.Console.WriteLine("(top);");
     System.Console.WriteLine("count of st: {0}", st.Count);
 }
Beispiel #8
0
        public ITester Read_Determ(Status s)
        {
            switch (continuous_state)
            {
            default: throw new System.Exception("この関数の実行は終了しています。");

            case 0: break;

            case 1: goto R5;
            }
#pragma warning disable 164
            capt_ch = new Gen::Stack <BacktrackRange>();
            L17 : if (!(capt_ch.Count != this.max))
            {
                goto L18;
            }
            capt_ch.Push(new BacktrackRange(s));
            if (!(!node.Read(s)))
            {
                goto L21;
            }
            capt_ch.Pop().Restore(s);
            goto L18;
            L21 :;
            goto L17;
            L18 :;

            L19 : if (!(capt_ch.Count >= this.min))
            {
                goto L20;
            }
            s.Success        = true;
            continuous_state = 1; return(null);

            R5 :;

            if (capt_ch.Count == 0)
            {
                goto L20;
            }
            capt_ch.Pop().Restore(s);
            goto L19;
            L20 :;

            s.Success        = false;
            continuous_state = -1; return(null);

#pragma warning restore 164
        }
Beispiel #9
0
        public override bool Test(HTMLElement elem, System.Collections.Generic.Stack <string> stack)
        {
            if (this.selector == null)
            {
                return(true);
            }
            Gen::Stack <string> s = selector.GetFirstStack(elem);

            if (s == null)
            {
                return(false);
            }
            foreach (string x in s)
            {
                stack.Push(x);
            }
            return(true);
        }
Beispiel #10
0
            /// <summary>
            /// 指定した Status の情報を記録します。
            /// </summary>
            /// <param name="s">状態を記録したい Status を指定します。</param>
            public StatusInfo(Status s)
            {
                this.capt_count = s.Captures.Count;
                this.index      = s.Target.Index;

                // スタックのコピー : Generics.Stack には Clone がない...
                this.st = new Gen::Stack <ITester>(s.st.Count);
                ITester[] testers = s.st.ToArray();
                if (testers.Length == 0)
                {
                    return;
                }
                for (int i = testers.Length - 1; i > 0; i--)
                {
                    this.st.Push(testers[i].Clone());
                }
                this.st.Push(testers[0]);                 //← 最後の要素に関しては Clone は必要ない
            }
Beispiel #11
0
        //----------------------------------------------------------------------
        //	解析
        //----------------------------------------------------------------------
        public Tree.IExpression Parse(Context startContext, Gen::IEnumerable <Word> input)
        {
            this.stk_parse = new Stack();
            this.stk_ctx   = new Gen::Stack <Context>();
            this.PushContext(startContext);
            foreach (Word w in input)
            {
                switch (w.type)
                {
                case WordType.Operator:
                    if (TrySuffixOperator(w))
                    {
                        break;
                    }
                    if (TryPrefixOperator(w))
                    {
                        break;
                    }
                    break;

                case WordType.Identifier:
                    this.stk_parse.Push(
                        new ExpressionElement(new Tree.IdExpression(w.word))
                        );
                    break;

                case WordType.Literal:
                    this.stk_parse.Push(
                        new ExpressionElement(new Tree.LiteralExpression(w.word))
                        );
                    break;
                }
            }

            if (!this.stk_parse.IsTopExpression)
            {
                throw new System.Exception("ParseError");
            }

            return(this.stk_parse.PopOperand(0).Expression);
        }
Beispiel #12
0
        public System.Collections.IEnumerable Enumerate(HTMLElement parent, Gen::Stack <string> stack)
        {
            System.Collections.IEnumerable @enum = this.getBaseEnum(parent);
            if (@enum == null)
            {
                yield break;
            }
            int  i;
            bool first = this.relation == '+' || this.relation == '-';
            int  stcC  = stack.Count;

            foreach (HTMLElement elem in @enum)
            {
                for (i = 0; i < this.len; i++)
                {
                    if (!this.testers[i].Test(elem, stack))
                    {
                        break;
                    }
                }
                if (i == this.len)
                {
                    yield return(elem);

                    while (stack.Count > stcC)
                    {
                        stack.Pop();
                    }
                    if (first)
                    {
                        break;
                    }
                }
            }
            // 元の状態に戻してから終わる (MoveNext = false)
            while (stack.Count > stcC)
            {
                stack.Pop();
            }
        }
Beispiel #13
0
 /// <summary>
 /// 値読込命令を含む際に値をスタックに返す形式の判断メソッドです。
 /// 通常ではこのメソッドは Test(HTMLElement) をそのまま呼び出すだけです。
 /// </summary>
 /// <param name="elem">適合するかどうかを確かめる要素を指定します。</param>
 /// <param name="stack">値を返す先のスタックを指定します。</param>
 /// <returns>適合した場合に true を返します。</returns>
 public virtual bool Test(HTMLElement elem, Gen::Stack <string> stack)
 {
     return(Test(elem));
 }
Beispiel #14
0
 /// <summary>
 /// Status のスタックを一時的に退避します。
 /// </summary>
 /// <param name="s">読み取りに使用している Status を指定します。</param>
 public StatusStackRefuge(Status s)
 {
     this.s     = s;
     this.stack = s.st;
     s.st       = new Gen::Stack <ITester>();
 }