示例#1
0
        private void AutoSizeNodeToFitTerminals()
        {
            var northTerminalCount     = Terminals.Count(m => m.Model.Direction == Direction.North);
            var southTerminalCount     = Terminals.Count(m => m.Model.Direction == Direction.South);
            var northSouthMaxTerminals = Math.Max(northTerminalCount, southTerminalCount);
            var idealWidth             = northSouthMaxTerminals * (Terminal.TerminalWidth + 5) + Diagram.NodeBorderWidth * 2;

            Width = Math.Max(Width, idealWidth);
        }
示例#2
0
        public Term[,] GenerateTable()
        {
            Table = new Term[NonTerminals.Count(), Terminals.Count()];

            foreach (var term in _terms)
            {
                var A = GetIndexNonTerminal(term.Caller);

                foreach (var production in term.Productions)
                {
                    var first = production.FirstToken;

                    var f = first.IsTerminal() || first.IsEmpty()
                        ? new First(term.Caller, new List <TerminalToken> {
                        first.ToTerminalToken()
                    })
                        : _firsts.Single(x => x.NonTerminal == first);

                    foreach (var terminal in f.Terminals)
                    {
                        var a = GetIndexTerminal(terminal);
                        var t = new Term(term.Caller, production);

                        if (terminal.Value == "ε")
                        {
                            var follow = _follows.Single(x => x.NonTerminal == term.Caller);

                            foreach (var followTerminal in follow.Terminals)
                            {
                                var b = GetIndexTerminal(followTerminal);
                                PopulateTable(A, b, t);
                            }
                        }
                        else if (A >= 0 && a >= 0)
                        {
                            PopulateTable(A, a, t);
                        }
                    }
                }
            }

            return(Table);
        }