Ejemplo n.º 1
0
 internal bool AddNfaNode(NfaNode nfa)
 {
     if (!m_nfa.Add(nfa))
     {
         return(false);
     }
     if (nfa.m_sTerminal != "")
     {
         int    qi, n = 0;
         string tokClass = "";
         string p        = nfa.m_sTerminal;
         if (p[0] == '%')
         {                                                 // check for %Tokname special action
             for (n = 0, qi = 1; qi < p.Length; qi++, n++) // extract the class name
             {
                 if (p[qi] == ' ' || p[qi] == '\t' || p[qi] == '\n' || p[qi] == '{' || p[qi] == ':')
                 {
                     break;
                 }
             }
             tokClass = nfa.m_sTerminal.Substring(1, n);
         }
         // check for ResWds machinery // 4.7
         if (n > 0 && n + 1 < p.Length)
         {
             string st = nfa.m_sTerminal.Substring(n + 1).Trim();
             if (st.Length > 0)
             {
                 if (st.StartsWith("%except"))
                 {
                     m_reswds = nfa.m_state;
                     m_tks.m_tokens.reswds[nfa.m_state] = ResWds.New(m_tks, st.Substring(7));
                 }
             }
         }
         // special action is always last in the list
         if (tokClass == "")
         {                                        //nfa has an old action
             if (m_tokClass == ""                 // if both are old-style
                 ||                               // or we have a special action that is later
                 (m_actions.a_act) > nfa.m_state) // m_actions has at least one entry
             {
                 AddAction(nfa.m_state);
             }
             // else we have a higher-precedence special action so we do nothing
         }
         else if (m_actions == null || m_actions.a_act > nfa.m_state)
         {
             MakeLastAction(nfa.m_state);
             m_tokClass = tokClass;
         }                 // else we have a higher-precedence special action so we do nothing
     }
     return(true);
 }
