blob: a521e5c64f2250beaa8c10af533cb3122f591579 (
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
64
65
66
|
package com.ashardalon.pratt.commands;
import com.ashardalon.pratt.ParserContext;
import com.ashardalon.pratt.tokens.Token;
import bjc.data.Tree;
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 result of executing the command.
*
* @throws ParserException
* If something went wrong during parsing.
*/
public abstract CommandResult<K, V> denote(Tree<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();
}
}
|