Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a new parse table from the given context free grammar.
        /// </summary>
        /// <param name="cfg"></param>
        public ParseTable(ContextFreeGrammar <T> cfg)
        {
            ActionTable = new Table <int, Terminal <T>, List <ParserAction <T> > >();
            GotoTable   = new Table <int, NonTerminal <T>, int?>();

            buildParseTable(cfg.CreateStateGraph(), cfg.StartElement);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Sets Parse Table from the given grammar.
        /// </summary>
        /// <param name="grammar"></param>
        /// <exception cref="ArgumentNullException">The value of 'grammar' cannot be null. </exception>
        /// <exception cref="InvalidParseTableException">
        ///     Thrown when the given parse table contains either a 'Shift
        ///     Reduce' conflict or a 'Reduce Reduce' conflict.
        /// </exception>
        public virtual void SetParseTable(ContextFreeGrammar <T> grammar)
        {
            if (grammar == null)
            {
                throw new ArgumentNullException("grammar", "The given grammar must be non-null");
            }

            StateGraph <GrammarElement <T>, LRItem <T>[]> graph = grammar.CreateStateGraph();

            SetParseTable(new ParseTable <T>(graph, grammar.StartElement), graph);
            EndOfInputElement = grammar.EndOfInputElement;
        }