summaryrefslogtreecommitdiff
path: root/JPratt/src/main/java/bjc/pratt/commands/BinaryPostCommand.java
blob: 1fa1ba3e5ca35e1491801a0d99f241452a71b661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package bjc.pratt.commands;

/**
 * A operator with fixed precedence.
 *
 * @author bjculkin
 *
 * @param <K>
 *        The key type of the tokens.
 *
 * @param <V>
 *        The value type of the tokens.
 *
 * @param <C>
 *        The state type of the parser.
 */
public abstract class BinaryPostCommand<K, V, C> extends NonInitialCommand<K, V, C> {
	private final int leftPower;

	/**
	 * Create a new operator with fixed precedence.
	 *
	 * @param precedence
	 *        The precedence of the operator.
	 */
	public BinaryPostCommand(final int precedence) {
		if(precedence < 0) throw new IllegalArgumentException("Precedence must be non-negative");

		leftPower = precedence;
	}

	@Override
	public int leftBinding() {
		return leftPower;
	}
}