示例#1
0
 public CfgConflict(CfgConflictKind kind, CfgRule rule1, CfgRule rule2, string symbol)
 {
     Kind   = kind;
     Rule1  = rule1 ?? throw new ArgumentNullException("rule1");
     Rule2  = rule2 ?? throw new ArgumentNullException("rule2");
     Symbol = symbol;
 }
示例#2
0
        CfgLL1ParseTable _MakeConflictTable(CfgRule left, CfgRule right, int index)
        {
            var result = new CfgLL1ParseTable();

            throw new NotImplementedException();
            //return result;
        }
示例#3
0
        public int GetK(CfgRule left, CfgRule right, int maxK = 20)
        {
            var lleft = new List <IList <string> >();

            lleft.Add(left.Right);
            var lright = new List <IList <string> >();

            lright.Add(right.Right);
            for (int i = 1; i < maxK; ++i)
            {
                if (_AreDistinct(ExpandRights(lleft, i), ExpandRights(lright, i)))
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#4
0
        static CfgRule _ParseRule(ParseContext pc)
        {
            var result = new CfgRule();

            pc.TrySkipWhiteSpace();
            pc.ClearCapture();
            pc.TryReadUntil(false, ' ', '\t', '\r', '\n', '\f', '\v', '-');
            result.Left = pc.Capture;
            pc.TrySkipWhiteSpace();
            pc.Expecting('-');
            pc.Advance();
            pc.Expecting('>');
            pc.Advance();
            while (-1 != pc.Current && '\n' != pc.Current)
            {
                pc.TrySkipWhiteSpace();
                pc.ClearCapture();
                pc.TryReadUntil(false, ' ', '\t', '\r', '\n', '\f', '\v');
                result.Right.Add(pc.Capture);
            }
            pc.TrySkipWhiteSpace();
            return(result);
        }
示例#5
0
        public override IList <IList <string> > ToDisjunctions(EbnfDocument parent, Cfg cfg)
        {
            string sid = null;
            var    sr  = Expression as EbnfRefExpression;

            if (null != parent && null != sr)
            {
                sid = string.Concat(sr.Symbol, "list");
            }
            if (string.IsNullOrEmpty(sid))
            {
                var cc = Expression as EbnfConcatExpression;
                if (null != cc)
                {
                    sr = cc.Right as EbnfRefExpression;
                    if (null != sr)
                    {
                        sid = string.Concat(sr.Symbol, "listtail");
                    }
                }
            }
            if (string.IsNullOrEmpty(sid))
            {
                sid = "implicitlist";
            }
            var _listId = cfg.GetUniqueId(sid);
            var attrs   = new AttributeSet();

            attrs.Add("collapsed", true);
            cfg.AttributeSets.Add(_listId, attrs);
            var expr =
                new EbnfOrExpression(
                    new EbnfConcatExpression(
                        new EbnfRefExpression(_listId), Expression), Expression);

            //if (IsOptional)
            //	expr = new EbnfOrExpression(expr, null);
            foreach (var nt in expr.ToDisjunctions(parent, cfg))
            {
                CfgRule r = new CfgRule();
                r.Left = _listId;
                foreach (var s in nt)
                {
                    if (1 < r.Right.Count && null == s)
                    {
                        continue;
                    }
                    r.Right.Add(s);
                }
                if (!cfg.Rules.Contains(r))
                {
                    cfg.Rules.Add(r);
                }
            }
            if (!IsOptional)
            {
                return(new List <IList <string> >(new IList <string>[] { new List <string>(new string[] { _listId }) }));
            }
            else
            {
                var result = new List <IList <string> >();
                result.Add(new List <string>(new string[] { _listId }));
                result.Add(new List <string>());
                return(result);
            }
        }
示例#6
0
 public CfgLL1ParseTableEntry(CfgRule rule, CfgLL1ParseTable conflictTable = null)
 {
     Rule          = rule;
     ConflictTable = conflictTable;
 }