All pastes #550878 Raw Edit

Main.java

public java v1 · immutable
·published 2007-06-08 15:39 UTC
rendered paste body
/* * Main.java * * Created on 3 de junio de 2007, 19:04 * * To change this template, choose Tools | Template Manager * and open the template in the editor. *//** * * @author E */import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Observable;import java.util.Observer;import Gramaticas.Cadena;import Gramaticas.GIC;import Gramaticas.G_Exception;import Gramaticas.No_terminal;import Gramaticas.Scanner;import Gramaticas.Simbolo;public class Main {    private BufferedReader br;    private boolean exit;	private int option;        public static final String[] options = {        "Debug",        "Apartado 1 (Sin salida)",        "Apartado 2 ()",        "Apartado 3 ()",        "Apartado 4 ()",        "Apartado 5 ()",        "Apartado 6 ()",    };        public static final Observer[] observers = {    	new Observer() {  // DEBUG		public void update(Observable arg0, Object arg1) {			Scanner s = (Scanner) arg0;            System.out.println(">> a"+s.cont +" r:"+s.i+"  A:"+s.A.get_id()+"  R:"+ s.reglasArray[s.i].toString());            System.out.println("u:"+imprime(s.u)+"  w:"+imprime(s.w)+"  v:"+imprime(s.v));            //System.out.println("////");            //System.out.println("("+ sc.cont + ", "+ sc.i +")");   		}},				new Observer() { // Apartado 1 Sin salida		public void update(Observable arg0, Object arg1) {					}},					new Observer() { // Apartado 2		public void update(Observable arg0, Object arg1) {			Scanner s = (Scanner) arg0;            System.out.println(">>>> " + s.reglasArray[s.i].toString());            System.out.println("////");            System.out.println("("+ s.cont + ", "+ s.i +")");					}},					new Observer() { // Apartado 3		public void update(Observable arg0, Object arg1) {			Scanner s = (Scanner) arg0;            System.out.println("Consideramos la regla >>>> " + s.reglasArray[s.i].toString());            System.out.println("&#65533;uwv &#65533; E*? "+ s.uwv.toString());            System.out.println("("+ s.cont + ", "+ s.i +")");					}},					new Observer() { // Apartado 4		public void update(Observable arg0, Object arg1) {			Scanner s = (Scanner) arg0;			System.out.println("("+ s.contNodos + ", "+ s.cont +")  " + s.uwv);					}},					new Observer() { // Apartado 5		public void update(Observable arg0, Object arg1) {			Scanner sc = (Scanner) arg0;            System.out.println(">>>> " + sc.reglasArray[sc.i].toString());            System.out.println("////");            System.out.println("("+ sc.cont + ", "+ sc.i +")");					}},					new Observer() { // Apartado 6			private int encontradas = 0;		public void update(Observable arg0, Object arg1) {			Scanner sc = (Scanner) arg0;            System.out.println(">>>> " + sc.reglasArray[sc.i].toString());            System.out.println("////");            System.out.println("("+ sc.cont + ", "+ sc.i +")");					}}    };	    /**     * @param args     */	public void init() throws G_Exception {		exit = true;        GIC g = new GIC("S A T; p q o b; S; S -> A; A -> T; A -> A o T; T -> b; T -> p A q;");        No_terminal S = new No_terminal("S");        Cadena cad = new Cadena("pbobq");        br = new BufferedReader(new InputStreamReader(System.in));        do {        	try {                for (int i = 0; i < options.length; i++) {                    System.out.println((i+1) + ". " + options[i]);                }                option = Integer.parseInt(br.readLine());                if (option < 1 || option > options.length)                   throw new NumberFormatException();                                                Scanner s = new Scanner();                s.addObserver(observers[option-1]);                s.scanAnchura(S, cad, g);                 exit = true;	        } 	        catch(IOException e) {	            System.out.println("Opcion no valida");	        } 	        catch(NumberFormatException e) {	            System.out.println("Opcion no valida");	        } catch (G_Exception e) {				// TODO Auto-generated catch block				e.printStackTrace();			}         } while (!exit);        System.exit(0);	}        /**     *      * @param array     * @return     */    public static String imprime(ArrayList<Simbolo> array) {        StringBuilder sb = new StringBuilder();        sb.append("{ ");        for (Simbolo s : array) {            sb.append(s.toString()+" ");        }        sb.append("}");        return sb.toString();    }    	    public static void main(String[] args) throws G_Exception {    	new Main().init();    }    }