/* Subject: Contest submission for problem #1, file 1.java */ /* kelvinso@imail.EECS.Berkeley.EDU */ /* Thu Sep 18 02:52:36 PDT 2003 */ /*___CONTEST_SUBMISSION___ kelvinso 1 */ import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.StreamTokenizer; import java.util.*; import java.lang.Double; class P1 { public static void main(String[] arg) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String string; boolean newLine = true; boolean afterColon = false; boolean inFunction = false; boolean afterAssignment = false; boolean openPara = false; boolean closePara = false; boolean isGoto = false; boolean isI = false; boolean isF = false; int numBegin = 0; int gotoNumIndex = 0; Instruction inst = new Instruction(); ArrayList set = new ArrayList(); int setIndex = 0; ArrayList instructions = new ArrayList(); int indexInst = 0; while ((string = in.readLine()) != null) { for (int i = 0; i= string.charAt(i) && gotoNumIndex == 0) { gotoNumIndex = i; } } } for(int i = 0; i< set.size(); i++) { ArrayList ins = (ArrayList) set.get(i); //System.out.println(ins); } for(int i = 0; i < set.size(); i++) { ArrayList ins = (ArrayList) set.get(i); if(findUndefined(ins, 0)) System.out.println("Set " + i + ": No use before definition"); else System.out.println("Set " + i + ": Possible use before definition"); } } public static boolean findUndefined(ArrayList instructions, int index) { Instruction inst = (Instruction) instructions.get(index); //System.out.println(inst); if(inst.stop) return true; if(inst.path.contains(new Integer(index))) return true; HashSet defined = new HashSet(); defined.addAll(inst.definedChar); if(!defined.containsAll(inst.usedChar)) return false; defined.addAll(inst.assignedChar); if(inst.ifStatement) { Instruction gotoInst = (Instruction) instructions.get(inst.gotoLine); gotoInst.path.add(new Integer(index)); gotoInst.path.addAll(inst.path); gotoInst.definedChar.addAll(defined); if(!findUndefined(instructions, inst.gotoLine)) return false; } Instruction nextInst = (Instruction) instructions.get(index + 1); nextInst.path.add(new Integer(index)); nextInst.path.addAll(inst.path); nextInst.definedChar.addAll(defined); if(!findUndefined(instructions, index + 1)) return false; inst.path.clear(); inst.definedChar.clear(); return true; } } class Instruction { public int index; public boolean ifStatement = false; public HashSet assignedChar = new HashSet(); public HashSet usedChar = new HashSet(); public int gotoLine; public boolean stop = false; public HashSet path = new HashSet(); public HashSet definedChar = new HashSet(); public Instruction() { } public String toString() { return "index: " + index + " ifStatement: " + ifStatement + " assignedChar: " + assignedChar + " usedChar: " + usedChar + " gotoLine: " + gotoLine + " stop: " + stop + " path: " + path + " definedChar: " + definedChar; } }