40 lines
767 B
Java
40 lines
767 B
Java
import java.util.Objects;
|
|
|
|
/**
|
|
* Jeton pour les opérateurs
|
|
*
|
|
* sert uniquement à des opérations entières, pas d'autre type pour l'instant.
|
|
*
|
|
*
|
|
* @author Florent Madelaine
|
|
* @see Operators.java
|
|
*/
|
|
|
|
|
|
public class TokenOperator extends AbstractToken{
|
|
|
|
private Operator o;
|
|
|
|
public TokenOperator(Operator o){
|
|
Objects.requireNonNull(o, "o must not be null");
|
|
this.o=o;
|
|
}
|
|
|
|
public Operator getOperator(){
|
|
return this.o;
|
|
}
|
|
|
|
public boolean takesPrecedenceOver(TokenOperator to2){
|
|
return (this.o.ordinal() < to2.getOperator().ordinal()
|
|
||
|
|
((this.o.ordinal() == to2.getOperator().ordinal())
|
|
&&
|
|
to2.getOperator().isLeftAssociative()));
|
|
}
|
|
|
|
@Override
|
|
public String toString(){
|
|
return this.o.toString();
|
|
}
|
|
}
|