@@ -0,0 +1,2303 @@
+package mohsen;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.HashSet;%0A%0Apublic class Grammar %7B%0A    private HashMap%3CString, HashSet%3CString%3E%3E products;%0A    private String firstState;%0A%0A    public Grammar(String firstState) %7B%0A        this.firstState = firstState;%0A        products = new HashMap%3CString, HashSet%3CString%3E%3E();%0A    %7D%0A%0A    /**%0A     * adds a product to grammar%0A     *%0A     * @param product enter like this pattern : S-%3EAB%7Ca%0A     */%0A    public void addProduct(String product) %7B%0A        String%5B%5D strings = product.split(%22-%3E%22);%0A        String key = strings%5B0%5D;%0A        HashSet%3CString%3E values;%0A        if (products.containsKey(key))%0A            values = products.get(key);%0A        else%7B%0A            values = new HashSet%3CString%3E();%0A            products.put(key,values);%0A        %7D%0A        String%5B%5D newValues = strings%5B1%5D.split(%22%5C%5C%7C%22);%0A        for (String s : newValues)%0A            values.add(s);%0A    %7D%0A%0A    /**%0A     * 'product' will be deleted%0A     *%0A     * @param generator non-terminal%0A     * @param product   non-terminal or terminal%0A     */%0A    public void removeProduct(String generator, String product) %7B%0A        for (Map.Entry%3CString, HashSet%3CString%3E%3E entry : products.entrySet()) %7B%0A            if (entry.getKey().equals(generator)) %7B%0A                entry.getValue().remove(product);%0A                return;%0A            %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     *%0A     * @param product%0A     * @return a list of generators. if key not found returns null.%0A     */%0A    public ArrayList%3CString%3E getGenerators(String product) %7B%0A        ArrayList%3CString%3E result = new ArrayList%3CString%3E();%0A        for (Map.Entry%3CString, HashSet%3CString%3E%3E entry : products.entrySet()) %7B%0A            HashSet%3CString%3E prod = entry.getValue();%0A            for (String s : prod) %7B%0A                if (s.equals(product))%0A                    result.add(entry.getKey());%0A            %7D%0A        %7D%0A%0A        return (result.size() %3E 0) ? result : null;%0A    %7D%0A%0A%0A    public ArrayList%3CString%3E getAllVariables()%7B%0A        ArrayList%3CString%3E vars = new ArrayList%3CString%3E();%0A        for (Map.Entry%3CString, HashSet%3CString%3E%3E entry : products.entrySet()) %7B%0A            vars.add(entry.getKey());%0A        %7D%0A%0A        return vars;%0A    %7D%0A%0A    public String getFirstState() %7B%0A        return firstState;%0A    %7D%0A%7D%0A

Create Grammar.java