ContextFreeGrammar extends Grammar { private boolean isInfinitelyRecursive(Rule startRule) throws MalformedGrammarException { Queue<Rule> rulesToVisit = new Queue<Rule>(); ArrayList<Rule> visitedRules = new ArrayList<Rule>(); Iterator<Symbol> symbIt; Iterator<Production> prodIt; Symbol tempSymbol; Rule currentRule ; rulesToVisit.enqueue(startRule); while(!rulesToVisit.isEmpty()) { currentRule = rulesToVisit.dequeue(); prodIt = currentRule.iterator(); visitedRules.add(currentRule); while(prodIt.hasNext()) { symbIt = prodIt.next().iterator(); while(symbIt.hasNext()) { tempSymbol = symbIt.next(); if(tempSymbol.getType() == Enums.SymbolType.NTSymbol && ! tempSymbol.getSymbolString().startsWith(Constants.GE_CODON_VALUE_PARSING)) { currentRule = this.findRule(tempSymbol); if (currentRule == null) { throw new MalformedGrammarException("No rule found for symbol " + tempSymbol.toString()); } if(!visitedRules.contains(currentRule)) { rulesToVisit.enqueue(currentRule); } } else { return false; } } } } return true; } ContextFreeGrammar();   ContextFreeGrammar(ContextFreeGrammar g); abstract boolean genotype2Phenotype(); abstract boolean phenotype2Genotype(); abstract int getUsedCodons(); abstract int getUsedWraps(); @SuppressWarnings({"UnusedReturnValue", "IOResourceOpenedButNotSafelyClosed"}) boolean readBNFFile(String file_name); Rule findRule(Symbol s); Rule findRule(String s); ArrayList getTerminalRules(); ArrayList getNonTerminalRules();  }
@Test public void testIsInfinitelyRecursive() throws MalformedGrammarException { System.out.println("* ContextFreeGrammarTest: isInfinitelyRecursive"); g = new ContextFreeGrammarMock(); String file_name2 = file_name.replace("test_grammar", "test_infiniteRecursive.bnf"); boolean result = g.readBNFFileFromFilesystem(file_name2); assertEquals(false, result); g = new ContextFreeGrammarMock(); file_name2 = file_name.replace("test_grammar", "test_infiniteRecursive_gec.bnf"); result = false; result = g.readBNFFileFromFilesystem(file_name); assertEquals(true, result); }