Beispiel #1
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /** Equality comparison. */
        public bool Equals(lalr_item_set other)
        {
            if (other == null || other.size() != size())
            {
                return(false);
            }

            /* once we know they are the same size, then improper subset does test */
            try
            {
                return(is_subset_of(other));
            }
            catch (internal_error e)
            {
                /* can't throw error from here (because superclass doesn't) so crash */
                e.crash();
                return(false);
            }
        }
Beispiel #2
0
	/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

	/** Equality comparison. */
	public bool Equals(lalr_item_set other)
{
	if (other == null || other.size() != size()) return false;

	/* once we know they are the same size, then improper subset does test */
	try 
{
	return is_subset_of(other);
} 
	catch (internal_error e) 
{
	/* can't throw error from here (because superclass doesn't) so crash */
	e.crash();
	return false;
}

}
Beispiel #3
0
        /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

        /** Compute the closure of the Set using the LALR closure rules.  Basically
         *  for every item of the form: <pre>
         *    [L ::= a *N alpha, l]
         *  </pre>
         *  (where N is a a non terminal and alpha is a string of symbols) make
         *  sure there are also items of the form:  <pre>
         *    [N ::= *beta, first(alpha l)]
         *  </pre>
         *  corresponding to each production of N.  Items with identical cores but
         *  differing lookahead sets are merged by creating a new item with the same
         *  core and the union of the lookahead sets (the LA in LALR stands for
         *  "lookahead merged" and this is where the merger is).  This routine
         *  assumes that nullability and first sets have been computed for all
         *  productions before it is called.
         */
        public void compute_closure()

        {
            lalr_item_set consider;
            lalr_item     itm, new_itm, add_itm;
            non_terminal  nt;
            terminal_set  new_lookaheads;
            IEnumerator   p;
            production    prod;
            bool          need_prop;



            /* invalidate cached hashcode */
            is_cached = false;

            /* each current element needs to be considered */
            consider = new lalr_item_set(this);

            /* repeat this until there is nothing else to consider */
            while (consider.size() > 0)
            {
                /* get one item to consider */
                itm = consider.get_one();

                /* do we have a dot before a non terminal */
                nt = itm.dot_before_nt();
                if (nt != null)
                {
                    /* create the lookahead Set based on first after dot */
                    new_lookaheads = itm.calc_lookahead(itm.lookahead());

                    /* are we going to need to propagate our lookahead to new item */
                    need_prop = itm.lookahead_visible();

                    /* create items for each production of that non term */
                    p = nt.productions();
                    while (p.MoveNext())
                    {
                        prod = (production)p.Current;

                        /* create new item with dot at start and that lookahead */
                        new_itm = new lalr_item(prod,
                                                new terminal_set(new_lookaheads));

                        /* add/merge item into the Set */
                        add_itm = add(new_itm);
                        /* if propagation is needed link to that item */
                        if (need_prop)
                        {
                            itm.add_propagate(add_itm);
                        }

                        /* was this was a new item*/
                        if (add_itm == new_itm)
                        {
                            /* that may need further closure, consider it also */
                            consider.add(new_itm);
                        }
                    }
                }
            }
        }
Beispiel #4
0
	/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

	/** Compute the closure of the Set using the LALR closure rules.  Basically
	 *  for every item of the form: <pre>
	 *    [L ::= a *N alpha, l] 
	 *  </pre>
	 *  (where N is a a non terminal and alpha is a string of symbols) make 
	 *  sure there are also items of the form:  <pre>
	 *    [N ::= *beta, first(alpha l)] 
	 *  </pre>
	 *  corresponding to each production of N.  Items with identical cores but 
	 *  differing lookahead sets are merged by creating a new item with the same 
	 *  core and the union of the lookahead sets (the LA in LALR stands for 
	 *  "lookahead merged" and this is where the merger is).  This routine 
	 *  assumes that nullability and first sets have been computed for all 
	 *  productions before it is called.
	 */
	public void compute_closure()
	
{
	lalr_item_set consider;
	lalr_item     itm, new_itm, add_itm;
	non_terminal  nt;
	terminal_set  new_lookaheads;
	IEnumerator   p;
	production    prod;
	bool       need_prop;



	/* invalidate cached hashcode */
	is_cached=false;

	/* each current element needs to be considered */
	consider = new lalr_item_set(this);

	/* repeat this until there is nothing else to consider */
	while (consider.size() > 0)
{
	/* get one item to consider */
	itm = consider.get_one(); 

	/* do we have a dot before a non terminal */
	nt = itm.dot_before_nt();
	if (nt != null)
{
	/* create the lookahead Set based on first after dot */
	new_lookaheads = itm.calc_lookahead(itm.lookahead());

	/* are we going to need to propagate our lookahead to new item */
	need_prop = itm.lookahead_visible();

	/* create items for each production of that non term */
	p = nt.productions();
	while ( p.MoveNext() )
{
	prod = (production)p.Current;

	/* create new item with dot at start and that lookahead */
	new_itm = new lalr_item(prod, 
	new terminal_set(new_lookaheads));

	/* add/merge item into the Set */
	add_itm = add(new_itm);
	/* if propagation is needed link to that item */
	if (need_prop)
	itm.add_propagate(add_itm);

	/* was this was a new item*/
	if (add_itm == new_itm)
{
	/* that may need further closure, consider it also */ 
	consider.add(new_itm);
} 
} 
} 
} 
}