コード例 #1
0
ファイル: Set.cs プロジェクト: li-fstz/CPP-EP
        public static Set Gen(string s)
        {
            Set   set = null;
            Match m   = AddressToSymbolInQuot.Match(s);

            if (m.Success)
            {
                string address = m.Groups[1].Value;
                Set    h       = Get <Set> (address, s);
                if (h is Set)
                {
                    set = h;
                }
                else
                {
                    set = new Set(address, s)
                    {
                        Name     = m.Groups[2].Value,
                        Terminal = new List <string> ()
                    };
                    MatchCollection ms = Text.Matches(s);
                    for (int i = 1; i < ms.Count; i++)
                    {
                        if (ms[i].Success)
                        {
                            set.Terminal.Add(ms[i].Groups[1].Value);
                        }
                    }
                }
            }
            return(set);
        }
コード例 #2
0
ファイル: Rule.cs プロジェクト: li-fstz/CPP-EP
        public static Rule Gen(string s)
        {
            if (s == null)
            {
                return(null);
            }

            Rule r = null;

            string[] ProductionStrings = s.Split(new string[] { "~\"|production|\"" }, StringSplitOptions.RemoveEmptyEntries);
            if (ProductionStrings.Length > 0)
            {
                Match m = AddressToSymbolInQuot.Match(ProductionStrings[0]);
                if (m.Success)
                {
                    string address = m.Groups[1].Value;
                    Rule   h       = Get <Rule> (address, s);
                    if (h is Rule)
                    {
                        r = h;
                    }
                    else
                    {
                        r = new Rule(address, s)
                        {
                            Name        = m.Groups[2].Value,
                            Productions = new List <Production> ()
                        };
                        for (int i = 1; i < ProductionStrings.Length; i++)
                        {
                            Production p = Production.Gen(ProductionStrings[i]);
                            if (p != null)
                            {
                                r.Productions.Add(p);
                            }
                        }
                    }
                }
            }
            return(r);
        }