/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /// <summary>Equality comparison. /// </summary> public virtual 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); } }
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /// <summary>Equality comparison. /// </summary> public virtual 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; } }
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /// <summary>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. /// </summary> public virtual void compute_closure() { lalr_item_set consider; lalr_item itm, new_itm, add_itm; non_terminal nt; terminal_set new_lookaheads; System.Collections.IEnumerator p; production prod; bool need_prop; /* invalidate cached hashcode */ hashcode_cache = int.MinValue; /* 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 */ //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"' for (p = nt.productions(); p.MoveNext(); ) { //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"' 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); } } } } }
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/ /// <summary>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. /// </summary> public virtual void compute_closure() { lalr_item_set consider; lalr_item itm, new_itm, add_itm; non_terminal nt; terminal_set new_lookaheads; System.Collections.IEnumerator p; production prod; bool need_prop; /* invalidate cached hashcode */ hashcode_cache = int.MinValue; /* 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 */ //UPGRADE_TODO: method 'java.util.Enumeration.hasMoreElements' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationhasMoreElements"' for (p = nt.productions(); p.MoveNext();) { //UPGRADE_TODO: method 'java.util.Enumeration.nextElement' was converted to ' ' which has a different behavior. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1073_javautilEnumerationnextElement"' 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); } } } } }