summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/commands/BinaryPostCommand.java
blob: 806f2f30727289ba0b7d34de75eb29fe5f079342 (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
37
38
39
40
package bjc.utils.parserutils.pratt.commands;

import bjc.utils.parserutils.pratt.NonInitialCommand;

/**
 * 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(int precedence) {
		if (precedence < 0) {
			throw new IllegalArgumentException("Precedence must be non-negative");
		}

		leftPower = precedence;
	}

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