Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if let Some(following_nonterminals) = indirections.get(&elem) {
- for &(other, idx, rule) in following_nonterminals.iter() {
- if !result.contains_key(&other) { continue; }
- let mut copy = HashSet::new();
- let mut needs_next = false;
- { // Lifetimes woo
- let other_first_set = result.get(&other).unwrap();
- for &term in other_first_set.iter() {
- match term {
- ProdElem::Epsilon => needs_next = true,
- _ => { copy.insert(term); }
- }
- }
- }
- if needs_next {
- if idx < rule.len() - 1 && !following_nonterminals.contains(&(rule[idx+1], idx + 1, rule)) {
- if Grammar::analyze_rule_for_first(rule, idx + 1, result.get_mut(&elem).unwrap(), indirections.get_mut(&elem).unwrap()) {
- dirty = true
- }
- } else if idx == rule.len() - 1 && !result.get(&elem).unwrap().contains(&ProdElem::Epsilon) {
- result.get_mut(&elem).unwrap().insert(ProdElem::Epsilon);
- dirty = true;
- }
- }
- for &c in copy.iter() {
- if !result.get_mut(&elem).unwrap().contains(&c) {
- result.get_mut(&elem).unwrap().insert(c);
- dirty = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement