コード例 #1
0
 public void SetParser(Lalr1Parser parser)
 {
     if (null != _lalr1Parser)
     {
         _lalr1Parser.Close();
     }
     _lalr1Parser = parser;
     if (null != _ll1Parser)
     {
         _ll1Parser.Close();
     }
     _ll1Parser = null;
 }
コード例 #2
0
ファイル: Lalr1.cs プロジェクト: wushian/pck
        public static IList <CfgMessage> TryToLalr1Parser(this CfgDocument cfg, out Lalr1Parser parser, IEnumerable <Token> tokenizer = null, IProgress <CfgLalr1Progress> progress = null)
        {
            CfgLalr1ParseTable parseTable;
            var result = TryToLalr1ParseTable(cfg, progress, out parseTable);
            var syms   = new List <string>();

            cfg.FillSymbols(syms);
            var nodeFlags = new int[syms.Count];

            for (var i = 0; i < nodeFlags.Length; i++)
            {
                var o = cfg.GetAttribute(syms[i], "hidden", false);
                if (o is bool && (bool)o)
                {
                    nodeFlags[i] |= 2;
                }
                o = cfg.GetAttribute(syms[i], "collapsed", false);
                if (o is bool && (bool)o)
                {
                    nodeFlags[i] |= 1;
                }
            }
            var substitutions = new int[syms.Count];

            for (var i = 0; i < substitutions.Length; i++)
            {
                var s = cfg.GetAttribute(syms[i], "substitute", null) as string;
                if (!string.IsNullOrEmpty(s) && cfg.IsSymbol(s) && s != syms[i])
                {
                    substitutions[i] = cfg.GetIdOfSymbol(s);
                }
                else
                {
                    substitutions[i] = -1;
                }
            }
            var attrSets = new KeyValuePair <string, object> [syms.Count][];

            for (var i = 0; i < attrSets.Length; i++)
            {
                CfgAttributeList attrs;
                if (cfg.AttributeSets.TryGetValue(syms[i], out attrs))
                {
                    attrSets[i] = new KeyValuePair <string, object> [attrs.Count];
                    var j = 0;
                    foreach (var attr in attrs)
                    {
                        attrSets[i][j] = new KeyValuePair <string, object>(attr.Name, attr.Value);
                        ++j;
                    }
                }
                else
                {
                    attrSets[i] = null;                    // new KeyValuePair<string, object>[0];
                }
            }
            var ss  = cfg.GetIdOfSymbol(cfg.StartSymbol);
            var ntc = cfg.FillNonTerminals().Count;

            parser = new Lalr1TableParser(parseTable.ToArray(syms), syms.ToArray(), nodeFlags, substitutions, attrSets, tokenizer);
            return(result);
        }