59 lines
1.4 KiB
Java
Executable file
59 lines
1.4 KiB
Java
Executable file
/** Afficheur infixe, complètement parenthésé, d'une expression arithmétique.
|
|
*
|
|
* @author Xavier Crégut
|
|
* @version $Revision$
|
|
*/
|
|
public class AfficheurInfixe implements VisiteurExpression<String> {
|
|
|
|
public String visiterAccesVariable(AccesVariable v) {
|
|
return "(" + v.getNom() + ")";
|
|
}
|
|
|
|
public String visiterConstante(Constante c) {
|
|
return "(" + String.valueOf(c.getValeur()) + ")";
|
|
}
|
|
|
|
public String visiterExpressionTernaire(ExpressionTernaire e) {
|
|
return "("
|
|
+ "let" + e.getOperateur().accepter(this)
|
|
+ " " + e.getOperande1().accepter(this)
|
|
+ "=" + e.getOperande2().accepter(this)
|
|
+ " in " + e.getOperande3().accepter(this)
|
|
+ ")" ;
|
|
}
|
|
|
|
public String visiterLet(Let l) {
|
|
return "";
|
|
}
|
|
|
|
|
|
public String visiterExpressionBinaire(ExpressionBinaire e) {
|
|
return "(" + e.getOperandeGauche().accepter(this)
|
|
+ " " + e.getOperateur().accepter(this)
|
|
+ " " + e.getOperandeDroite().accepter(this)
|
|
+ ")" ;
|
|
}
|
|
|
|
public String visiterAddition(Addition a) {
|
|
return "+";
|
|
}
|
|
|
|
public String visiterSoustraction(Soustraction a) {
|
|
return "-";
|
|
}
|
|
|
|
public String visiterMultiplication(Multiplication m) {
|
|
return "*";
|
|
}
|
|
|
|
public String visiterExpressionUnaire(ExpressionUnaire e) {
|
|
return "(" + e.getOperateur().accepter(this)
|
|
+ " " + e.getOperande().accepter(this) + ")";
|
|
}
|
|
|
|
public String visiterNegation(Negation n) {
|
|
return "~";
|
|
}
|
|
|
|
}
|