Ejemplo n.º 2
0
Archivo: Dfa.cs Proyecto: m33p/radegast
 internal bool AddNfaNode(NfaNode nfa)
 {
     if (!this.m_nfa.Add(nfa))
     {
         return(false);
     }
     if (nfa.m_sTerminal != "")
     {
         int    length    = 0;
         string str1      = "";
         string sTerminal = nfa.m_sTerminal;
         if (sTerminal[0] == '%')
         {
             length = 0;
             int index = 1;
             while (index < sTerminal.Length && (sTerminal[index] != ' ' && sTerminal[index] != '\t') && (sTerminal[index] != '\n' && sTerminal[index] != '{' && sTerminal[index] != ':'))
             {
                 ++index;
                 ++length;
             }
             str1 = nfa.m_sTerminal.Substring(1, length);
         }
         if (length > 0 && length + 1 < sTerminal.Length)
         {
             string str2 = nfa.m_sTerminal.Substring(length + 1).Trim();
             if (str2.Length > 0 && str2.StartsWith("%except"))
             {
                 this.m_reswds = nfa.m_state;
                 this.m_tks.m_tokens.reswds[(object)nfa.m_state] = (object)ResWds.New(this.m_tks, str2.Substring(7));
             }
         }
         if (str1 == "")
         {
             if (this.m_tokClass == "" || this.m_actions.a_act > nfa.m_state)
             {
                 this.AddAction(nfa.m_state);
             }
         }
         else if (this.m_actions == null || this.m_actions.a_act > nfa.m_state)
         {
             this.MakeLastAction(nfa.m_state);
             this.m_tokClass = str1;
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
        public static object Serialise(object o, Serialiser s)
        {
            if (s == null)
            {
                return(new ResWds());
            }
            ResWds r = (ResWds)o;

            if (s.Encode)
            {
                s.Serialise(r.m_upper);
                s.Serialise(r.m_wds);
                return(null);
            }
            r.m_upper = (bool)s.Deserialise();
            r.m_wds   = (Hashtable)s.Deserialise();
            return(r);
        }
Ejemplo n.º 4
0
        public static ResWds New(TokensGen tks, string str)
        {
            ResWds r = new ResWds();

            str = str.Trim();
            if (str[0] == 'U')
            {
                r.m_upper = true;
                str       = str.Substring(1).Trim();
            }
            if (str[0] != '{' || str[str.Length - 1] != '}')
            {
                goto bad;
            }
            str = str.Substring(1, str.Length - 2).Trim();
            string[] wds = str.Split(',');
            for (int j = 0; j < wds.Length; j++)
            {
                string w = wds[j].Trim();
                string a = w;
                int    i = w.IndexOf(' ');
                if (i > 0)
                {
                    a = w.Substring(i).Trim();
                    w = w.Substring(0, i);
                }
                r.m_wds[w] = a;
                if (tks.m_tokens.tokens[a] == null)
                {
                    TokClassDef t = new TokClassDef(tks, a, "TOKEN");
                    tks.m_outFile.WriteLine("//%{0}+{1}", a, t.m_yynum);
                    tks.m_outFile.Write("public class {0} : TOKEN", a);
                    tks.m_outFile.WriteLine("{ public override string yyname { get { return \"" + a + "\";}}");
                    tks.m_outFile.WriteLine("public override int yynum { get { return " + t.m_yynum + "; }}");
                    tks.m_outFile.WriteLine(" public " + a + "(Lexer yyl):base(yyl) {}}");
                }
            }
            return(r);

bad:
            tks.m_tokens.erh.Error(new CSToolsException(47, "bad ResWds element"));
            return(null);
        }
Ejemplo n.º 5
0
        public static ResWds New(TokensGen tks, string str)
        {
            ResWds resWds = new ResWds();

            str = str.Trim();
            if (str[0] == 'U')
            {
                resWds.m_upper = true;
                str            = str.Substring(1).Trim();
            }
            if (str[0] == '{' && str[str.Length - 1] == '}')
            {
                str = str.Substring(1, str.Length - 2).Trim();
                string str1    = str;
                char[] chArray = new char[1] {
                    ','
                };
                foreach (string str2 in str1.Split(chArray))
                {
                    string str3 = str2.Trim();
                    string name = str3;
                    int    num  = str3.IndexOf(' ');
                    if (num > 0)
                    {
                        name = str3.Substring(num).Trim();
                        str3 = str3.Substring(0, num);
                    }
                    resWds.m_wds[(object)str3] = (object)name;
                    if (tks.m_tokens.tokens[(object)name] == null)
                    {
                        TokClassDef tokClassDef = new TokClassDef((GenBase)tks, name, "TOKEN");
                        tks.m_outFile.WriteLine("//%{0}+{1}", (object)name, (object)tokClassDef.m_yynum);
                        tks.m_outFile.Write("public class {0} : TOKEN", (object)name);
                        tks.m_outFile.WriteLine("{ public override string yyname { get { return \"" + name + "\";}}");
                        tks.m_outFile.WriteLine("public override int yynum { get { return " + (object)tokClassDef.m_yynum + "; }}");
                        tks.m_outFile.WriteLine(" public " + name + "(Lexer yyl):base(yyl) {}}");
                    }
                }
                return(resWds);
            }
            tks.m_tokens.erh.Error(new CSToolsException(47, "bad ResWds element"));
            return((ResWds)null);
        }
Ejemplo n.º 6
0
 /// <exclude/>
 public static ResWds New(TokensGen tks,string str)
 {
     ResWds r = new ResWds();
     str = str.Trim();
     if (str[0]=='U')
     {
         r.m_upper = true;
         str = str.Substring(1).Trim();
     }
     if (str[0]!='{' || str[str.Length-1]!='}')
         goto bad;
     str = str.Substring(1,str.Length-2).Trim();
     string[] wds = str.Split(',');
     for (int j=0;j<wds.Length;j++)
     {
         string w = wds[j].Trim();
         string a = w;
         int i = w.IndexOf(' ');
         if (i>0)
         {
             a = w.Substring(i).Trim();
             w = w.Substring(0,i);
         }
         r.m_wds[w] = a;
         if (tks.m_tokens.tokens[a]==null)
         {
             TokClassDef t = new TokClassDef(tks,a,"TOKEN");
             tks.m_outFile.WriteLine("//%{0}+{1}",a,t.m_yynum);
             tks.m_outFile.Write("public class {0} : TOKEN",a);
             tks.m_outFile.WriteLine("{ public override string yyname { get { return \""+a+"\";}}");
             tks.m_outFile.WriteLine("public override int yynum { get { return "+t.m_yynum+"; }}");
             tks.m_outFile.WriteLine(" public "+a+"(Lexer yyl):base(yyl) {}}");
         }
     }
     return r;
     bad:
         tks.m_tokens.erh.Error(new CSToolsException(47,"bad ResWds element"));
     return null;
 }