summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/v2/Shunter.java
blob: bca08eb737446cb2c6771f6cce891e61f8774a0b (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
package bjc.dicelang.v2;

import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.FunctionalMap;
import bjc.utils.funcdata.IList;
import bjc.utils.funcdata.IMap;

import java.util.HashSet;
import java.util.Set;

import static bjc.dicelang.v2.Token.Type.*;

public class Shunter {
	// The binary operators and their
	// priorities
	private IMap<Token.Type, Integer> ops;

	// Unary operators that can only be
	// applied to non-operator tokens
	private Set<Token.Type> unaryAdjectives;
	
	// Unary operators that con only be
	// applied to operator tokens
	private Set<Token.Type> unaryAdverbs;

	private final int MATH_PREC	= 20;
	private final int DICE_PREC	= 10;
	private final int EXPR_PREC	= 0;

	public Shunter() {
		ops = new FunctionalMap<>();

		unaryAdjectives = new HashSet<>();
		unaryAdverbs    = new HashSet<>();

		ops.put(ADD,      0 + MATH_PREC);
		ops.put(SUBTRACT, 0 + MATH_PREC);

		ops.put(MULTIPLY, 1 + MATH_PREC);
		ops.put(IDIVIDE,  1 + MATH_PREC);
		ops.put(DIVIDE,   1 + MATH_PREC);

		ops.put(DICEGROUP,  0 + DICE_PREC);
		ops.put(DICECONCAT, 1 + DICE_PREC);

		ops.put(LET,  0 + EXPR_PREC);
		ops.put(BIND, 1 + EXPR_PREC);
	}

	public IList<Token> shuntTokens(IList<Token> tks) {
		IList<Token> returned = new FunctionalList<>();

		for(Token tk : tks.toIterable()) {

		}

		return returned;
	}
}