summaryrefslogtreecommitdiff
path: root/dice-lang/src/bjc/dicelang/CompilerTweaker.java
blob: ef965b5a3c9b45f399abf8ef12bdb237d9fb6bd0 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package bjc.dicelang;

import bjc.utils.funcutils.TokenSplitter;

/**
 * Contains methods for customizing the DiceLang and SCL compilers.
 *
 * @author Ben Culkin
 */
public class CompilerTweaker {
	/*
	 * Bits of the compiler necessary
	 */
	private DiceLangEngine		eng;
	private TokenSplitter	opExpander;

	public CompilerTweaker(DiceLangEngine eng) {
		this.eng = eng;

		this.opExpander = eng.opExpander;
	}

	/**
	 * Add a string literal to the compiler's internal banks.
	 *
	 * @param val
	 *                The string literal to add.
	 *
	 * @return The key into the string literal table for this string.
	 */
	public int addStringLiteral(String val) {
		eng.addStringLiteral(eng.nextLiteral, val);

		eng.nextLiteral += 1;
		return eng.nextLiteral;
	}

	/**
	 * Add a line defn to the compiler.
	 *
	 * @param dfn
	 *                The defn to add.
	 */
	public void addLineDefine(Define dfn) {
		eng.addLineDefine(dfn);
	}

	/**
	 * Add a token defn to the compiler.
	 *
	 * @param dfn
	 *                The defn to add.
	 */
	public void addTokenDefine(Define dfn) {
		eng.addTokenDefine(dfn);
	}

	/**
	 * Adds a delimiter that is expanded from tokens.
	 *
	 * @param delim
	 *                The delimiter to expand on.
	 */
	public void addDelimiter(String delim) {
		opExpander.addDelimiter(delim);
	}

	/**
	 * Adds a multi-character delimiter that is expanded from tokens.
	 *
	 * @param delim
	 *                The multi-character delimiter to expand on.
	 */
	public void addMultiDelimiter(String delim) {
		opExpander.addMultiDelimiter(delim);
	}

	/**
	 * Make delimiter changes visible to the compiler.
	 */
	public void compile() {
		opExpander.compile();
	}

	/**
	 * Change the max no. of times defines are allowed to recur.
	 *
	 * @param times
	 *                The number of times to allow defines to recur.
	 */
	public void setDefineRecurLimit(int times) {
		Define.MAX_RECURS = times;
	}
}