예제 #1
0
파일: Dfa.cs 프로젝트: m33p/radegast
 private void MakeLastAction(int act)
 {
     while (this.m_actions != null && this.m_actions.a_act >= act)
     {
         this.m_actions = this.m_actions.a_next;
     }
     this.AddAction(act);
 }
예제 #2
0
파일: Dfa.cs 프로젝트: m33p/radegast
 public static object Serialise(object o, Serialiser s)
 {
     if (s == null)
     {
         return((object)new Dfa.Action());
     }
     Dfa.Action action = (Dfa.Action)o;
     if (s.Encode)
     {
         s.Serialise((object)action.a_act);
         s.Serialise((object)action.a_next);
         return((object)null);
     }
     action.a_act  = (int)s.Deserialise();
     action.a_next = (Dfa.Action)s.Deserialise();
     return((object)action);
 }
예제 #3
0
        bool TryActions(Dfa dfa, ref TOKEN tok)
        {
            int len = m_pch - m_startMatch;

            if (len == 0)
            {
                return(false);
            }
            if (m_startMatch + len <= m_buf.Length)
            {
                yytext = m_buf.Substring(m_startMatch, len);
            }
            else // can happen with {EOF} rules
            {
                yytext = m_buf.Substring(m_startMatch);
            }
            // actions is a list of old-style actions for this DFA in order of priority
            // there is a list because of the chance that any of them may REJECT
            Dfa.Action a      = dfa.m_actions;
            bool       reject = true;

            while (reject && a != null)
            {
                int action = a.a_act;
                reject = false;
                a      = a.a_next;
                if (a == null && dfa.m_tokClass != "")
                { // last one might not be an old-style action
                    if (m_debug)
                    {
                        Console.WriteLine("creating a " + dfa.m_tokClass);
                    }
                    tok = (TOKEN)Tfactory.create(dfa.m_tokClass, this);
                }
                else
                {
                    tok = m_tokens.OldAction(this, ref yytext, action, ref reject);
                    if (m_debug && !reject)
                    {
                        Console.WriteLine("Old action " + action);
                    }
                }
            }
            return(!reject);
        }
예제 #4
0
파일: Lexer.cs 프로젝트: m33p/radegast
        private bool TryActions(Dfa dfa, ref TOKEN tok)
        {
            int length = this.m_pch - this.m_startMatch;

            if (length == 0)
            {
                return(false);
            }
            this.yytext = this.m_startMatch + length > this.m_buf.Length ? this.m_buf.Substring(this.m_startMatch) : this.m_buf.Substring(this.m_startMatch, length);
            Dfa.Action action = dfa.m_actions;
            bool       reject = true;

            while (reject && action != null)
            {
                int aAct = action.a_act;
                reject = false;
                action = action.a_next;
                if (action == null && dfa.m_tokClass != "")
                {
                    if (this.m_debug)
                    {
                        Console.WriteLine("creating a " + dfa.m_tokClass);
                    }
                    tok = (TOKEN)Tfactory.create(dfa.m_tokClass, this);
                }
                else
                {
                    tok = this.m_tokens.OldAction(this, ref this.yytext, aAct, ref reject);
                    if (this.m_debug && !reject)
                    {
                        Console.WriteLine("Old action " + (object)aAct);
                    }
                }
            }
            return(!reject);
        }
예제 #5
0
파일: Dfa.cs 프로젝트: m33p/radegast
 private void AddAction(int act)
 {
     this.m_actions = new Dfa.Action(act, this.m_actions);
 }
예제 #6
0
파일: Dfa.cs 프로젝트: m33p/radegast
 public Action(int act, Dfa.Action next)
 {
     this.a_act  = act;
     this.a_next = next;
 }
예제 #7
0
파일: Dfa.cs 프로젝트: m33p/radegast
        public void Print()
        {
            Console.Write("{0}:", (object)this.m_state);
            if (this.m_actions != null)
            {
                Console.Write(" (");
                for (Dfa.Action action = this.m_actions; action != null; action = action.a_next)
                {
                    Console.Write("{0} <", (object)action.a_act);
                }
                if (this.m_tokClass != "")
                {
                    Console.Write(this.m_tokClass);
                }
                Console.Write(">)");
            }
            Console.WriteLine();
            Hashtable             hashtable   = new Hashtable();
            IDictionaryEnumerator enumerator1 = this.m_map.GetEnumerator();
            int count = this.m_map.Count;

            while (count-- > 0)
            {
                enumerator1.MoveNext();
                char key1 = (char)enumerator1.Key;
                Dfa  dfa1 = (Dfa)enumerator1.Value;
                if (!hashtable.Contains((object)key1))
                {
                    hashtable[(object)key1] = (object)true;
                    Console.Write("  {0}  ", (object)dfa1.m_state);
                    int num1 = (int)key1;
                    if (num1 >= 32 && num1 < 128)
                    {
                        Console.Write(key1);
                    }
                    else
                    {
                        Console.Write(" #{0} ", (object)num1);
                    }
                    IDictionaryEnumerator enumerator2 = this.m_map.GetEnumerator();
                    do
                    {
                        enumerator2.MoveNext();
                    }while ((Dfa)enumerator2.Value != dfa1);
                    for (int index = count; index > 0; --index)
                    {
                        enumerator2.MoveNext();
                        char key2 = (char)enumerator2.Key;
                        Dfa  dfa2 = (Dfa)enumerator2.Value;
                        if (dfa1 == dfa2)
                        {
                            hashtable[(object)key2] = (object)true;
                            int num2 = (int)key2;
                            if (num2 >= 32 && num2 < 128)
                            {
                                Console.Write(key2);
                            }
                            else
                            {
                                Console.Write(" #{0} ", (object)num2);
                            }
                        }
                    }
                    Console.WriteLine();
                }
            }
        }