Diseño de aplicaciones orientadas a objetos
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
package patronInterpreter;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
//esta clase seria el cliente
|
|
|
|
|
public class Main {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
String roman = "MCMXXVIII";
|
|
|
|
|
Context context = new Context(roman);
|
|
|
|
|
|
|
|
|
|
//Construye el <EFBFBD>rbol sint<EFBFBD>ctico
|
|
|
|
|
ArrayList<Expression> tree = new ArrayList<Expression>();
|
|
|
|
|
tree.add(new ThousandExpression());
|
|
|
|
|
tree.add(new HundredExpression());
|
|
|
|
|
tree.add(new TenExpression());
|
|
|
|
|
tree.add(new OneExpression());
|
|
|
|
|
|
|
|
|
|
// Interpretar: recorre todas las Expresiones del <EFBFBD>rbol.
|
|
|
|
|
for (Iterator it = tree.iterator(); it.hasNext();){
|
|
|
|
|
Expression exp = (Expression)it.next();
|
|
|
|
|
exp.interpret(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println(roman + " = " + Integer.toString(context.getOutput()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|