106 lines
3.1 KiB
Java
106 lines
3.1 KiB
Java
import java.util.Deque;
|
|
import java.util.ArrayDeque;
|
|
|
|
|
|
|
|
public class ExempleSY4{
|
|
public static void main(String[] args){
|
|
// utilisation de l'algo de Fortan sur l'expression de ExempleSY3
|
|
// (( 3 ))+(( 4 )*( ( (( 2 ))-(( 1)))))
|
|
// doit donner 3421-*+ mais le parseur actuel ne sait pas gérer plusieurs parenthèses.
|
|
Deque<AbstractToken> expression = new ArrayDeque<AbstractToken>();
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenConstant(3));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenOperator(Operator.ADD));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenConstant(4));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenOperator(Operator.MUL));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenConstant(2));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenOperator(Operator.SUB2));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenSeparator(Separator.LB));
|
|
expression.addLast(new TokenConstant(1));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
expression.addLast(new TokenSeparator(Separator.RB));
|
|
|
|
ShuntingYard se = new ShuntingYard(expression);
|
|
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
se.shunting();
|
|
System.out.println(se);
|
|
}
|
|
}
|
|
|