Skip to content

Instantly share code, notes, and snippets.

@Feder1co5oave
Created February 13, 2012 16:40
Show Gist options
  • Save Feder1co5oave/1818063 to your computer and use it in GitHub Desktop.
Save Feder1co5oave/1818063 to your computer and use it in GitHub Desktop.
package arithmeticExpression.tokens;
import java.util.regex.Pattern;
/**
*
* @author Feder1co 5oave
*/
public class Operator extends Token {
//TODO verificare la correttezza dell'uso dei get* static
public enum Operators {
ADDITION ("+", 0),
SUBSTRACTION ("-", 0),
MULTIPLICATION ("*", 1),
DIVISION ("/", 1);
Operators (String s, int prio) {
this.s = s;
this.prio = prio;
}
private int prio;
private String s;
}
private Operators type;
public Operator (int pos, Operators type) { //XXX private contructor
super(pos);
this.type = type;
}
public final int compareTo(Operator o) { //per prioritÃ
Integer me, you;
me = this.type.prio;
you = o.type.prio;
return me.compareTo(you);
}
public Operators getType () {
return this.type;
}
public int getPrio () {
return type.prio;
}
public String toString () {
return this.type.s;
}
public static Operator getAdd (int pos) {
return new Operator(pos, Operators.ADDITION);
}
public static Operator getSub (int pos) {
return new Operator(pos, Operators.SUBSTRACTION);
}
public static Operator getMul (int pos) {
return new Operator(pos, Operators.MULTIPLICATION);
}
public static Operator getDiv (int pos) {
return new Operator(pos, Operators.DIVISION);
}
public Operator clone() {
return new Operator(this.getPos(), this.type);
}
public Pattern getRegex() {
//TODO scrivere
throw new UnsupportedOperationException("Not supported yet.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment