summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/parserutils/pratt/NonInitialCommand.java
blob: b6797d3b2ff80c18256cec1da392acdb53230877 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package bjc.utils.parserutils.pratt;

import bjc.utils.data.ITree;
import bjc.utils.parserutils.ParserException;

/**
 * Represents a non-initial command in parsing.
 * 
 * @author EVE
 * 
 * @param <K>
 *                The key type for the tokens.
 * 
 * @param <V>
 *                The value type for the tokens.
 * 
 * @param <C>
 *                The state type of the parser.
 *
 */
public abstract class NonInitialCommand<K, V, C> {
	/**
	 * Construct the left denotation of this command.
	 * 
	 * @param operand
	 *                The left-hand operand of this command.
	 * @param operator
	 *                The operator for this command.
	 * 
	 * @param ctx
	 *                The state needed for commands.
	 * 
	 * @return The tree this command forms.
	 * 
	 * @throws ParserException
	 *                 If something went wrong during parsing.
	 */
	public abstract ITree<Token<K, V>> denote(ITree<Token<K, V>> operand, Token<K, V> operator,
			ParserContext<K, V, C> ctx) throws ParserException;

	/**
	 * Get the left-binding power of this command.
	 * 
	 * This represents the general precedence of this command.
	 * 
	 * @return The left-binding power of this command.
	 */
	public abstract int leftBinding();

	/**
	 * Get the next-binding power of this command.
	 * 
	 * This represents the highest precedence of command this command can be
	 * the left operand of.
	 * 
	 * This is the same as the left-binding power by default.
	 * 
	 * @return The next-binding power of this command.
	 */
	public int nextBinding() {
		return leftBinding();
	}
}