maj
This commit is contained in:
60
DEV3.4/ControleMachine/test/ExempleSY1.java
Normal file
60
DEV3.4/ControleMachine/test/ExempleSY1.java
Normal file
@@ -0,0 +1,60 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user