<commit_before>package pp.block2.cc.ll;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import pp.block2.cc.NonTerm;
import pp.block2.cc.Symbol;
import pp.block2.cc.Term;

public class LLCalc{
    public Map<Symbol, Set<Term>> first;
    public Map<NonTerm, Set<Term>> follow;
    public Map<Rule, Set<Term>> first+;
    public Grammar g;

    public LLCalc(Grammar g){
        this.g = g;
        first = new HashMap<Symbol, Set<Term>>();
        follow = new HashMap<NonTerm, Set<Term>>();
        first+ = new HashMap<Rule, Set<Term>>();
        setFirst();
        setFollow();
        setFirst+();
    }

    private void setFirst(){
        Set<Term> terminals = g.getTerminals.size();
        Set<Term> nonTerminals = g.getNonTerminals.size();
        for(int i=0; i < terminals; i++){
            Set<Term>  terms = new HashSet<term>
            first.put(terminals.get(i), terms.put(terminals.get(i)));
        }
        for(int i=0; i < nonTerminals; i++){
            Set<Term>  terms = new HashSet<term>
            first.put(nonTerminals.get(i), terms);
        }
        Map<Symbol, Set<Term>> firstOld = first;
        List<Rule> rules = g.getRules();
        while(!firstOld.equals(first)){
            for(int i=0; i < rules.size(); i++){
                Rule rule = rules.get(i);
                List<Symbol> symbols = rule.getRHS()-epsilon;
                if(symbols.length()>0){
                    Set<Symbol> rhs = First.get(symbols.get(1));
                    int i=1;
                    while(First.get(symbols.get(i)).contains(epsilon)){
                        rhs = rhs + First.get(symbols.get(i+1)) - epsilon;
                        i++
                    }
                }
                if(i==symbols.length() && First.get(symbols.get(symbols.length())).contains(epsilon)){
                    rhs = rhs + epsilon
                }
                First(rule.getLHS()) =First(rule.getLHS()) + rhs;
            }
        }


    }



    private void setFollow(){

    }

    private void setFirst+(){

    }

    /** Returns the FIRST-map for the grammar of this calculator instance. */
    public Map<Symbol, Set<Term>> getFirst(){
        return first;
    }

    /** Returns the FOLLOW-map for the grammar of this calculator instance. */
    public Map<NonTerm, Set<Term>> getFollow(){
        return follow;
    }

    /** Returns the FIRST+-map for the grammar of this calculator instance. */
    public Map<Rule, Set<Term>> getFirstp(){
        return first+;
    }

    /** Indicates if the grammar of this calculator instance is LL(1). */
    public boolean isLL1();


}<commit_msg>Changed implemenation of first<commit_after>package pp.block2.cc.ll;

import pp.block2.cc.NonTerm;
import pp.block2.cc.Symbol;
import pp.block2.cc.Term;

import java.util.*;

public class LLCalcImpl implements LLCalc{
    public Map<Symbol, Set<Term>> first;
    public Map<NonTerm, Set<Term>> follow;
    public Map<Rule, Set<Term>> firstPlus;
    public Grammar g;

    public LLCalcImpl(Grammar g){
        this.g = g;
        first = new HashMap<Symbol, Set<Term>>();
        follow = new HashMap<NonTerm, Set<Term>>();
        firstPlus = new HashMap<Rule, Set<Term>>();
        setFirst();
        setFollow();
        setFirstPlus();
    }

    private void setFirst(){
        Term epsilon = g.getTerminal(Sentence.ENDMARK);
        Set<Term> terminals = g.getTerminals();
        Set<NonTerm> nonTerminals = g.getNonterminals();
        Iterator iter =  terminals.iterator();
        while(iter.hasNext()){
            Set<Term> terms = new HashSet<Term>();
            Term term = (Term) iter.next();
            terms.add(term);
            first.put((Symbol) term, terms);
        }
        iter = nonTerminals.iterator();
        while(iter.hasNext()){
            Set<Term> terms = new HashSet<Term>();
            first.put((Symbol) iter.next(), terms);
        }

        Map<Symbol, Set<Term>> firstOld = first;

        while(!firstOld.equals(first)){
            List<Rule> rules = g.getRules();

            for(int i=0; i < rules.size(); i++){
                Set<Term> rhs=new HashSet<Term>();
                List<Symbol> beta = rules.get(i).getRHS();
                //ik ga er hier vanuit dat alles in beta een terminal of nonterminal is
                iter = first.get(beta.get(0)).iterator();
                while(iter.hasNext()){
                    Term t = (Term) iter.next();
                    if(!t.equals(epsilon)){
                        rhs.add(t);
                    }
                }
                int k=0;
               while(k<beta.size()-1){
                    iter = first.get(beta.get(k)).iterator();
                    while(iter.hasNext()){
                        Term t = (Term) iter.next();
                        if(!t.equals(epsilon)){
                            rhs.add(t);
                        }
                    }
                   k++;
                }
                if(k==beta.size()-1 && first(beta.get(k)).contains(epsilon)){
                    rhs.add(epsilon);
                }
                Set<Term> terms = first(rules.get(i).getLHS());
                iter = rhs.iterator();
                while(iter.hasNext()){
                    terms.add(iter.next());
                }
                first.remove(rules.get(i).getLHS());
                first.put((Symbol) rules.get(i).getLHS(), terms);


            }
        }


    }



    private void setFollow(){

    }

    private void setFirsPlus(){

    }

    /** Returns the FIRST-map for the grammar of this calculator instance. */
    public Map<Symbol, Set<Term>> getFirst(){
        return first;
    }

    /** Returns the FOLLOW-map for the grammar of this calculator instance. */
    public Map<NonTerm, Set<Term>> getFollow(){
        return follow;
    }

    /** Returns the FIRST+-map for the grammar of this calculator instance. */
    public Map<Rule, Set<Term>> getFirstp(){
        return firstPlus;
    }

    /** Indicates if the grammar of this calculator instance is LL(1). */
    public boolean isLL1();


}
{'fraction_non_alphanumeric': 0.1376326530612245, 'fraction_numerical': 0.003918367346938775, 'mean_word_length': 1.7348214285714285, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3385233', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1743, 'n_words': 416}