61 lines
1.6 KiB
Java
61 lines
1.6 KiB
Java
import java.util.Deque;
|
|
import java.util.ArrayDeque;
|
|
|
|
public class ExempleSY1{
|
|
public static void main(String[] args){
|
|
// 3 + 4 * 2
|
|
// doit donner 342*+
|
|
ArrayDeque<AbstractToken> expression = new ArrayDeque<AbstractToken>();
|
|
expression.addLast(new TokenConstant(3));
|
|
expression.addLast(new TokenOperator(Operator.ADD));
|
|
expression.addLast(new TokenConstant(4));
|
|
expression.addLast(new TokenOperator(Operator.MUL));
|
|
expression.addLast(new TokenConstant(2));
|
|
|
|
ShuntingYard se1 = new ShuntingYard(expression);
|
|
ShuntingYard se2 = new ShuntingYard(expression.clone());
|
|
// à la main
|
|
System.out.println("-----à la main -----");
|
|
System.out.println(se1);
|
|
se1.shuntFromInput(); //step1
|
|
System.out.println(se1);
|
|
se1.pushToStack(); //step2
|
|
System.out.println(se1);
|
|
se1.shuntFromInput(); //step3
|
|
System.out.println(se1);
|
|
se1.pushToStack(); //step4
|
|
System.out.println(se1);
|
|
se1.shuntFromInput(); //step5
|
|
System.out.println(se1);
|
|
se1.shuntFromStack(); //step6
|
|
System.out.println(se1);
|
|
se1.shuntFromStack(); //step7
|
|
System.out.println(se1);
|
|
System.out.println("-----------FIN à la main---------------");
|
|
|
|
// avec l'algo
|
|
System.out.println("-----avec l'algo -----");
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
se2.shunting();
|
|
System.out.println(se2);
|
|
|
|
// se2.shunting();
|
|
// System.out.println(se2);
|
|
// se2.shunting();
|
|
// System.out.println(se2);
|
|
}
|
|
}
|
|
|