131 | ```
132 | The standard settings are
133 |
134 | ```FactorioScript
135 | # STANDARD => signal-Y signal-Z
136 | ```
137 | So, if you need *signal-Y* and *signal-Z* in your equations, just change them with this compiler statement.
138 | If you dont do that, your results will be messed up.
139 |
140 |
141 | ## Ingame Usage
142 |
143 | 
144 |
145 |
146 | ## More Complex Example
147 |
148 | 
149 |
150 | ## Future features
151 |
152 | Well, i would like to add everything, but here is a good starting selection:
153 |
154 | * More direct assign statements (*=, /=, ^=, ect)
155 | * Allow the import of variable/signal names and aliases from a file.
156 | * IF statements
157 | * Math and Util (e.g. return max or min) library
158 |
159 |
160 | ## Libraries
161 |
162 | I used the awesome [ANTLR4 library](http://www.antlr.org/) to parse the code. Huge thanks to Terence Parr and his tools, without them this would have been a much more cumbersum and timeconsuming project.
163 |
--------------------------------------------------------------------------------
/images/factorioscript.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/un0btanium/FactorioScript/73f5f536cbc0214c986b0fad93f3969a9df9089c/images/factorioscript.png
--------------------------------------------------------------------------------
/images/fscomplex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/un0btanium/FactorioScript/73f5f536cbc0214c986b0fad93f3969a9df9089c/images/fscomplex.png
--------------------------------------------------------------------------------
/images/fstut.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/un0btanium/FactorioScript/73f5f536cbc0214c986b0fad93f3969a9df9089c/images/fstut.png
--------------------------------------------------------------------------------
/lib/antlr-4.7-complete.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/un0btanium/FactorioScript/73f5f536cbc0214c986b0fad93f3969a9df9089c/lib/antlr-4.7-complete.jar
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | factorioscript
5 | factorioscript
6 | 0.1.0
7 | jar
8 |
9 | factorioscript
10 | http://maven.apache.org
11 |
12 |
13 |
14 | UTF-8
15 | 1.8
16 | 1.8
17 |
18 |
19 |
20 | target/generated-sources/antlr4
21 |
22 |
23 | target/generated-sources/antlr4
24 |
25 | **/*.java
26 |
27 |
28 |
29 |
30 |
31 | maven-compiler-plugin
32 | 3.5.1
33 |
34 | 1.8
35 | 1.8
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | junit
44 | junit
45 | 3.8.1
46 | test
47 |
48 |
49 |
50 | com.fasterxml.jackson.core
51 | jackson-databind
52 | 2.8.9
53 |
54 |
55 |
56 | com.fasterxml.jackson.core
57 | jackson-annotations
58 | 2.8.9
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/main/java/antlr/FactorioScriptBaseListener.java:
--------------------------------------------------------------------------------
1 | package antlr;
2 | // Generated from FactorioScript.g4 by ANTLR 4.7
3 |
4 | import org.antlr.v4.runtime.ParserRuleContext;
5 | import org.antlr.v4.runtime.tree.ErrorNode;
6 | import org.antlr.v4.runtime.tree.TerminalNode;
7 |
8 | /**
9 | * This class provides an empty implementation of {@link FactorioScriptListener},
10 | * which can be extended to create a listener which only needs to handle a subset
11 | * of the available methods.
12 | */
13 | public class FactorioScriptBaseListener implements FactorioScriptListener {
14 | /**
15 | * {@inheritDoc}
16 | *
17 | * The default implementation does nothing.
18 | */
19 | @Override public void enterMultipleStatementList(FactorioScriptParser.MultipleStatementListContext ctx) { }
20 | /**
21 | * {@inheritDoc}
22 | *
23 | * The default implementation does nothing.
24 | */
25 | @Override public void exitMultipleStatementList(FactorioScriptParser.MultipleStatementListContext ctx) { }
26 | /**
27 | * {@inheritDoc}
28 | *
29 | * The default implementation does nothing.
30 | */
31 | @Override public void enterSingleStatementList(FactorioScriptParser.SingleStatementListContext ctx) { }
32 | /**
33 | * {@inheritDoc}
34 | *
35 | * The default implementation does nothing.
36 | */
37 | @Override public void exitSingleStatementList(FactorioScriptParser.SingleStatementListContext ctx) { }
38 | /**
39 | * {@inheritDoc}
40 | *
41 | * The default implementation does nothing.
42 | */
43 | @Override public void enterStatement(FactorioScriptParser.StatementContext ctx) { }
44 | /**
45 | * {@inheritDoc}
46 | *
47 | * The default implementation does nothing.
48 | */
49 | @Override public void exitStatement(FactorioScriptParser.StatementContext ctx) { }
50 | /**
51 | * {@inheritDoc}
52 | *
53 | * The default implementation does nothing.
54 | */
55 | @Override public void enterCompilerStandard(FactorioScriptParser.CompilerStandardContext ctx) { }
56 | /**
57 | * {@inheritDoc}
58 | *
59 | * The default implementation does nothing.
60 | */
61 | @Override public void exitCompilerStandard(FactorioScriptParser.CompilerStandardContext ctx) { }
62 | /**
63 | * {@inheritDoc}
64 | *
65 | * The default implementation does nothing.
66 | */
67 | @Override public void enterCompilerAlias(FactorioScriptParser.CompilerAliasContext ctx) { }
68 | /**
69 | * {@inheritDoc}
70 | *
71 | * The default implementation does nothing.
72 | */
73 | @Override public void exitCompilerAlias(FactorioScriptParser.CompilerAliasContext ctx) { }
74 | /**
75 | * {@inheritDoc}
76 | *
77 | * The default implementation does nothing.
78 | */
79 | @Override public void enterCompilerPowerpole(FactorioScriptParser.CompilerPowerpoleContext ctx) { }
80 | /**
81 | * {@inheritDoc}
82 | *
83 | * The default implementation does nothing.
84 | */
85 | @Override public void exitCompilerPowerpole(FactorioScriptParser.CompilerPowerpoleContext ctx) { }
86 | /**
87 | * {@inheritDoc}
88 | *
89 | * The default implementation does nothing.
90 | */
91 | @Override public void enterOverwriteStatementAssign(FactorioScriptParser.OverwriteStatementAssignContext ctx) { }
92 | /**
93 | * {@inheritDoc}
94 | *
95 | * The default implementation does nothing.
96 | */
97 | @Override public void exitOverwriteStatementAssign(FactorioScriptParser.OverwriteStatementAssignContext ctx) { }
98 | /**
99 | * {@inheritDoc}
100 | *
101 | * The default implementation does nothing.
102 | */
103 | @Override public void enterAddStatementAssign(FactorioScriptParser.AddStatementAssignContext ctx) { }
104 | /**
105 | * {@inheritDoc}
106 | *
107 | * The default implementation does nothing.
108 | */
109 | @Override public void exitAddStatementAssign(FactorioScriptParser.AddStatementAssignContext ctx) { }
110 | /**
111 | * {@inheritDoc}
112 | *
113 | * The default implementation does nothing.
114 | */
115 | @Override public void enterSubStatementAssign(FactorioScriptParser.SubStatementAssignContext ctx) { }
116 | /**
117 | * {@inheritDoc}
118 | *
119 | * The default implementation does nothing.
120 | */
121 | @Override public void exitSubStatementAssign(FactorioScriptParser.SubStatementAssignContext ctx) { }
122 | /**
123 | * {@inheritDoc}
124 | *
125 | * The default implementation does nothing.
126 | */
127 | @Override public void enterIfElseIfElseStatement(FactorioScriptParser.IfElseIfElseStatementContext ctx) { }
128 | /**
129 | * {@inheritDoc}
130 | *
131 | * The default implementation does nothing.
132 | */
133 | @Override public void exitIfElseIfElseStatement(FactorioScriptParser.IfElseIfElseStatementContext ctx) { }
134 | /**
135 | * {@inheritDoc}
136 | *
137 | * The default implementation does nothing.
138 | */
139 | @Override public void enterIfElseStatement(FactorioScriptParser.IfElseStatementContext ctx) { }
140 | /**
141 | * {@inheritDoc}
142 | *
143 | * The default implementation does nothing.
144 | */
145 | @Override public void exitIfElseStatement(FactorioScriptParser.IfElseStatementContext ctx) { }
146 | /**
147 | * {@inheritDoc}
148 | *
149 | * The default implementation does nothing.
150 | */
151 | @Override public void enterIfStatement(FactorioScriptParser.IfStatementContext ctx) { }
152 | /**
153 | * {@inheritDoc}
154 | *
155 | * The default implementation does nothing.
156 | */
157 | @Override public void exitIfStatement(FactorioScriptParser.IfStatementContext ctx) { }
158 | /**
159 | * {@inheritDoc}
160 | *
161 | * The default implementation does nothing.
162 | */
163 | @Override public void enterVarExp(FactorioScriptParser.VarExpContext ctx) { }
164 | /**
165 | * {@inheritDoc}
166 | *
167 | * The default implementation does nothing.
168 | */
169 | @Override public void exitVarExp(FactorioScriptParser.VarExpContext ctx) { }
170 | /**
171 | * {@inheritDoc}
172 | *
173 | * The default implementation does nothing.
174 | */
175 | @Override public void enterMulDivModExp(FactorioScriptParser.MulDivModExpContext ctx) { }
176 | /**
177 | * {@inheritDoc}
178 | *
179 | * The default implementation does nothing.
180 | */
181 | @Override public void exitMulDivModExp(FactorioScriptParser.MulDivModExpContext ctx) { }
182 | /**
183 | * {@inheritDoc}
184 | *
185 | * The default implementation does nothing.
186 | */
187 | @Override public void enterPowExp(FactorioScriptParser.PowExpContext ctx) { }
188 | /**
189 | * {@inheritDoc}
190 | *
191 | * The default implementation does nothing.
192 | */
193 | @Override public void exitPowExp(FactorioScriptParser.PowExpContext ctx) { }
194 | /**
195 | * {@inheritDoc}
196 | *
197 | * The default implementation does nothing.
198 | */
199 | @Override public void enterBitExp(FactorioScriptParser.BitExpContext ctx) { }
200 | /**
201 | * {@inheritDoc}
202 | *
203 | * The default implementation does nothing.
204 | */
205 | @Override public void exitBitExp(FactorioScriptParser.BitExpContext ctx) { }
206 | /**
207 | * {@inheritDoc}
208 | *
209 | * The default implementation does nothing.
210 | */
211 | @Override public void enterPriorityExp(FactorioScriptParser.PriorityExpContext ctx) { }
212 | /**
213 | * {@inheritDoc}
214 | *
215 | * The default implementation does nothing.
216 | */
217 | @Override public void exitPriorityExp(FactorioScriptParser.PriorityExpContext ctx) { }
218 | /**
219 | * {@inheritDoc}
220 | *
221 | * The default implementation does nothing.
222 | */
223 | @Override public void enterAddSubExp(FactorioScriptParser.AddSubExpContext ctx) { }
224 | /**
225 | * {@inheritDoc}
226 | *
227 | * The default implementation does nothing.
228 | */
229 | @Override public void exitAddSubExp(FactorioScriptParser.AddSubExpContext ctx) { }
230 | /**
231 | * {@inheritDoc}
232 | *
233 | * The default implementation does nothing.
234 | */
235 | @Override public void enterNumExp(FactorioScriptParser.NumExpContext ctx) { }
236 | /**
237 | * {@inheritDoc}
238 | *
239 | * The default implementation does nothing.
240 | */
241 | @Override public void exitNumExp(FactorioScriptParser.NumExpContext ctx) { }
242 | /**
243 | * {@inheritDoc}
244 | *
245 | * The default implementation does nothing.
246 | */
247 | @Override public void enterCondition(FactorioScriptParser.ConditionContext ctx) { }
248 | /**
249 | * {@inheritDoc}
250 | *
251 | * The default implementation does nothing.
252 | */
253 | @Override public void exitCondition(FactorioScriptParser.ConditionContext ctx) { }
254 |
255 | /**
256 | * {@inheritDoc}
257 | *
258 | * The default implementation does nothing.
259 | */
260 | @Override public void enterEveryRule(ParserRuleContext ctx) { }
261 | /**
262 | * {@inheritDoc}
263 | *
264 | * The default implementation does nothing.
265 | */
266 | @Override public void exitEveryRule(ParserRuleContext ctx) { }
267 | /**
268 | * {@inheritDoc}
269 | *
270 | * The default implementation does nothing.
271 | */
272 | @Override public void visitTerminal(TerminalNode node) { }
273 | /**
274 | * {@inheritDoc}
275 | *
276 | * The default implementation does nothing.
277 | */
278 | @Override public void visitErrorNode(ErrorNode node) { }
279 | }
--------------------------------------------------------------------------------
/src/main/java/antlr/FactorioScriptBaseVisitor.java:
--------------------------------------------------------------------------------
1 | package antlr;
2 | // Generated from FactorioScript.g4 by ANTLR 4.7
3 | import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
4 |
5 | /**
6 | * This class provides an empty implementation of {@link FactorioScriptVisitor},
7 | * which can be extended to create a visitor which only needs to handle a subset
8 | * of the available methods.
9 | *
10 | * @param The return type of the visit operation. Use {@link Void} for
11 | * operations with no return type.
12 | */
13 | public class FactorioScriptBaseVisitor extends AbstractParseTreeVisitor implements FactorioScriptVisitor {
14 | /**
15 | * {@inheritDoc}
16 | *
17 | * The default implementation returns the result of calling
18 | * {@link #visitChildren} on {@code ctx}.
19 | */
20 | @Override public T visitMultipleStatementList(FactorioScriptParser.MultipleStatementListContext ctx) { return visitChildren(ctx); }
21 | /**
22 | * {@inheritDoc}
23 | *
24 | * The default implementation returns the result of calling
25 | * {@link #visitChildren} on {@code ctx}.
26 | */
27 | @Override public T visitSingleStatementList(FactorioScriptParser.SingleStatementListContext ctx) { return visitChildren(ctx); }
28 | /**
29 | * {@inheritDoc}
30 | *
31 | * The default implementation returns the result of calling
32 | * {@link #visitChildren} on {@code ctx}.
33 | */
34 | @Override public T visitStatement(FactorioScriptParser.StatementContext ctx) { return visitChildren(ctx); }
35 | /**
36 | * {@inheritDoc}
37 | *
38 | * The default implementation returns the result of calling
39 | * {@link #visitChildren} on {@code ctx}.
40 | */
41 | @Override public T visitCompilerStandard(FactorioScriptParser.CompilerStandardContext ctx) { return visitChildren(ctx); }
42 | /**
43 | * {@inheritDoc}
44 | *
45 | * The default implementation returns the result of calling
46 | * {@link #visitChildren} on {@code ctx}.
47 | */
48 | @Override public T visitCompilerAlias(FactorioScriptParser.CompilerAliasContext ctx) { return visitChildren(ctx); }
49 | /**
50 | * {@inheritDoc}
51 | *
52 | * The default implementation returns the result of calling
53 | * {@link #visitChildren} on {@code ctx}.
54 | */
55 | @Override public T visitCompilerPowerpole(FactorioScriptParser.CompilerPowerpoleContext ctx) { return visitChildren(ctx); }
56 | /**
57 | * {@inheritDoc}
58 | *
59 | * The default implementation returns the result of calling
60 | * {@link #visitChildren} on {@code ctx}.
61 | */
62 | @Override public T visitOverwriteStatementAssign(FactorioScriptParser.OverwriteStatementAssignContext ctx) { return visitChildren(ctx); }
63 | /**
64 | * {@inheritDoc}
65 | *
66 | * The default implementation returns the result of calling
67 | * {@link #visitChildren} on {@code ctx}.
68 | */
69 | @Override public T visitAddStatementAssign(FactorioScriptParser.AddStatementAssignContext ctx) { return visitChildren(ctx); }
70 | /**
71 | * {@inheritDoc}
72 | *
73 | * The default implementation returns the result of calling
74 | * {@link #visitChildren} on {@code ctx}.
75 | */
76 | @Override public T visitSubStatementAssign(FactorioScriptParser.SubStatementAssignContext ctx) { return visitChildren(ctx); }
77 | /**
78 | * {@inheritDoc}
79 | *
80 | * The default implementation returns the result of calling
81 | * {@link #visitChildren} on {@code ctx}.
82 | */
83 | @Override public T visitIfElseIfElseStatement(FactorioScriptParser.IfElseIfElseStatementContext ctx) { return visitChildren(ctx); }
84 | /**
85 | * {@inheritDoc}
86 | *
87 | * The default implementation returns the result of calling
88 | * {@link #visitChildren} on {@code ctx}.
89 | */
90 | @Override public T visitIfElseStatement(FactorioScriptParser.IfElseStatementContext ctx) { return visitChildren(ctx); }
91 | /**
92 | * {@inheritDoc}
93 | *
94 | * The default implementation returns the result of calling
95 | * {@link #visitChildren} on {@code ctx}.
96 | */
97 | @Override public T visitIfStatement(FactorioScriptParser.IfStatementContext ctx) { return visitChildren(ctx); }
98 | /**
99 | * {@inheritDoc}
100 | *
101 | * The default implementation returns the result of calling
102 | * {@link #visitChildren} on {@code ctx}.
103 | */
104 | @Override public T visitVarExp(FactorioScriptParser.VarExpContext ctx) { return visitChildren(ctx); }
105 | /**
106 | * {@inheritDoc}
107 | *
108 | * The default implementation returns the result of calling
109 | * {@link #visitChildren} on {@code ctx}.
110 | */
111 | @Override public T visitMulDivModExp(FactorioScriptParser.MulDivModExpContext ctx) { return visitChildren(ctx); }
112 | /**
113 | * {@inheritDoc}
114 | *
115 | * The default implementation returns the result of calling
116 | * {@link #visitChildren} on {@code ctx}.
117 | */
118 | @Override public T visitPowExp(FactorioScriptParser.PowExpContext ctx) { return visitChildren(ctx); }
119 | /**
120 | * {@inheritDoc}
121 | *
122 | * The default implementation returns the result of calling
123 | * {@link #visitChildren} on {@code ctx}.
124 | */
125 | @Override public T visitBitExp(FactorioScriptParser.BitExpContext ctx) { return visitChildren(ctx); }
126 | /**
127 | * {@inheritDoc}
128 | *
129 | * The default implementation returns the result of calling
130 | * {@link #visitChildren} on {@code ctx}.
131 | */
132 | @Override public T visitPriorityExp(FactorioScriptParser.PriorityExpContext ctx) { return visitChildren(ctx); }
133 | /**
134 | * {@inheritDoc}
135 | *
136 | * The default implementation returns the result of calling
137 | * {@link #visitChildren} on {@code ctx}.
138 | */
139 | @Override public T visitAddSubExp(FactorioScriptParser.AddSubExpContext ctx) { return visitChildren(ctx); }
140 | /**
141 | * {@inheritDoc}
142 | *
143 | * The default implementation returns the result of calling
144 | * {@link #visitChildren} on {@code ctx}.
145 | */
146 | @Override public T visitNumExp(FactorioScriptParser.NumExpContext ctx) { return visitChildren(ctx); }
147 | /**
148 | * {@inheritDoc}
149 | *
150 | * The default implementation returns the result of calling
151 | * {@link #visitChildren} on {@code ctx}.
152 | */
153 | @Override public T visitCondition(FactorioScriptParser.ConditionContext ctx) { return visitChildren(ctx); }
154 | }
--------------------------------------------------------------------------------
/src/main/java/antlr/FactorioScriptLexer.java:
--------------------------------------------------------------------------------
1 | package antlr;
2 | // Generated from FactorioScript.g4 by ANTLR 4.7
3 | import org.antlr.v4.runtime.Lexer;
4 | import org.antlr.v4.runtime.CharStream;
5 | import org.antlr.v4.runtime.Token;
6 | import org.antlr.v4.runtime.TokenStream;
7 | import org.antlr.v4.runtime.*;
8 | import org.antlr.v4.runtime.atn.*;
9 | import org.antlr.v4.runtime.dfa.DFA;
10 | import org.antlr.v4.runtime.misc.*;
11 |
12 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
13 | public class FactorioScriptLexer extends Lexer {
14 | static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
15 |
16 | protected static final DFA[] _decisionToDFA;
17 | protected static final PredictionContextCache _sharedContextCache =
18 | new PredictionContextCache();
19 | public static final int
20 | COMPILERSIGN=1, STANDARD=2, ALIAS=3, ALIASASSIGN=4, POWERPOLE=5, SMALL=6,
21 | MEDIUM=7, SUBSTATION=8, IF=9, ELSEIF=10, ELSE=11, BRACKET_OPEN=12, BRACKET_CLOSE=13,
22 | BRACE_OPEN=14, BRACE_CLOSE=15, ASTERISK=16, SLASH=17, MODULO=18, PLUS=19,
23 | MINUS=20, BIT_LEFT=21, BIT_RIGHT=22, BIT_AND=23, BIT_OR=24, BIT_XOR=25,
24 | POWER=26, EQUAL=27, NOTEQUAL=28, GREATER=29, LOWER=30, GREATEREQUAL=31,
25 | LOWEREQUAL=32, ASSIGN=33, NUMBER=34, VAR=35, WS=36;
26 | public static String[] channelNames = {
27 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN"
28 | };
29 |
30 | public static String[] modeNames = {
31 | "DEFAULT_MODE"
32 | };
33 |
34 | public static final String[] ruleNames = {
35 | "COMPILERSIGN", "STANDARD", "ALIAS", "ALIASASSIGN", "POWERPOLE", "SMALL",
36 | "MEDIUM", "SUBSTATION", "IF", "ELSEIF", "ELSE", "BRACKET_OPEN", "BRACKET_CLOSE",
37 | "BRACE_OPEN", "BRACE_CLOSE", "ASTERISK", "SLASH", "MODULO", "PLUS", "MINUS",
38 | "BIT_LEFT", "BIT_RIGHT", "BIT_AND", "BIT_OR", "BIT_XOR", "POWER", "EQUAL",
39 | "NOTEQUAL", "GREATER", "LOWER", "GREATEREQUAL", "LOWEREQUAL", "ASSIGN",
40 | "NUMBER", "VAR", "WS"
41 | };
42 |
43 | private static final String[] _LITERAL_NAMES = {
44 | null, "'#'", null, null, "'=>'", null, null, null, null, null, null, null,
45 | "'('", "')'", "'{'", "'}'", "'*'", "'/'", "'%'", "'+'", "'-'", "'<<'",
46 | "'>>'", "'AND'", "'OR'", "'XOR'", "'^'", "'=='", "'!='", "'>'", "'<'",
47 | "'>='", "'<='", "'='"
48 | };
49 | private static final String[] _SYMBOLIC_NAMES = {
50 | null, "COMPILERSIGN", "STANDARD", "ALIAS", "ALIASASSIGN", "POWERPOLE",
51 | "SMALL", "MEDIUM", "SUBSTATION", "IF", "ELSEIF", "ELSE", "BRACKET_OPEN",
52 | "BRACKET_CLOSE", "BRACE_OPEN", "BRACE_CLOSE", "ASTERISK", "SLASH", "MODULO",
53 | "PLUS", "MINUS", "BIT_LEFT", "BIT_RIGHT", "BIT_AND", "BIT_OR", "BIT_XOR",
54 | "POWER", "EQUAL", "NOTEQUAL", "GREATER", "LOWER", "GREATEREQUAL", "LOWEREQUAL",
55 | "ASSIGN", "NUMBER", "VAR", "WS"
56 | };
57 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
58 |
59 | /**
60 | * @deprecated Use {@link #VOCABULARY} instead.
61 | */
62 | @Deprecated
63 | public static final String[] tokenNames;
64 | static {
65 | tokenNames = new String[_SYMBOLIC_NAMES.length];
66 | for (int i = 0; i < tokenNames.length; i++) {
67 | tokenNames[i] = VOCABULARY.getLiteralName(i);
68 | if (tokenNames[i] == null) {
69 | tokenNames[i] = VOCABULARY.getSymbolicName(i);
70 | }
71 |
72 | if (tokenNames[i] == null) {
73 | tokenNames[i] = "";
74 | }
75 | }
76 | }
77 |
78 | @Override
79 | @Deprecated
80 | public String[] getTokenNames() {
81 | return tokenNames;
82 | }
83 |
84 | @Override
85 |
86 | public Vocabulary getVocabulary() {
87 | return VOCABULARY;
88 | }
89 |
90 |
91 | public FactorioScriptLexer(CharStream input) {
92 | super(input);
93 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
94 | }
95 |
96 | @Override
97 | public String getGrammarFileName() { return "FactorioScript.g4"; }
98 |
99 | @Override
100 | public String[] getRuleNames() { return ruleNames; }
101 |
102 | @Override
103 | public String getSerializedATN() { return _serializedATN; }
104 |
105 | @Override
106 | public String[] getChannelNames() { return channelNames; }
107 |
108 | @Override
109 | public String[] getModeNames() { return modeNames; }
110 |
111 | @Override
112 | public ATN getATN() { return _ATN; }
113 |
114 | public static final String _serializedATN =
115 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2&\u011a\b\1\4\2\t"+
116 | "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+
117 | "\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22"+
118 | "\4\23\t\23\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31\t\31"+
119 | "\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36\4\37\t\37\4 \t \4!"+
120 | "\t!\4\"\t\"\4#\t#\4$\t$\4%\t%\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3"+
121 | "\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\5\3^\n\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4"+
122 | "\3\4\3\4\3\4\5\4j\n\4\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6"+
123 | "\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\5\6\u0081\n\6\3\7\3\7\3\7\3\7\3\7"+
124 | "\3\7\3\7\3\7\3\7\3\7\5\7\u008d\n\7\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b"+
125 | "\3\b\3\b\3\b\5\b\u009b\n\b\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t"+
126 | "\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\3\t\5\t\u00b1\n\t\3\n\3\n\3\n\3\n\5\n"+
127 | "\u00b7\n\n\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13\3\13"+
128 | "\5\13\u00c5\n\13\3\f\3\f\3\f\3\f\3\f\3\f\3\f\3\f\5\f\u00cf\n\f\3\r\3\r"+
129 | "\3\16\3\16\3\17\3\17\3\20\3\20\3\21\3\21\3\22\3\22\3\23\3\23\3\24\3\24"+
130 | "\3\25\3\25\3\26\3\26\3\26\3\27\3\27\3\27\3\30\3\30\3\30\3\30\3\31\3\31"+
131 | "\3\31\3\32\3\32\3\32\3\32\3\33\3\33\3\34\3\34\3\34\3\35\3\35\3\35\3\36"+
132 | "\3\36\3\37\3\37\3 \3 \3 \3!\3!\3!\3\"\3\"\3#\6#\u0109\n#\r#\16#\u010a"+
133 | "\3$\3$\7$\u010f\n$\f$\16$\u0112\13$\3%\6%\u0115\n%\r%\16%\u0116\3%\3%"+
134 | "\2\2&\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r\31\16\33\17\35"+
135 | "\20\37\21!\22#\23%\24\'\25)\26+\27-\30/\31\61\32\63\33\65\34\67\359\36"+
136 | ";\37= ?!A\"C#E$G%I&\3\2\6\3\2\62;\3\2c|\6\2//\62;C\\c|\5\2\13\f\17\17"+
137 | "\"\"\2\u0125\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2"+
138 | "\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2"+
139 | "\27\3\2\2\2\2\31\3\2\2\2\2\33\3\2\2\2\2\35\3\2\2\2\2\37\3\2\2\2\2!\3\2"+
140 | "\2\2\2#\3\2\2\2\2%\3\2\2\2\2\'\3\2\2\2\2)\3\2\2\2\2+\3\2\2\2\2-\3\2\2"+
141 | "\2\2/\3\2\2\2\2\61\3\2\2\2\2\63\3\2\2\2\2\65\3\2\2\2\2\67\3\2\2\2\29\3"+
142 | "\2\2\2\2;\3\2\2\2\2=\3\2\2\2\2?\3\2\2\2\2A\3\2\2\2\2C\3\2\2\2\2E\3\2\2"+
143 | "\2\2G\3\2\2\2\2I\3\2\2\2\3K\3\2\2\2\5]\3\2\2\2\7i\3\2\2\2\tk\3\2\2\2\13"+
144 | "\u0080\3\2\2\2\r\u008c\3\2\2\2\17\u009a\3\2\2\2\21\u00b0\3\2\2\2\23\u00b6"+
145 | "\3\2\2\2\25\u00c4\3\2\2\2\27\u00ce\3\2\2\2\31\u00d0\3\2\2\2\33\u00d2\3"+
146 | "\2\2\2\35\u00d4\3\2\2\2\37\u00d6\3\2\2\2!\u00d8\3\2\2\2#\u00da\3\2\2\2"+
147 | "%\u00dc\3\2\2\2\'\u00de\3\2\2\2)\u00e0\3\2\2\2+\u00e2\3\2\2\2-\u00e5\3"+
148 | "\2\2\2/\u00e8\3\2\2\2\61\u00ec\3\2\2\2\63\u00ef\3\2\2\2\65\u00f3\3\2\2"+
149 | "\2\67\u00f5\3\2\2\29\u00f8\3\2\2\2;\u00fb\3\2\2\2=\u00fd\3\2\2\2?\u00ff"+
150 | "\3\2\2\2A\u0102\3\2\2\2C\u0105\3\2\2\2E\u0108\3\2\2\2G\u010c\3\2\2\2I"+
151 | "\u0114\3\2\2\2KL\7%\2\2L\4\3\2\2\2MN\7u\2\2NO\7v\2\2OP\7c\2\2PQ\7p\2\2"+
152 | "QR\7f\2\2RS\7c\2\2ST\7t\2\2T^\7f\2\2UV\7U\2\2VW\7V\2\2WX\7C\2\2XY\7P\2"+
153 | "\2YZ\7F\2\2Z[\7C\2\2[\\\7T\2\2\\^\7F\2\2]M\3\2\2\2]U\3\2\2\2^\6\3\2\2"+
154 | "\2_`\7c\2\2`a\7n\2\2ab\7k\2\2bc\7c\2\2cj\7u\2\2de\7C\2\2ef\7N\2\2fg\7"+
155 | "K\2\2gh\7C\2\2hj\7U\2\2i_\3\2\2\2id\3\2\2\2j\b\3\2\2\2kl\7?\2\2lm\7@\2"+
156 | "\2m\n\3\2\2\2no\7r\2\2op\7q\2\2pq\7y\2\2qr\7g\2\2rs\7t\2\2st\7r\2\2tu"+
157 | "\7q\2\2uv\7n\2\2v\u0081\7g\2\2wx\7R\2\2xy\7Q\2\2yz\7Y\2\2z{\7G\2\2{|\7"+
158 | "T\2\2|}\7R\2\2}~\7Q\2\2~\177\7N\2\2\177\u0081\7G\2\2\u0080n\3\2\2\2\u0080"+
159 | "w\3\2\2\2\u0081\f\3\2\2\2\u0082\u0083\7u\2\2\u0083\u0084\7o\2\2\u0084"+
160 | "\u0085\7c\2\2\u0085\u0086\7n\2\2\u0086\u008d\7n\2\2\u0087\u0088\7U\2\2"+
161 | "\u0088\u0089\7O\2\2\u0089\u008a\7C\2\2\u008a\u008b\7N\2\2\u008b\u008d"+
162 | "\7N\2\2\u008c\u0082\3\2\2\2\u008c\u0087\3\2\2\2\u008d\16\3\2\2\2\u008e"+
163 | "\u008f\7o\2\2\u008f\u0090\7g\2\2\u0090\u0091\7f\2\2\u0091\u0092\7k\2\2"+
164 | "\u0092\u0093\7w\2\2\u0093\u009b\7o\2\2\u0094\u0095\7O\2\2\u0095\u0096"+
165 | "\7G\2\2\u0096\u0097\7F\2\2\u0097\u0098\7K\2\2\u0098\u0099\7W\2\2\u0099"+
166 | "\u009b\7O\2\2\u009a\u008e\3\2\2\2\u009a\u0094\3\2\2\2\u009b\20\3\2\2\2"+
167 | "\u009c\u009d\7u\2\2\u009d\u009e\7w\2\2\u009e\u009f\7d\2\2\u009f\u00a0"+
168 | "\7u\2\2\u00a0\u00a1\7v\2\2\u00a1\u00a2\7c\2\2\u00a2\u00a3\7v\2\2\u00a3"+
169 | "\u00a4\7k\2\2\u00a4\u00a5\7q\2\2\u00a5\u00b1\7p\2\2\u00a6\u00a7\7U\2\2"+
170 | "\u00a7\u00a8\7W\2\2\u00a8\u00a9\7D\2\2\u00a9\u00aa\7U\2\2\u00aa\u00ab"+
171 | "\7V\2\2\u00ab\u00ac\7C\2\2\u00ac\u00ad\7V\2\2\u00ad\u00ae\7K\2\2\u00ae"+
172 | "\u00af\7Q\2\2\u00af\u00b1\7P\2\2\u00b0\u009c\3\2\2\2\u00b0\u00a6\3\2\2"+
173 | "\2\u00b1\22\3\2\2\2\u00b2\u00b3\7k\2\2\u00b3\u00b7\7h\2\2\u00b4\u00b5"+
174 | "\7K\2\2\u00b5\u00b7\7H\2\2\u00b6\u00b2\3\2\2\2\u00b6\u00b4\3\2\2\2\u00b7"+
175 | "\24\3\2\2\2\u00b8\u00b9\7g\2\2\u00b9\u00ba\7n\2\2\u00ba\u00bb\7u\2\2\u00bb"+
176 | "\u00bc\7g\2\2\u00bc\u00bd\7k\2\2\u00bd\u00c5\7h\2\2\u00be\u00bf\7G\2\2"+
177 | "\u00bf\u00c0\7N\2\2\u00c0\u00c1\7U\2\2\u00c1\u00c2\7G\2\2\u00c2\u00c3"+
178 | "\7K\2\2\u00c3\u00c5\7H\2\2\u00c4\u00b8\3\2\2\2\u00c4\u00be\3\2\2\2\u00c5"+
179 | "\26\3\2\2\2\u00c6\u00c7\7g\2\2\u00c7\u00c8\7n\2\2\u00c8\u00c9\7u\2\2\u00c9"+
180 | "\u00cf\7g\2\2\u00ca\u00cb\7G\2\2\u00cb\u00cc\7N\2\2\u00cc\u00cd\7U\2\2"+
181 | "\u00cd\u00cf\7G\2\2\u00ce\u00c6\3\2\2\2\u00ce\u00ca\3\2\2\2\u00cf\30\3"+
182 | "\2\2\2\u00d0\u00d1\7*\2\2\u00d1\32\3\2\2\2\u00d2\u00d3\7+\2\2\u00d3\34"+
183 | "\3\2\2\2\u00d4\u00d5\7}\2\2\u00d5\36\3\2\2\2\u00d6\u00d7\7\177\2\2\u00d7"+
184 | " \3\2\2\2\u00d8\u00d9\7,\2\2\u00d9\"\3\2\2\2\u00da\u00db\7\61\2\2\u00db"+
185 | "$\3\2\2\2\u00dc\u00dd\7\'\2\2\u00dd&\3\2\2\2\u00de\u00df\7-\2\2\u00df"+
186 | "(\3\2\2\2\u00e0\u00e1\7/\2\2\u00e1*\3\2\2\2\u00e2\u00e3\7>\2\2\u00e3\u00e4"+
187 | "\7>\2\2\u00e4,\3\2\2\2\u00e5\u00e6\7@\2\2\u00e6\u00e7\7@\2\2\u00e7.\3"+
188 | "\2\2\2\u00e8\u00e9\7C\2\2\u00e9\u00ea\7P\2\2\u00ea\u00eb\7F\2\2\u00eb"+
189 | "\60\3\2\2\2\u00ec\u00ed\7Q\2\2\u00ed\u00ee\7T\2\2\u00ee\62\3\2\2\2\u00ef"+
190 | "\u00f0\7Z\2\2\u00f0\u00f1\7Q\2\2\u00f1\u00f2\7T\2\2\u00f2\64\3\2\2\2\u00f3"+
191 | "\u00f4\7`\2\2\u00f4\66\3\2\2\2\u00f5\u00f6\7?\2\2\u00f6\u00f7\7?\2\2\u00f7"+
192 | "8\3\2\2\2\u00f8\u00f9\7#\2\2\u00f9\u00fa\7?\2\2\u00fa:\3\2\2\2\u00fb\u00fc"+
193 | "\7@\2\2\u00fc<\3\2\2\2\u00fd\u00fe\7>\2\2\u00fe>\3\2\2\2\u00ff\u0100\7"+
194 | "@\2\2\u0100\u0101\7?\2\2\u0101@\3\2\2\2\u0102\u0103\7>\2\2\u0103\u0104"+
195 | "\7?\2\2\u0104B\3\2\2\2\u0105\u0106\7?\2\2\u0106D\3\2\2\2\u0107\u0109\t"+
196 | "\2\2\2\u0108\u0107\3\2\2\2\u0109\u010a\3\2\2\2\u010a\u0108\3\2\2\2\u010a"+
197 | "\u010b\3\2\2\2\u010bF\3\2\2\2\u010c\u0110\t\3\2\2\u010d\u010f\t\4\2\2"+
198 | "\u010e\u010d\3\2\2\2\u010f\u0112\3\2\2\2\u0110\u010e\3\2\2\2\u0110\u0111"+
199 | "\3\2\2\2\u0111H\3\2\2\2\u0112\u0110\3\2\2\2\u0113\u0115\t\5\2\2\u0114"+
200 | "\u0113\3\2\2\2\u0115\u0116\3\2\2\2\u0116\u0114\3\2\2\2\u0116\u0117\3\2"+
201 | "\2\2\u0117\u0118\3\2\2\2\u0118\u0119\b%\2\2\u0119J\3\2\2\2\17\2]i\u0080"+
202 | "\u008c\u009a\u00b0\u00b6\u00c4\u00ce\u010a\u0110\u0116\3\b\2\2";
203 | public static final ATN _ATN =
204 | new ATNDeserializer().deserialize(_serializedATN.toCharArray());
205 | static {
206 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
207 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
208 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
209 | }
210 | }
211 | }
--------------------------------------------------------------------------------
/src/main/java/antlr/FactorioScriptListener.java:
--------------------------------------------------------------------------------
1 | package antlr;
2 | // Generated from FactorioScript.g4 by ANTLR 4.7
3 | import org.antlr.v4.runtime.tree.ParseTreeListener;
4 |
5 | /**
6 | * This interface defines a complete listener for a parse tree produced by
7 | * {@link FactorioScriptParser}.
8 | */
9 | public interface FactorioScriptListener extends ParseTreeListener {
10 | /**
11 | * Enter a parse tree produced by the {@code multipleStatementList}
12 | * labeled alternative in {@link FactorioScriptParser#statementList}.
13 | * @param ctx the parse tree
14 | */
15 | void enterMultipleStatementList(FactorioScriptParser.MultipleStatementListContext ctx);
16 | /**
17 | * Exit a parse tree produced by the {@code multipleStatementList}
18 | * labeled alternative in {@link FactorioScriptParser#statementList}.
19 | * @param ctx the parse tree
20 | */
21 | void exitMultipleStatementList(FactorioScriptParser.MultipleStatementListContext ctx);
22 | /**
23 | * Enter a parse tree produced by the {@code singleStatementList}
24 | * labeled alternative in {@link FactorioScriptParser#statementList}.
25 | * @param ctx the parse tree
26 | */
27 | void enterSingleStatementList(FactorioScriptParser.SingleStatementListContext ctx);
28 | /**
29 | * Exit a parse tree produced by the {@code singleStatementList}
30 | * labeled alternative in {@link FactorioScriptParser#statementList}.
31 | * @param ctx the parse tree
32 | */
33 | void exitSingleStatementList(FactorioScriptParser.SingleStatementListContext ctx);
34 | /**
35 | * Enter a parse tree produced by {@link FactorioScriptParser#statement}.
36 | * @param ctx the parse tree
37 | */
38 | void enterStatement(FactorioScriptParser.StatementContext ctx);
39 | /**
40 | * Exit a parse tree produced by {@link FactorioScriptParser#statement}.
41 | * @param ctx the parse tree
42 | */
43 | void exitStatement(FactorioScriptParser.StatementContext ctx);
44 | /**
45 | * Enter a parse tree produced by the {@code CompilerStandard}
46 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
47 | * @param ctx the parse tree
48 | */
49 | void enterCompilerStandard(FactorioScriptParser.CompilerStandardContext ctx);
50 | /**
51 | * Exit a parse tree produced by the {@code CompilerStandard}
52 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
53 | * @param ctx the parse tree
54 | */
55 | void exitCompilerStandard(FactorioScriptParser.CompilerStandardContext ctx);
56 | /**
57 | * Enter a parse tree produced by the {@code CompilerAlias}
58 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
59 | * @param ctx the parse tree
60 | */
61 | void enterCompilerAlias(FactorioScriptParser.CompilerAliasContext ctx);
62 | /**
63 | * Exit a parse tree produced by the {@code CompilerAlias}
64 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
65 | * @param ctx the parse tree
66 | */
67 | void exitCompilerAlias(FactorioScriptParser.CompilerAliasContext ctx);
68 | /**
69 | * Enter a parse tree produced by the {@code CompilerPowerpole}
70 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
71 | * @param ctx the parse tree
72 | */
73 | void enterCompilerPowerpole(FactorioScriptParser.CompilerPowerpoleContext ctx);
74 | /**
75 | * Exit a parse tree produced by the {@code CompilerPowerpole}
76 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
77 | * @param ctx the parse tree
78 | */
79 | void exitCompilerPowerpole(FactorioScriptParser.CompilerPowerpoleContext ctx);
80 | /**
81 | * Enter a parse tree produced by the {@code overwriteStatementAssign}
82 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
83 | * @param ctx the parse tree
84 | */
85 | void enterOverwriteStatementAssign(FactorioScriptParser.OverwriteStatementAssignContext ctx);
86 | /**
87 | * Exit a parse tree produced by the {@code overwriteStatementAssign}
88 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
89 | * @param ctx the parse tree
90 | */
91 | void exitOverwriteStatementAssign(FactorioScriptParser.OverwriteStatementAssignContext ctx);
92 | /**
93 | * Enter a parse tree produced by the {@code addStatementAssign}
94 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
95 | * @param ctx the parse tree
96 | */
97 | void enterAddStatementAssign(FactorioScriptParser.AddStatementAssignContext ctx);
98 | /**
99 | * Exit a parse tree produced by the {@code addStatementAssign}
100 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
101 | * @param ctx the parse tree
102 | */
103 | void exitAddStatementAssign(FactorioScriptParser.AddStatementAssignContext ctx);
104 | /**
105 | * Enter a parse tree produced by the {@code subStatementAssign}
106 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
107 | * @param ctx the parse tree
108 | */
109 | void enterSubStatementAssign(FactorioScriptParser.SubStatementAssignContext ctx);
110 | /**
111 | * Exit a parse tree produced by the {@code subStatementAssign}
112 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
113 | * @param ctx the parse tree
114 | */
115 | void exitSubStatementAssign(FactorioScriptParser.SubStatementAssignContext ctx);
116 | /**
117 | * Enter a parse tree produced by the {@code ifElseIfElseStatement}
118 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
119 | * @param ctx the parse tree
120 | */
121 | void enterIfElseIfElseStatement(FactorioScriptParser.IfElseIfElseStatementContext ctx);
122 | /**
123 | * Exit a parse tree produced by the {@code ifElseIfElseStatement}
124 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
125 | * @param ctx the parse tree
126 | */
127 | void exitIfElseIfElseStatement(FactorioScriptParser.IfElseIfElseStatementContext ctx);
128 | /**
129 | * Enter a parse tree produced by the {@code ifElseStatement}
130 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
131 | * @param ctx the parse tree
132 | */
133 | void enterIfElseStatement(FactorioScriptParser.IfElseStatementContext ctx);
134 | /**
135 | * Exit a parse tree produced by the {@code ifElseStatement}
136 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
137 | * @param ctx the parse tree
138 | */
139 | void exitIfElseStatement(FactorioScriptParser.IfElseStatementContext ctx);
140 | /**
141 | * Enter a parse tree produced by the {@code ifStatement}
142 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
143 | * @param ctx the parse tree
144 | */
145 | void enterIfStatement(FactorioScriptParser.IfStatementContext ctx);
146 | /**
147 | * Exit a parse tree produced by the {@code ifStatement}
148 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
149 | * @param ctx the parse tree
150 | */
151 | void exitIfStatement(FactorioScriptParser.IfStatementContext ctx);
152 | /**
153 | * Enter a parse tree produced by the {@code varExp}
154 | * labeled alternative in {@link FactorioScriptParser#expression}.
155 | * @param ctx the parse tree
156 | */
157 | void enterVarExp(FactorioScriptParser.VarExpContext ctx);
158 | /**
159 | * Exit a parse tree produced by the {@code varExp}
160 | * labeled alternative in {@link FactorioScriptParser#expression}.
161 | * @param ctx the parse tree
162 | */
163 | void exitVarExp(FactorioScriptParser.VarExpContext ctx);
164 | /**
165 | * Enter a parse tree produced by the {@code mulDivModExp}
166 | * labeled alternative in {@link FactorioScriptParser#expression}.
167 | * @param ctx the parse tree
168 | */
169 | void enterMulDivModExp(FactorioScriptParser.MulDivModExpContext ctx);
170 | /**
171 | * Exit a parse tree produced by the {@code mulDivModExp}
172 | * labeled alternative in {@link FactorioScriptParser#expression}.
173 | * @param ctx the parse tree
174 | */
175 | void exitMulDivModExp(FactorioScriptParser.MulDivModExpContext ctx);
176 | /**
177 | * Enter a parse tree produced by the {@code powExp}
178 | * labeled alternative in {@link FactorioScriptParser#expression}.
179 | * @param ctx the parse tree
180 | */
181 | void enterPowExp(FactorioScriptParser.PowExpContext ctx);
182 | /**
183 | * Exit a parse tree produced by the {@code powExp}
184 | * labeled alternative in {@link FactorioScriptParser#expression}.
185 | * @param ctx the parse tree
186 | */
187 | void exitPowExp(FactorioScriptParser.PowExpContext ctx);
188 | /**
189 | * Enter a parse tree produced by the {@code bitExp}
190 | * labeled alternative in {@link FactorioScriptParser#expression}.
191 | * @param ctx the parse tree
192 | */
193 | void enterBitExp(FactorioScriptParser.BitExpContext ctx);
194 | /**
195 | * Exit a parse tree produced by the {@code bitExp}
196 | * labeled alternative in {@link FactorioScriptParser#expression}.
197 | * @param ctx the parse tree
198 | */
199 | void exitBitExp(FactorioScriptParser.BitExpContext ctx);
200 | /**
201 | * Enter a parse tree produced by the {@code priorityExp}
202 | * labeled alternative in {@link FactorioScriptParser#expression}.
203 | * @param ctx the parse tree
204 | */
205 | void enterPriorityExp(FactorioScriptParser.PriorityExpContext ctx);
206 | /**
207 | * Exit a parse tree produced by the {@code priorityExp}
208 | * labeled alternative in {@link FactorioScriptParser#expression}.
209 | * @param ctx the parse tree
210 | */
211 | void exitPriorityExp(FactorioScriptParser.PriorityExpContext ctx);
212 | /**
213 | * Enter a parse tree produced by the {@code addSubExp}
214 | * labeled alternative in {@link FactorioScriptParser#expression}.
215 | * @param ctx the parse tree
216 | */
217 | void enterAddSubExp(FactorioScriptParser.AddSubExpContext ctx);
218 | /**
219 | * Exit a parse tree produced by the {@code addSubExp}
220 | * labeled alternative in {@link FactorioScriptParser#expression}.
221 | * @param ctx the parse tree
222 | */
223 | void exitAddSubExp(FactorioScriptParser.AddSubExpContext ctx);
224 | /**
225 | * Enter a parse tree produced by the {@code numExp}
226 | * labeled alternative in {@link FactorioScriptParser#expression}.
227 | * @param ctx the parse tree
228 | */
229 | void enterNumExp(FactorioScriptParser.NumExpContext ctx);
230 | /**
231 | * Exit a parse tree produced by the {@code numExp}
232 | * labeled alternative in {@link FactorioScriptParser#expression}.
233 | * @param ctx the parse tree
234 | */
235 | void exitNumExp(FactorioScriptParser.NumExpContext ctx);
236 | /**
237 | * Enter a parse tree produced by {@link FactorioScriptParser#condition}.
238 | * @param ctx the parse tree
239 | */
240 | void enterCondition(FactorioScriptParser.ConditionContext ctx);
241 | /**
242 | * Exit a parse tree produced by {@link FactorioScriptParser#condition}.
243 | * @param ctx the parse tree
244 | */
245 | void exitCondition(FactorioScriptParser.ConditionContext ctx);
246 | }
--------------------------------------------------------------------------------
/src/main/java/antlr/FactorioScriptParser.java:
--------------------------------------------------------------------------------
1 | package antlr;
2 | // Generated from FactorioScript.g4 by ANTLR 4.7
3 | import org.antlr.v4.runtime.atn.*;
4 | import org.antlr.v4.runtime.dfa.DFA;
5 | import org.antlr.v4.runtime.*;
6 | import org.antlr.v4.runtime.misc.*;
7 | import org.antlr.v4.runtime.tree.*;
8 | import java.util.List;
9 | import java.util.Iterator;
10 | import java.util.ArrayList;
11 |
12 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
13 | public class FactorioScriptParser extends Parser {
14 | static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
15 |
16 | protected static final DFA[] _decisionToDFA;
17 | protected static final PredictionContextCache _sharedContextCache =
18 | new PredictionContextCache();
19 | public static final int
20 | COMPILERSIGN=1, STANDARD=2, ALIAS=3, ALIASASSIGN=4, POWERPOLE=5, SMALL=6,
21 | MEDIUM=7, SUBSTATION=8, IF=9, ELSEIF=10, ELSE=11, BRACKET_OPEN=12, BRACKET_CLOSE=13,
22 | BRACE_OPEN=14, BRACE_CLOSE=15, ASTERISK=16, SLASH=17, MODULO=18, PLUS=19,
23 | MINUS=20, BIT_LEFT=21, BIT_RIGHT=22, BIT_AND=23, BIT_OR=24, BIT_XOR=25,
24 | POWER=26, EQUAL=27, NOTEQUAL=28, GREATER=29, LOWER=30, GREATEREQUAL=31,
25 | LOWEREQUAL=32, ASSIGN=33, NUMBER=34, VAR=35, WS=36;
26 | public static final int
27 | RULE_statementList = 0, RULE_statement = 1, RULE_statementCompiler = 2,
28 | RULE_statementAssign = 3, RULE_statementIf = 4, RULE_expression = 5, RULE_condition = 6;
29 | public static final String[] ruleNames = {
30 | "statementList", "statement", "statementCompiler", "statementAssign",
31 | "statementIf", "expression", "condition"
32 | };
33 |
34 | private static final String[] _LITERAL_NAMES = {
35 | null, "'#'", null, null, "'=>'", null, null, null, null, null, null, null,
36 | "'('", "')'", "'{'", "'}'", "'*'", "'/'", "'%'", "'+'", "'-'", "'<<'",
37 | "'>>'", "'AND'", "'OR'", "'XOR'", "'^'", "'=='", "'!='", "'>'", "'<'",
38 | "'>='", "'<='", "'='"
39 | };
40 | private static final String[] _SYMBOLIC_NAMES = {
41 | null, "COMPILERSIGN", "STANDARD", "ALIAS", "ALIASASSIGN", "POWERPOLE",
42 | "SMALL", "MEDIUM", "SUBSTATION", "IF", "ELSEIF", "ELSE", "BRACKET_OPEN",
43 | "BRACKET_CLOSE", "BRACE_OPEN", "BRACE_CLOSE", "ASTERISK", "SLASH", "MODULO",
44 | "PLUS", "MINUS", "BIT_LEFT", "BIT_RIGHT", "BIT_AND", "BIT_OR", "BIT_XOR",
45 | "POWER", "EQUAL", "NOTEQUAL", "GREATER", "LOWER", "GREATEREQUAL", "LOWEREQUAL",
46 | "ASSIGN", "NUMBER", "VAR", "WS"
47 | };
48 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
49 |
50 | /**
51 | * @deprecated Use {@link #VOCABULARY} instead.
52 | */
53 | @Deprecated
54 | public static final String[] tokenNames;
55 | static {
56 | tokenNames = new String[_SYMBOLIC_NAMES.length];
57 | for (int i = 0; i < tokenNames.length; i++) {
58 | tokenNames[i] = VOCABULARY.getLiteralName(i);
59 | if (tokenNames[i] == null) {
60 | tokenNames[i] = VOCABULARY.getSymbolicName(i);
61 | }
62 |
63 | if (tokenNames[i] == null) {
64 | tokenNames[i] = "";
65 | }
66 | }
67 | }
68 |
69 | @Override
70 | @Deprecated
71 | public String[] getTokenNames() {
72 | return tokenNames;
73 | }
74 |
75 | @Override
76 |
77 | public Vocabulary getVocabulary() {
78 | return VOCABULARY;
79 | }
80 |
81 | @Override
82 | public String getGrammarFileName() { return "FactorioScript.g4"; }
83 |
84 | @Override
85 | public String[] getRuleNames() { return ruleNames; }
86 |
87 | @Override
88 | public String getSerializedATN() { return _serializedATN; }
89 |
90 | @Override
91 | public ATN getATN() { return _ATN; }
92 |
93 | public FactorioScriptParser(TokenStream input) {
94 | super(input);
95 | _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
96 | }
97 | public static class StatementListContext extends ParserRuleContext {
98 | public StatementListContext(ParserRuleContext parent, int invokingState) {
99 | super(parent, invokingState);
100 | }
101 | @Override public int getRuleIndex() { return RULE_statementList; }
102 |
103 | public StatementListContext() { }
104 | public void copyFrom(StatementListContext ctx) {
105 | super.copyFrom(ctx);
106 | }
107 | }
108 | public static class MultipleStatementListContext extends StatementListContext {
109 | public StatementContext s;
110 | public StatementListContext sl;
111 | public StatementContext statement() {
112 | return getRuleContext(StatementContext.class,0);
113 | }
114 | public StatementListContext statementList() {
115 | return getRuleContext(StatementListContext.class,0);
116 | }
117 | public MultipleStatementListContext(StatementListContext ctx) { copyFrom(ctx); }
118 | @Override
119 | public void enterRule(ParseTreeListener listener) {
120 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterMultipleStatementList(this);
121 | }
122 | @Override
123 | public void exitRule(ParseTreeListener listener) {
124 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitMultipleStatementList(this);
125 | }
126 | @Override
127 | public T accept(ParseTreeVisitor extends T> visitor) {
128 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitMultipleStatementList(this);
129 | else return visitor.visitChildren(this);
130 | }
131 | }
132 | public static class SingleStatementListContext extends StatementListContext {
133 | public StatementContext s;
134 | public StatementContext statement() {
135 | return getRuleContext(StatementContext.class,0);
136 | }
137 | public SingleStatementListContext(StatementListContext ctx) { copyFrom(ctx); }
138 | @Override
139 | public void enterRule(ParseTreeListener listener) {
140 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterSingleStatementList(this);
141 | }
142 | @Override
143 | public void exitRule(ParseTreeListener listener) {
144 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitSingleStatementList(this);
145 | }
146 | @Override
147 | public T accept(ParseTreeVisitor extends T> visitor) {
148 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitSingleStatementList(this);
149 | else return visitor.visitChildren(this);
150 | }
151 | }
152 |
153 | public final StatementListContext statementList() throws RecognitionException {
154 | StatementListContext _localctx = new StatementListContext(_ctx, getState());
155 | enterRule(_localctx, 0, RULE_statementList);
156 | try {
157 | setState(18);
158 | _errHandler.sync(this);
159 | switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
160 | case 1:
161 | _localctx = new MultipleStatementListContext(_localctx);
162 | enterOuterAlt(_localctx, 1);
163 | {
164 | setState(14);
165 | ((MultipleStatementListContext)_localctx).s = statement();
166 | setState(15);
167 | ((MultipleStatementListContext)_localctx).sl = statementList();
168 | }
169 | break;
170 | case 2:
171 | _localctx = new SingleStatementListContext(_localctx);
172 | enterOuterAlt(_localctx, 2);
173 | {
174 | setState(17);
175 | ((SingleStatementListContext)_localctx).s = statement();
176 | }
177 | break;
178 | }
179 | }
180 | catch (RecognitionException re) {
181 | _localctx.exception = re;
182 | _errHandler.reportError(this, re);
183 | _errHandler.recover(this, re);
184 | }
185 | finally {
186 | exitRule();
187 | }
188 | return _localctx;
189 | }
190 |
191 | public static class StatementContext extends ParserRuleContext {
192 | public StatementCompilerContext statementCompiler() {
193 | return getRuleContext(StatementCompilerContext.class,0);
194 | }
195 | public StatementAssignContext statementAssign() {
196 | return getRuleContext(StatementAssignContext.class,0);
197 | }
198 | public StatementIfContext statementIf() {
199 | return getRuleContext(StatementIfContext.class,0);
200 | }
201 | public StatementContext(ParserRuleContext parent, int invokingState) {
202 | super(parent, invokingState);
203 | }
204 | @Override public int getRuleIndex() { return RULE_statement; }
205 | @Override
206 | public void enterRule(ParseTreeListener listener) {
207 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterStatement(this);
208 | }
209 | @Override
210 | public void exitRule(ParseTreeListener listener) {
211 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitStatement(this);
212 | }
213 | @Override
214 | public T accept(ParseTreeVisitor extends T> visitor) {
215 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitStatement(this);
216 | else return visitor.visitChildren(this);
217 | }
218 | }
219 |
220 | public final StatementContext statement() throws RecognitionException {
221 | StatementContext _localctx = new StatementContext(_ctx, getState());
222 | enterRule(_localctx, 2, RULE_statement);
223 | try {
224 | setState(23);
225 | _errHandler.sync(this);
226 | switch (_input.LA(1)) {
227 | case COMPILERSIGN:
228 | enterOuterAlt(_localctx, 1);
229 | {
230 | setState(20);
231 | statementCompiler();
232 | }
233 | break;
234 | case VAR:
235 | enterOuterAlt(_localctx, 2);
236 | {
237 | setState(21);
238 | statementAssign();
239 | }
240 | break;
241 | case IF:
242 | enterOuterAlt(_localctx, 3);
243 | {
244 | setState(22);
245 | statementIf();
246 | }
247 | break;
248 | default:
249 | throw new NoViableAltException(this);
250 | }
251 | }
252 | catch (RecognitionException re) {
253 | _localctx.exception = re;
254 | _errHandler.reportError(this, re);
255 | _errHandler.recover(this, re);
256 | }
257 | finally {
258 | exitRule();
259 | }
260 | return _localctx;
261 | }
262 |
263 | public static class StatementCompilerContext extends ParserRuleContext {
264 | public StatementCompilerContext(ParserRuleContext parent, int invokingState) {
265 | super(parent, invokingState);
266 | }
267 | @Override public int getRuleIndex() { return RULE_statementCompiler; }
268 |
269 | public StatementCompilerContext() { }
270 | public void copyFrom(StatementCompilerContext ctx) {
271 | super.copyFrom(ctx);
272 | }
273 | }
274 | public static class CompilerAliasContext extends StatementCompilerContext {
275 | public Token varOld;
276 | public Token varAlias;
277 | public TerminalNode COMPILERSIGN() { return getToken(FactorioScriptParser.COMPILERSIGN, 0); }
278 | public TerminalNode ALIAS() { return getToken(FactorioScriptParser.ALIAS, 0); }
279 | public TerminalNode ALIASASSIGN() { return getToken(FactorioScriptParser.ALIASASSIGN, 0); }
280 | public List VAR() { return getTokens(FactorioScriptParser.VAR); }
281 | public TerminalNode VAR(int i) {
282 | return getToken(FactorioScriptParser.VAR, i);
283 | }
284 | public CompilerAliasContext(StatementCompilerContext ctx) { copyFrom(ctx); }
285 | @Override
286 | public void enterRule(ParseTreeListener listener) {
287 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterCompilerAlias(this);
288 | }
289 | @Override
290 | public void exitRule(ParseTreeListener listener) {
291 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitCompilerAlias(this);
292 | }
293 | @Override
294 | public T accept(ParseTreeVisitor extends T> visitor) {
295 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitCompilerAlias(this);
296 | else return visitor.visitChildren(this);
297 | }
298 | }
299 | public static class CompilerStandardContext extends StatementCompilerContext {
300 | public Token varLeft;
301 | public Token varRight;
302 | public TerminalNode COMPILERSIGN() { return getToken(FactorioScriptParser.COMPILERSIGN, 0); }
303 | public TerminalNode STANDARD() { return getToken(FactorioScriptParser.STANDARD, 0); }
304 | public TerminalNode ALIASASSIGN() { return getToken(FactorioScriptParser.ALIASASSIGN, 0); }
305 | public List VAR() { return getTokens(FactorioScriptParser.VAR); }
306 | public TerminalNode VAR(int i) {
307 | return getToken(FactorioScriptParser.VAR, i);
308 | }
309 | public CompilerStandardContext(StatementCompilerContext ctx) { copyFrom(ctx); }
310 | @Override
311 | public void enterRule(ParseTreeListener listener) {
312 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterCompilerStandard(this);
313 | }
314 | @Override
315 | public void exitRule(ParseTreeListener listener) {
316 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitCompilerStandard(this);
317 | }
318 | @Override
319 | public T accept(ParseTreeVisitor extends T> visitor) {
320 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitCompilerStandard(this);
321 | else return visitor.visitChildren(this);
322 | }
323 | }
324 | public static class CompilerPowerpoleContext extends StatementCompilerContext {
325 | public Token pole;
326 | public TerminalNode COMPILERSIGN() { return getToken(FactorioScriptParser.COMPILERSIGN, 0); }
327 | public TerminalNode POWERPOLE() { return getToken(FactorioScriptParser.POWERPOLE, 0); }
328 | public TerminalNode SMALL() { return getToken(FactorioScriptParser.SMALL, 0); }
329 | public TerminalNode MEDIUM() { return getToken(FactorioScriptParser.MEDIUM, 0); }
330 | public TerminalNode SUBSTATION() { return getToken(FactorioScriptParser.SUBSTATION, 0); }
331 | public CompilerPowerpoleContext(StatementCompilerContext ctx) { copyFrom(ctx); }
332 | @Override
333 | public void enterRule(ParseTreeListener listener) {
334 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterCompilerPowerpole(this);
335 | }
336 | @Override
337 | public void exitRule(ParseTreeListener listener) {
338 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitCompilerPowerpole(this);
339 | }
340 | @Override
341 | public T accept(ParseTreeVisitor extends T> visitor) {
342 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitCompilerPowerpole(this);
343 | else return visitor.visitChildren(this);
344 | }
345 | }
346 |
347 | public final StatementCompilerContext statementCompiler() throws RecognitionException {
348 | StatementCompilerContext _localctx = new StatementCompilerContext(_ctx, getState());
349 | enterRule(_localctx, 4, RULE_statementCompiler);
350 | int _la;
351 | try {
352 | setState(38);
353 | _errHandler.sync(this);
354 | switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) {
355 | case 1:
356 | _localctx = new CompilerStandardContext(_localctx);
357 | enterOuterAlt(_localctx, 1);
358 | {
359 | setState(25);
360 | match(COMPILERSIGN);
361 | setState(26);
362 | match(STANDARD);
363 | setState(27);
364 | match(ALIASASSIGN);
365 | setState(28);
366 | ((CompilerStandardContext)_localctx).varLeft = match(VAR);
367 | setState(29);
368 | ((CompilerStandardContext)_localctx).varRight = match(VAR);
369 | }
370 | break;
371 | case 2:
372 | _localctx = new CompilerAliasContext(_localctx);
373 | enterOuterAlt(_localctx, 2);
374 | {
375 | setState(30);
376 | match(COMPILERSIGN);
377 | setState(31);
378 | match(ALIAS);
379 | setState(32);
380 | ((CompilerAliasContext)_localctx).varOld = match(VAR);
381 | setState(33);
382 | match(ALIASASSIGN);
383 | setState(34);
384 | ((CompilerAliasContext)_localctx).varAlias = match(VAR);
385 | }
386 | break;
387 | case 3:
388 | _localctx = new CompilerPowerpoleContext(_localctx);
389 | enterOuterAlt(_localctx, 3);
390 | {
391 | setState(35);
392 | match(COMPILERSIGN);
393 | setState(36);
394 | match(POWERPOLE);
395 | setState(37);
396 | ((CompilerPowerpoleContext)_localctx).pole = _input.LT(1);
397 | _la = _input.LA(1);
398 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << SMALL) | (1L << MEDIUM) | (1L << SUBSTATION))) != 0)) ) {
399 | ((CompilerPowerpoleContext)_localctx).pole = (Token)_errHandler.recoverInline(this);
400 | }
401 | else {
402 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
403 | _errHandler.reportMatch(this);
404 | consume();
405 | }
406 | }
407 | break;
408 | }
409 | }
410 | catch (RecognitionException re) {
411 | _localctx.exception = re;
412 | _errHandler.reportError(this, re);
413 | _errHandler.recover(this, re);
414 | }
415 | finally {
416 | exitRule();
417 | }
418 | return _localctx;
419 | }
420 |
421 | public static class StatementAssignContext extends ParserRuleContext {
422 | public StatementAssignContext(ParserRuleContext parent, int invokingState) {
423 | super(parent, invokingState);
424 | }
425 | @Override public int getRuleIndex() { return RULE_statementAssign; }
426 |
427 | public StatementAssignContext() { }
428 | public void copyFrom(StatementAssignContext ctx) {
429 | super.copyFrom(ctx);
430 | }
431 | }
432 | public static class AddStatementAssignContext extends StatementAssignContext {
433 | public Token var;
434 | public ExpressionContext expr;
435 | public TerminalNode PLUS() { return getToken(FactorioScriptParser.PLUS, 0); }
436 | public TerminalNode ASSIGN() { return getToken(FactorioScriptParser.ASSIGN, 0); }
437 | public TerminalNode VAR() { return getToken(FactorioScriptParser.VAR, 0); }
438 | public ExpressionContext expression() {
439 | return getRuleContext(ExpressionContext.class,0);
440 | }
441 | public AddStatementAssignContext(StatementAssignContext ctx) { copyFrom(ctx); }
442 | @Override
443 | public void enterRule(ParseTreeListener listener) {
444 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterAddStatementAssign(this);
445 | }
446 | @Override
447 | public void exitRule(ParseTreeListener listener) {
448 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitAddStatementAssign(this);
449 | }
450 | @Override
451 | public T accept(ParseTreeVisitor extends T> visitor) {
452 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitAddStatementAssign(this);
453 | else return visitor.visitChildren(this);
454 | }
455 | }
456 | public static class SubStatementAssignContext extends StatementAssignContext {
457 | public Token var;
458 | public ExpressionContext expr;
459 | public TerminalNode MINUS() { return getToken(FactorioScriptParser.MINUS, 0); }
460 | public TerminalNode ASSIGN() { return getToken(FactorioScriptParser.ASSIGN, 0); }
461 | public TerminalNode VAR() { return getToken(FactorioScriptParser.VAR, 0); }
462 | public ExpressionContext expression() {
463 | return getRuleContext(ExpressionContext.class,0);
464 | }
465 | public SubStatementAssignContext(StatementAssignContext ctx) { copyFrom(ctx); }
466 | @Override
467 | public void enterRule(ParseTreeListener listener) {
468 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterSubStatementAssign(this);
469 | }
470 | @Override
471 | public void exitRule(ParseTreeListener listener) {
472 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitSubStatementAssign(this);
473 | }
474 | @Override
475 | public T accept(ParseTreeVisitor extends T> visitor) {
476 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitSubStatementAssign(this);
477 | else return visitor.visitChildren(this);
478 | }
479 | }
480 | public static class OverwriteStatementAssignContext extends StatementAssignContext {
481 | public Token var;
482 | public ExpressionContext expr;
483 | public TerminalNode ASSIGN() { return getToken(FactorioScriptParser.ASSIGN, 0); }
484 | public TerminalNode VAR() { return getToken(FactorioScriptParser.VAR, 0); }
485 | public ExpressionContext expression() {
486 | return getRuleContext(ExpressionContext.class,0);
487 | }
488 | public OverwriteStatementAssignContext(StatementAssignContext ctx) { copyFrom(ctx); }
489 | @Override
490 | public void enterRule(ParseTreeListener listener) {
491 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterOverwriteStatementAssign(this);
492 | }
493 | @Override
494 | public void exitRule(ParseTreeListener listener) {
495 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitOverwriteStatementAssign(this);
496 | }
497 | @Override
498 | public T accept(ParseTreeVisitor extends T> visitor) {
499 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitOverwriteStatementAssign(this);
500 | else return visitor.visitChildren(this);
501 | }
502 | }
503 |
504 | public final StatementAssignContext statementAssign() throws RecognitionException {
505 | StatementAssignContext _localctx = new StatementAssignContext(_ctx, getState());
506 | enterRule(_localctx, 6, RULE_statementAssign);
507 | try {
508 | setState(51);
509 | _errHandler.sync(this);
510 | switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) {
511 | case 1:
512 | _localctx = new OverwriteStatementAssignContext(_localctx);
513 | enterOuterAlt(_localctx, 1);
514 | {
515 | setState(40);
516 | ((OverwriteStatementAssignContext)_localctx).var = match(VAR);
517 | setState(41);
518 | match(ASSIGN);
519 | setState(42);
520 | ((OverwriteStatementAssignContext)_localctx).expr = expression(0);
521 | }
522 | break;
523 | case 2:
524 | _localctx = new AddStatementAssignContext(_localctx);
525 | enterOuterAlt(_localctx, 2);
526 | {
527 | setState(43);
528 | ((AddStatementAssignContext)_localctx).var = match(VAR);
529 | setState(44);
530 | match(PLUS);
531 | setState(45);
532 | match(ASSIGN);
533 | setState(46);
534 | ((AddStatementAssignContext)_localctx).expr = expression(0);
535 | }
536 | break;
537 | case 3:
538 | _localctx = new SubStatementAssignContext(_localctx);
539 | enterOuterAlt(_localctx, 3);
540 | {
541 | setState(47);
542 | ((SubStatementAssignContext)_localctx).var = match(VAR);
543 | setState(48);
544 | match(MINUS);
545 | setState(49);
546 | match(ASSIGN);
547 | setState(50);
548 | ((SubStatementAssignContext)_localctx).expr = expression(0);
549 | }
550 | break;
551 | }
552 | }
553 | catch (RecognitionException re) {
554 | _localctx.exception = re;
555 | _errHandler.reportError(this, re);
556 | _errHandler.recover(this, re);
557 | }
558 | finally {
559 | exitRule();
560 | }
561 | return _localctx;
562 | }
563 |
564 | public static class StatementIfContext extends ParserRuleContext {
565 | public StatementIfContext(ParserRuleContext parent, int invokingState) {
566 | super(parent, invokingState);
567 | }
568 | @Override public int getRuleIndex() { return RULE_statementIf; }
569 |
570 | public StatementIfContext() { }
571 | public void copyFrom(StatementIfContext ctx) {
572 | super.copyFrom(ctx);
573 | }
574 | }
575 | public static class IfElseStatementContext extends StatementIfContext {
576 | public TerminalNode IF() { return getToken(FactorioScriptParser.IF, 0); }
577 | public List BRACKET_OPEN() { return getTokens(FactorioScriptParser.BRACKET_OPEN); }
578 | public TerminalNode BRACKET_OPEN(int i) {
579 | return getToken(FactorioScriptParser.BRACKET_OPEN, i);
580 | }
581 | public List condition() {
582 | return getRuleContexts(ConditionContext.class);
583 | }
584 | public ConditionContext condition(int i) {
585 | return getRuleContext(ConditionContext.class,i);
586 | }
587 | public List BRACKET_CLOSE() { return getTokens(FactorioScriptParser.BRACKET_CLOSE); }
588 | public TerminalNode BRACKET_CLOSE(int i) {
589 | return getToken(FactorioScriptParser.BRACKET_CLOSE, i);
590 | }
591 | public List BRACE_OPEN() { return getTokens(FactorioScriptParser.BRACE_OPEN); }
592 | public TerminalNode BRACE_OPEN(int i) {
593 | return getToken(FactorioScriptParser.BRACE_OPEN, i);
594 | }
595 | public List statementList() {
596 | return getRuleContexts(StatementListContext.class);
597 | }
598 | public StatementListContext statementList(int i) {
599 | return getRuleContext(StatementListContext.class,i);
600 | }
601 | public List BRACE_CLOSE() { return getTokens(FactorioScriptParser.BRACE_CLOSE); }
602 | public TerminalNode BRACE_CLOSE(int i) {
603 | return getToken(FactorioScriptParser.BRACE_CLOSE, i);
604 | }
605 | public TerminalNode ELSE() { return getToken(FactorioScriptParser.ELSE, 0); }
606 | public IfElseStatementContext(StatementIfContext ctx) { copyFrom(ctx); }
607 | @Override
608 | public void enterRule(ParseTreeListener listener) {
609 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterIfElseStatement(this);
610 | }
611 | @Override
612 | public void exitRule(ParseTreeListener listener) {
613 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitIfElseStatement(this);
614 | }
615 | @Override
616 | public T accept(ParseTreeVisitor extends T> visitor) {
617 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitIfElseStatement(this);
618 | else return visitor.visitChildren(this);
619 | }
620 | }
621 | public static class IfStatementContext extends StatementIfContext {
622 | public TerminalNode IF() { return getToken(FactorioScriptParser.IF, 0); }
623 | public TerminalNode BRACKET_OPEN() { return getToken(FactorioScriptParser.BRACKET_OPEN, 0); }
624 | public ConditionContext condition() {
625 | return getRuleContext(ConditionContext.class,0);
626 | }
627 | public TerminalNode BRACKET_CLOSE() { return getToken(FactorioScriptParser.BRACKET_CLOSE, 0); }
628 | public TerminalNode BRACE_OPEN() { return getToken(FactorioScriptParser.BRACE_OPEN, 0); }
629 | public StatementListContext statementList() {
630 | return getRuleContext(StatementListContext.class,0);
631 | }
632 | public TerminalNode BRACE_CLOSE() { return getToken(FactorioScriptParser.BRACE_CLOSE, 0); }
633 | public IfStatementContext(StatementIfContext ctx) { copyFrom(ctx); }
634 | @Override
635 | public void enterRule(ParseTreeListener listener) {
636 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterIfStatement(this);
637 | }
638 | @Override
639 | public void exitRule(ParseTreeListener listener) {
640 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitIfStatement(this);
641 | }
642 | @Override
643 | public T accept(ParseTreeVisitor extends T> visitor) {
644 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitIfStatement(this);
645 | else return visitor.visitChildren(this);
646 | }
647 | }
648 | public static class IfElseIfElseStatementContext extends StatementIfContext {
649 | public TerminalNode IF() { return getToken(FactorioScriptParser.IF, 0); }
650 | public List BRACKET_OPEN() { return getTokens(FactorioScriptParser.BRACKET_OPEN); }
651 | public TerminalNode BRACKET_OPEN(int i) {
652 | return getToken(FactorioScriptParser.BRACKET_OPEN, i);
653 | }
654 | public List condition() {
655 | return getRuleContexts(ConditionContext.class);
656 | }
657 | public ConditionContext condition(int i) {
658 | return getRuleContext(ConditionContext.class,i);
659 | }
660 | public List BRACKET_CLOSE() { return getTokens(FactorioScriptParser.BRACKET_CLOSE); }
661 | public TerminalNode BRACKET_CLOSE(int i) {
662 | return getToken(FactorioScriptParser.BRACKET_CLOSE, i);
663 | }
664 | public List BRACE_OPEN() { return getTokens(FactorioScriptParser.BRACE_OPEN); }
665 | public TerminalNode BRACE_OPEN(int i) {
666 | return getToken(FactorioScriptParser.BRACE_OPEN, i);
667 | }
668 | public List statementList() {
669 | return getRuleContexts(StatementListContext.class);
670 | }
671 | public StatementListContext statementList(int i) {
672 | return getRuleContext(StatementListContext.class,i);
673 | }
674 | public List BRACE_CLOSE() { return getTokens(FactorioScriptParser.BRACE_CLOSE); }
675 | public TerminalNode BRACE_CLOSE(int i) {
676 | return getToken(FactorioScriptParser.BRACE_CLOSE, i);
677 | }
678 | public TerminalNode ELSEIF() { return getToken(FactorioScriptParser.ELSEIF, 0); }
679 | public TerminalNode ELSE() { return getToken(FactorioScriptParser.ELSE, 0); }
680 | public IfElseIfElseStatementContext(StatementIfContext ctx) { copyFrom(ctx); }
681 | @Override
682 | public void enterRule(ParseTreeListener listener) {
683 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterIfElseIfElseStatement(this);
684 | }
685 | @Override
686 | public void exitRule(ParseTreeListener listener) {
687 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitIfElseIfElseStatement(this);
688 | }
689 | @Override
690 | public T accept(ParseTreeVisitor extends T> visitor) {
691 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitIfElseIfElseStatement(this);
692 | else return visitor.visitChildren(this);
693 | }
694 | }
695 |
696 | public final StatementIfContext statementIf() throws RecognitionException {
697 | StatementIfContext _localctx = new StatementIfContext(_ctx, getState());
698 | enterRule(_localctx, 8, RULE_statementIf);
699 | try {
700 | setState(98);
701 | _errHandler.sync(this);
702 | switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) {
703 | case 1:
704 | _localctx = new IfElseIfElseStatementContext(_localctx);
705 | enterOuterAlt(_localctx, 1);
706 | {
707 | setState(53);
708 | match(IF);
709 | setState(54);
710 | match(BRACKET_OPEN);
711 | setState(55);
712 | condition();
713 | setState(56);
714 | match(BRACKET_CLOSE);
715 | setState(57);
716 | match(BRACE_OPEN);
717 | setState(58);
718 | statementList();
719 | setState(59);
720 | match(BRACE_CLOSE);
721 | setState(60);
722 | match(ELSEIF);
723 | setState(61);
724 | match(BRACKET_OPEN);
725 | setState(62);
726 | condition();
727 | setState(63);
728 | match(BRACKET_CLOSE);
729 | setState(64);
730 | match(BRACE_OPEN);
731 | setState(65);
732 | statementList();
733 | setState(66);
734 | match(BRACE_CLOSE);
735 | setState(67);
736 | match(ELSE);
737 | setState(68);
738 | match(BRACKET_OPEN);
739 | setState(69);
740 | condition();
741 | setState(70);
742 | match(BRACKET_CLOSE);
743 | setState(71);
744 | match(BRACE_OPEN);
745 | setState(72);
746 | statementList();
747 | setState(73);
748 | match(BRACE_CLOSE);
749 | }
750 | break;
751 | case 2:
752 | _localctx = new IfElseStatementContext(_localctx);
753 | enterOuterAlt(_localctx, 2);
754 | {
755 | setState(75);
756 | match(IF);
757 | setState(76);
758 | match(BRACKET_OPEN);
759 | setState(77);
760 | condition();
761 | setState(78);
762 | match(BRACKET_CLOSE);
763 | setState(79);
764 | match(BRACE_OPEN);
765 | setState(80);
766 | statementList();
767 | setState(81);
768 | match(BRACE_CLOSE);
769 | setState(82);
770 | match(ELSE);
771 | setState(83);
772 | match(BRACKET_OPEN);
773 | setState(84);
774 | condition();
775 | setState(85);
776 | match(BRACKET_CLOSE);
777 | setState(86);
778 | match(BRACE_OPEN);
779 | setState(87);
780 | statementList();
781 | setState(88);
782 | match(BRACE_CLOSE);
783 | }
784 | break;
785 | case 3:
786 | _localctx = new IfStatementContext(_localctx);
787 | enterOuterAlt(_localctx, 3);
788 | {
789 | setState(90);
790 | match(IF);
791 | setState(91);
792 | match(BRACKET_OPEN);
793 | setState(92);
794 | condition();
795 | setState(93);
796 | match(BRACKET_CLOSE);
797 | setState(94);
798 | match(BRACE_OPEN);
799 | setState(95);
800 | statementList();
801 | setState(96);
802 | match(BRACE_CLOSE);
803 | }
804 | break;
805 | }
806 | }
807 | catch (RecognitionException re) {
808 | _localctx.exception = re;
809 | _errHandler.reportError(this, re);
810 | _errHandler.recover(this, re);
811 | }
812 | finally {
813 | exitRule();
814 | }
815 | return _localctx;
816 | }
817 |
818 | public static class ExpressionContext extends ParserRuleContext {
819 | public ExpressionContext(ParserRuleContext parent, int invokingState) {
820 | super(parent, invokingState);
821 | }
822 | @Override public int getRuleIndex() { return RULE_expression; }
823 |
824 | public ExpressionContext() { }
825 | public void copyFrom(ExpressionContext ctx) {
826 | super.copyFrom(ctx);
827 | }
828 | }
829 | public static class VarExpContext extends ExpressionContext {
830 | public Token variable;
831 | public TerminalNode VAR() { return getToken(FactorioScriptParser.VAR, 0); }
832 | public VarExpContext(ExpressionContext ctx) { copyFrom(ctx); }
833 | @Override
834 | public void enterRule(ParseTreeListener listener) {
835 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterVarExp(this);
836 | }
837 | @Override
838 | public void exitRule(ParseTreeListener listener) {
839 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitVarExp(this);
840 | }
841 | @Override
842 | public T accept(ParseTreeVisitor extends T> visitor) {
843 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitVarExp(this);
844 | else return visitor.visitChildren(this);
845 | }
846 | }
847 | public static class MulDivModExpContext extends ExpressionContext {
848 | public ExpressionContext left;
849 | public Token operand;
850 | public ExpressionContext right;
851 | public List expression() {
852 | return getRuleContexts(ExpressionContext.class);
853 | }
854 | public ExpressionContext expression(int i) {
855 | return getRuleContext(ExpressionContext.class,i);
856 | }
857 | public TerminalNode ASTERISK() { return getToken(FactorioScriptParser.ASTERISK, 0); }
858 | public TerminalNode SLASH() { return getToken(FactorioScriptParser.SLASH, 0); }
859 | public TerminalNode MODULO() { return getToken(FactorioScriptParser.MODULO, 0); }
860 | public MulDivModExpContext(ExpressionContext ctx) { copyFrom(ctx); }
861 | @Override
862 | public void enterRule(ParseTreeListener listener) {
863 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterMulDivModExp(this);
864 | }
865 | @Override
866 | public void exitRule(ParseTreeListener listener) {
867 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitMulDivModExp(this);
868 | }
869 | @Override
870 | public T accept(ParseTreeVisitor extends T> visitor) {
871 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitMulDivModExp(this);
872 | else return visitor.visitChildren(this);
873 | }
874 | }
875 | public static class PowExpContext extends ExpressionContext {
876 | public ExpressionContext left;
877 | public ExpressionContext right;
878 | public TerminalNode POWER() { return getToken(FactorioScriptParser.POWER, 0); }
879 | public List expression() {
880 | return getRuleContexts(ExpressionContext.class);
881 | }
882 | public ExpressionContext expression(int i) {
883 | return getRuleContext(ExpressionContext.class,i);
884 | }
885 | public PowExpContext(ExpressionContext ctx) { copyFrom(ctx); }
886 | @Override
887 | public void enterRule(ParseTreeListener listener) {
888 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterPowExp(this);
889 | }
890 | @Override
891 | public void exitRule(ParseTreeListener listener) {
892 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitPowExp(this);
893 | }
894 | @Override
895 | public T accept(ParseTreeVisitor extends T> visitor) {
896 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitPowExp(this);
897 | else return visitor.visitChildren(this);
898 | }
899 | }
900 | public static class BitExpContext extends ExpressionContext {
901 | public ExpressionContext left;
902 | public Token operand;
903 | public ExpressionContext right;
904 | public List expression() {
905 | return getRuleContexts(ExpressionContext.class);
906 | }
907 | public ExpressionContext expression(int i) {
908 | return getRuleContext(ExpressionContext.class,i);
909 | }
910 | public TerminalNode BIT_LEFT() { return getToken(FactorioScriptParser.BIT_LEFT, 0); }
911 | public TerminalNode BIT_RIGHT() { return getToken(FactorioScriptParser.BIT_RIGHT, 0); }
912 | public TerminalNode BIT_AND() { return getToken(FactorioScriptParser.BIT_AND, 0); }
913 | public TerminalNode BIT_OR() { return getToken(FactorioScriptParser.BIT_OR, 0); }
914 | public TerminalNode BIT_XOR() { return getToken(FactorioScriptParser.BIT_XOR, 0); }
915 | public BitExpContext(ExpressionContext ctx) { copyFrom(ctx); }
916 | @Override
917 | public void enterRule(ParseTreeListener listener) {
918 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterBitExp(this);
919 | }
920 | @Override
921 | public void exitRule(ParseTreeListener listener) {
922 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitBitExp(this);
923 | }
924 | @Override
925 | public T accept(ParseTreeVisitor extends T> visitor) {
926 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitBitExp(this);
927 | else return visitor.visitChildren(this);
928 | }
929 | }
930 | public static class PriorityExpContext extends ExpressionContext {
931 | public ExpressionContext expr;
932 | public TerminalNode BRACKET_OPEN() { return getToken(FactorioScriptParser.BRACKET_OPEN, 0); }
933 | public TerminalNode BRACKET_CLOSE() { return getToken(FactorioScriptParser.BRACKET_CLOSE, 0); }
934 | public ExpressionContext expression() {
935 | return getRuleContext(ExpressionContext.class,0);
936 | }
937 | public PriorityExpContext(ExpressionContext ctx) { copyFrom(ctx); }
938 | @Override
939 | public void enterRule(ParseTreeListener listener) {
940 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterPriorityExp(this);
941 | }
942 | @Override
943 | public void exitRule(ParseTreeListener listener) {
944 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitPriorityExp(this);
945 | }
946 | @Override
947 | public T accept(ParseTreeVisitor extends T> visitor) {
948 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitPriorityExp(this);
949 | else return visitor.visitChildren(this);
950 | }
951 | }
952 | public static class AddSubExpContext extends ExpressionContext {
953 | public ExpressionContext left;
954 | public Token operand;
955 | public ExpressionContext right;
956 | public List expression() {
957 | return getRuleContexts(ExpressionContext.class);
958 | }
959 | public ExpressionContext expression(int i) {
960 | return getRuleContext(ExpressionContext.class,i);
961 | }
962 | public TerminalNode PLUS() { return getToken(FactorioScriptParser.PLUS, 0); }
963 | public TerminalNode MINUS() { return getToken(FactorioScriptParser.MINUS, 0); }
964 | public AddSubExpContext(ExpressionContext ctx) { copyFrom(ctx); }
965 | @Override
966 | public void enterRule(ParseTreeListener listener) {
967 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterAddSubExp(this);
968 | }
969 | @Override
970 | public void exitRule(ParseTreeListener listener) {
971 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitAddSubExp(this);
972 | }
973 | @Override
974 | public T accept(ParseTreeVisitor extends T> visitor) {
975 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitAddSubExp(this);
976 | else return visitor.visitChildren(this);
977 | }
978 | }
979 | public static class NumExpContext extends ExpressionContext {
980 | public Token number;
981 | public TerminalNode NUMBER() { return getToken(FactorioScriptParser.NUMBER, 0); }
982 | public NumExpContext(ExpressionContext ctx) { copyFrom(ctx); }
983 | @Override
984 | public void enterRule(ParseTreeListener listener) {
985 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterNumExp(this);
986 | }
987 | @Override
988 | public void exitRule(ParseTreeListener listener) {
989 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitNumExp(this);
990 | }
991 | @Override
992 | public T accept(ParseTreeVisitor extends T> visitor) {
993 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitNumExp(this);
994 | else return visitor.visitChildren(this);
995 | }
996 | }
997 |
998 | public final ExpressionContext expression() throws RecognitionException {
999 | return expression(0);
1000 | }
1001 |
1002 | private ExpressionContext expression(int _p) throws RecognitionException {
1003 | ParserRuleContext _parentctx = _ctx;
1004 | int _parentState = getState();
1005 | ExpressionContext _localctx = new ExpressionContext(_ctx, _parentState);
1006 | ExpressionContext _prevctx = _localctx;
1007 | int _startState = 10;
1008 | enterRecursionRule(_localctx, 10, RULE_expression, _p);
1009 | int _la;
1010 | try {
1011 | int _alt;
1012 | enterOuterAlt(_localctx, 1);
1013 | {
1014 | setState(107);
1015 | _errHandler.sync(this);
1016 | switch (_input.LA(1)) {
1017 | case BRACKET_OPEN:
1018 | {
1019 | _localctx = new PriorityExpContext(_localctx);
1020 | _ctx = _localctx;
1021 | _prevctx = _localctx;
1022 |
1023 | setState(101);
1024 | match(BRACKET_OPEN);
1025 | setState(102);
1026 | ((PriorityExpContext)_localctx).expr = expression(0);
1027 | setState(103);
1028 | match(BRACKET_CLOSE);
1029 | }
1030 | break;
1031 | case VAR:
1032 | {
1033 | _localctx = new VarExpContext(_localctx);
1034 | _ctx = _localctx;
1035 | _prevctx = _localctx;
1036 | setState(105);
1037 | ((VarExpContext)_localctx).variable = match(VAR);
1038 | }
1039 | break;
1040 | case NUMBER:
1041 | {
1042 | _localctx = new NumExpContext(_localctx);
1043 | _ctx = _localctx;
1044 | _prevctx = _localctx;
1045 | setState(106);
1046 | ((NumExpContext)_localctx).number = match(NUMBER);
1047 | }
1048 | break;
1049 | default:
1050 | throw new NoViableAltException(this);
1051 | }
1052 | _ctx.stop = _input.LT(-1);
1053 | setState(123);
1054 | _errHandler.sync(this);
1055 | _alt = getInterpreter().adaptivePredict(_input,7,_ctx);
1056 | while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) {
1057 | if ( _alt==1 ) {
1058 | if ( _parseListeners!=null ) triggerExitRuleEvent();
1059 | _prevctx = _localctx;
1060 | {
1061 | setState(121);
1062 | _errHandler.sync(this);
1063 | switch ( getInterpreter().adaptivePredict(_input,6,_ctx) ) {
1064 | case 1:
1065 | {
1066 | _localctx = new MulDivModExpContext(new ExpressionContext(_parentctx, _parentState));
1067 | ((MulDivModExpContext)_localctx).left = _prevctx;
1068 | pushNewRecursionContext(_localctx, _startState, RULE_expression);
1069 | setState(109);
1070 | if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)");
1071 | setState(110);
1072 | ((MulDivModExpContext)_localctx).operand = _input.LT(1);
1073 | _la = _input.LA(1);
1074 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << ASTERISK) | (1L << SLASH) | (1L << MODULO))) != 0)) ) {
1075 | ((MulDivModExpContext)_localctx).operand = (Token)_errHandler.recoverInline(this);
1076 | }
1077 | else {
1078 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
1079 | _errHandler.reportMatch(this);
1080 | consume();
1081 | }
1082 | setState(111);
1083 | ((MulDivModExpContext)_localctx).right = expression(7);
1084 | }
1085 | break;
1086 | case 2:
1087 | {
1088 | _localctx = new AddSubExpContext(new ExpressionContext(_parentctx, _parentState));
1089 | ((AddSubExpContext)_localctx).left = _prevctx;
1090 | pushNewRecursionContext(_localctx, _startState, RULE_expression);
1091 | setState(112);
1092 | if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)");
1093 | setState(113);
1094 | ((AddSubExpContext)_localctx).operand = _input.LT(1);
1095 | _la = _input.LA(1);
1096 | if ( !(_la==PLUS || _la==MINUS) ) {
1097 | ((AddSubExpContext)_localctx).operand = (Token)_errHandler.recoverInline(this);
1098 | }
1099 | else {
1100 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
1101 | _errHandler.reportMatch(this);
1102 | consume();
1103 | }
1104 | setState(114);
1105 | ((AddSubExpContext)_localctx).right = expression(6);
1106 | }
1107 | break;
1108 | case 3:
1109 | {
1110 | _localctx = new BitExpContext(new ExpressionContext(_parentctx, _parentState));
1111 | ((BitExpContext)_localctx).left = _prevctx;
1112 | pushNewRecursionContext(_localctx, _startState, RULE_expression);
1113 | setState(115);
1114 | if (!(precpred(_ctx, 4))) throw new FailedPredicateException(this, "precpred(_ctx, 4)");
1115 | setState(116);
1116 | ((BitExpContext)_localctx).operand = _input.LT(1);
1117 | _la = _input.LA(1);
1118 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << BIT_LEFT) | (1L << BIT_RIGHT) | (1L << BIT_AND) | (1L << BIT_OR) | (1L << BIT_XOR))) != 0)) ) {
1119 | ((BitExpContext)_localctx).operand = (Token)_errHandler.recoverInline(this);
1120 | }
1121 | else {
1122 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
1123 | _errHandler.reportMatch(this);
1124 | consume();
1125 | }
1126 | setState(117);
1127 | ((BitExpContext)_localctx).right = expression(5);
1128 | }
1129 | break;
1130 | case 4:
1131 | {
1132 | _localctx = new PowExpContext(new ExpressionContext(_parentctx, _parentState));
1133 | ((PowExpContext)_localctx).left = _prevctx;
1134 | pushNewRecursionContext(_localctx, _startState, RULE_expression);
1135 | setState(118);
1136 | if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)");
1137 | setState(119);
1138 | match(POWER);
1139 | setState(120);
1140 | ((PowExpContext)_localctx).right = expression(3);
1141 | }
1142 | break;
1143 | }
1144 | }
1145 | }
1146 | setState(125);
1147 | _errHandler.sync(this);
1148 | _alt = getInterpreter().adaptivePredict(_input,7,_ctx);
1149 | }
1150 | }
1151 | }
1152 | catch (RecognitionException re) {
1153 | _localctx.exception = re;
1154 | _errHandler.reportError(this, re);
1155 | _errHandler.recover(this, re);
1156 | }
1157 | finally {
1158 | unrollRecursionContexts(_parentctx);
1159 | }
1160 | return _localctx;
1161 | }
1162 |
1163 | public static class ConditionContext extends ParserRuleContext {
1164 | public List expression() {
1165 | return getRuleContexts(ExpressionContext.class);
1166 | }
1167 | public ExpressionContext expression(int i) {
1168 | return getRuleContext(ExpressionContext.class,i);
1169 | }
1170 | public TerminalNode EQUAL() { return getToken(FactorioScriptParser.EQUAL, 0); }
1171 | public TerminalNode NOTEQUAL() { return getToken(FactorioScriptParser.NOTEQUAL, 0); }
1172 | public TerminalNode GREATER() { return getToken(FactorioScriptParser.GREATER, 0); }
1173 | public TerminalNode LOWER() { return getToken(FactorioScriptParser.LOWER, 0); }
1174 | public TerminalNode GREATEREQUAL() { return getToken(FactorioScriptParser.GREATEREQUAL, 0); }
1175 | public TerminalNode LOWEREQUAL() { return getToken(FactorioScriptParser.LOWEREQUAL, 0); }
1176 | public ConditionContext(ParserRuleContext parent, int invokingState) {
1177 | super(parent, invokingState);
1178 | }
1179 | @Override public int getRuleIndex() { return RULE_condition; }
1180 | @Override
1181 | public void enterRule(ParseTreeListener listener) {
1182 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).enterCondition(this);
1183 | }
1184 | @Override
1185 | public void exitRule(ParseTreeListener listener) {
1186 | if ( listener instanceof FactorioScriptListener ) ((FactorioScriptListener)listener).exitCondition(this);
1187 | }
1188 | @Override
1189 | public T accept(ParseTreeVisitor extends T> visitor) {
1190 | if ( visitor instanceof FactorioScriptVisitor ) return ((FactorioScriptVisitor extends T>)visitor).visitCondition(this);
1191 | else return visitor.visitChildren(this);
1192 | }
1193 | }
1194 |
1195 | public final ConditionContext condition() throws RecognitionException {
1196 | ConditionContext _localctx = new ConditionContext(_ctx, getState());
1197 | enterRule(_localctx, 12, RULE_condition);
1198 | int _la;
1199 | try {
1200 | enterOuterAlt(_localctx, 1);
1201 | {
1202 | setState(126);
1203 | expression(0);
1204 | setState(127);
1205 | _la = _input.LA(1);
1206 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << EQUAL) | (1L << NOTEQUAL) | (1L << GREATER) | (1L << LOWER) | (1L << GREATEREQUAL) | (1L << LOWEREQUAL))) != 0)) ) {
1207 | _errHandler.recoverInline(this);
1208 | }
1209 | else {
1210 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
1211 | _errHandler.reportMatch(this);
1212 | consume();
1213 | }
1214 | setState(128);
1215 | expression(0);
1216 | }
1217 | }
1218 | catch (RecognitionException re) {
1219 | _localctx.exception = re;
1220 | _errHandler.reportError(this, re);
1221 | _errHandler.recover(this, re);
1222 | }
1223 | finally {
1224 | exitRule();
1225 | }
1226 | return _localctx;
1227 | }
1228 |
1229 | public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
1230 | switch (ruleIndex) {
1231 | case 5:
1232 | return expression_sempred((ExpressionContext)_localctx, predIndex);
1233 | }
1234 | return true;
1235 | }
1236 | private boolean expression_sempred(ExpressionContext _localctx, int predIndex) {
1237 | switch (predIndex) {
1238 | case 0:
1239 | return precpred(_ctx, 6);
1240 | case 1:
1241 | return precpred(_ctx, 5);
1242 | case 2:
1243 | return precpred(_ctx, 4);
1244 | case 3:
1245 | return precpred(_ctx, 3);
1246 | }
1247 | return true;
1248 | }
1249 |
1250 | public static final String _serializedATN =
1251 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3&\u0085\4\2\t\2\4"+
1252 | "\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\3\2\3\2\3\2\3\2\5\2\25"+
1253 | "\n\2\3\3\3\3\3\3\5\3\32\n\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3"+
1254 | "\4\3\4\3\4\5\4)\n\4\3\5\3\5\3\5\3\5\3\5\3\5\3\5\3\5\3\5\3\5\3\5\5\5\66"+
1255 | "\n\5\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3"+
1256 | "\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6"+
1257 | "\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\3\6\5\6e\n\6\3\7\3\7\3\7\3\7"+
1258 | "\3\7\3\7\3\7\5\7n\n\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7\3\7"+
1259 | "\7\7|\n\7\f\7\16\7\177\13\7\3\b\3\b\3\b\3\b\3\b\2\3\f\t\2\4\6\b\n\f\16"+
1260 | "\2\7\3\2\b\n\3\2\22\24\3\2\25\26\3\2\27\33\3\2\35\"\2\u008c\2\24\3\2\2"+
1261 | "\2\4\31\3\2\2\2\6(\3\2\2\2\b\65\3\2\2\2\nd\3\2\2\2\fm\3\2\2\2\16\u0080"+
1262 | "\3\2\2\2\20\21\5\4\3\2\21\22\5\2\2\2\22\25\3\2\2\2\23\25\5\4\3\2\24\20"+
1263 | "\3\2\2\2\24\23\3\2\2\2\25\3\3\2\2\2\26\32\5\6\4\2\27\32\5\b\5\2\30\32"+
1264 | "\5\n\6\2\31\26\3\2\2\2\31\27\3\2\2\2\31\30\3\2\2\2\32\5\3\2\2\2\33\34"+
1265 | "\7\3\2\2\34\35\7\4\2\2\35\36\7\6\2\2\36\37\7%\2\2\37)\7%\2\2 !\7\3\2\2"+
1266 | "!\"\7\5\2\2\"#\7%\2\2#$\7\6\2\2$)\7%\2\2%&\7\3\2\2&\'\7\7\2\2\')\t\2\2"+
1267 | "\2(\33\3\2\2\2( \3\2\2\2(%\3\2\2\2)\7\3\2\2\2*+\7%\2\2+,\7#\2\2,\66\5"+
1268 | "\f\7\2-.\7%\2\2./\7\25\2\2/\60\7#\2\2\60\66\5\f\7\2\61\62\7%\2\2\62\63"+
1269 | "\7\26\2\2\63\64\7#\2\2\64\66\5\f\7\2\65*\3\2\2\2\65-\3\2\2\2\65\61\3\2"+
1270 | "\2\2\66\t\3\2\2\2\678\7\13\2\289\7\16\2\29:\5\16\b\2:;\7\17\2\2;<\7\20"+
1271 | "\2\2<=\5\2\2\2=>\7\21\2\2>?\7\f\2\2?@\7\16\2\2@A\5\16\b\2AB\7\17\2\2B"+
1272 | "C\7\20\2\2CD\5\2\2\2DE\7\21\2\2EF\7\r\2\2FG\7\16\2\2GH\5\16\b\2HI\7\17"+
1273 | "\2\2IJ\7\20\2\2JK\5\2\2\2KL\7\21\2\2Le\3\2\2\2MN\7\13\2\2NO\7\16\2\2O"+
1274 | "P\5\16\b\2PQ\7\17\2\2QR\7\20\2\2RS\5\2\2\2ST\7\21\2\2TU\7\r\2\2UV\7\16"+
1275 | "\2\2VW\5\16\b\2WX\7\17\2\2XY\7\20\2\2YZ\5\2\2\2Z[\7\21\2\2[e\3\2\2\2\\"+
1276 | "]\7\13\2\2]^\7\16\2\2^_\5\16\b\2_`\7\17\2\2`a\7\20\2\2ab\5\2\2\2bc\7\21"+
1277 | "\2\2ce\3\2\2\2d\67\3\2\2\2dM\3\2\2\2d\\\3\2\2\2e\13\3\2\2\2fg\b\7\1\2"+
1278 | "gh\7\16\2\2hi\5\f\7\2ij\7\17\2\2jn\3\2\2\2kn\7%\2\2ln\7$\2\2mf\3\2\2\2"+
1279 | "mk\3\2\2\2ml\3\2\2\2n}\3\2\2\2op\f\b\2\2pq\t\3\2\2q|\5\f\7\trs\f\7\2\2"+
1280 | "st\t\4\2\2t|\5\f\7\buv\f\6\2\2vw\t\5\2\2w|\5\f\7\7xy\f\5\2\2yz\7\34\2"+
1281 | "\2z|\5\f\7\5{o\3\2\2\2{r\3\2\2\2{u\3\2\2\2{x\3\2\2\2|\177\3\2\2\2}{\3"+
1282 | "\2\2\2}~\3\2\2\2~\r\3\2\2\2\177}\3\2\2\2\u0080\u0081\5\f\7\2\u0081\u0082"+
1283 | "\t\6\2\2\u0082\u0083\5\f\7\2\u0083\17\3\2\2\2\n\24\31(\65dm{}";
1284 | public static final ATN _ATN =
1285 | new ATNDeserializer().deserialize(_serializedATN.toCharArray());
1286 | static {
1287 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
1288 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
1289 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
1290 | }
1291 | }
1292 | }
--------------------------------------------------------------------------------
/src/main/java/antlr/FactorioScriptVisitor.java:
--------------------------------------------------------------------------------
1 | package antlr;
2 | // Generated from FactorioScript.g4 by ANTLR 4.7
3 | import org.antlr.v4.runtime.tree.ParseTreeVisitor;
4 |
5 | /**
6 | * This interface defines a complete generic visitor for a parse tree produced
7 | * by {@link FactorioScriptParser}.
8 | *
9 | * @param The return type of the visit operation. Use {@link Void} for
10 | * operations with no return type.
11 | */
12 | public interface FactorioScriptVisitor extends ParseTreeVisitor {
13 | /**
14 | * Visit a parse tree produced by the {@code multipleStatementList}
15 | * labeled alternative in {@link FactorioScriptParser#statementList}.
16 | * @param ctx the parse tree
17 | * @return the visitor result
18 | */
19 | T visitMultipleStatementList(FactorioScriptParser.MultipleStatementListContext ctx);
20 | /**
21 | * Visit a parse tree produced by the {@code singleStatementList}
22 | * labeled alternative in {@link FactorioScriptParser#statementList}.
23 | * @param ctx the parse tree
24 | * @return the visitor result
25 | */
26 | T visitSingleStatementList(FactorioScriptParser.SingleStatementListContext ctx);
27 | /**
28 | * Visit a parse tree produced by {@link FactorioScriptParser#statement}.
29 | * @param ctx the parse tree
30 | * @return the visitor result
31 | */
32 | T visitStatement(FactorioScriptParser.StatementContext ctx);
33 | /**
34 | * Visit a parse tree produced by the {@code CompilerStandard}
35 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
36 | * @param ctx the parse tree
37 | * @return the visitor result
38 | */
39 | T visitCompilerStandard(FactorioScriptParser.CompilerStandardContext ctx);
40 | /**
41 | * Visit a parse tree produced by the {@code CompilerAlias}
42 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
43 | * @param ctx the parse tree
44 | * @return the visitor result
45 | */
46 | T visitCompilerAlias(FactorioScriptParser.CompilerAliasContext ctx);
47 | /**
48 | * Visit a parse tree produced by the {@code CompilerPowerpole}
49 | * labeled alternative in {@link FactorioScriptParser#statementCompiler}.
50 | * @param ctx the parse tree
51 | * @return the visitor result
52 | */
53 | T visitCompilerPowerpole(FactorioScriptParser.CompilerPowerpoleContext ctx);
54 | /**
55 | * Visit a parse tree produced by the {@code overwriteStatementAssign}
56 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
57 | * @param ctx the parse tree
58 | * @return the visitor result
59 | */
60 | T visitOverwriteStatementAssign(FactorioScriptParser.OverwriteStatementAssignContext ctx);
61 | /**
62 | * Visit a parse tree produced by the {@code addStatementAssign}
63 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
64 | * @param ctx the parse tree
65 | * @return the visitor result
66 | */
67 | T visitAddStatementAssign(FactorioScriptParser.AddStatementAssignContext ctx);
68 | /**
69 | * Visit a parse tree produced by the {@code subStatementAssign}
70 | * labeled alternative in {@link FactorioScriptParser#statementAssign}.
71 | * @param ctx the parse tree
72 | * @return the visitor result
73 | */
74 | T visitSubStatementAssign(FactorioScriptParser.SubStatementAssignContext ctx);
75 | /**
76 | * Visit a parse tree produced by the {@code ifElseIfElseStatement}
77 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
78 | * @param ctx the parse tree
79 | * @return the visitor result
80 | */
81 | T visitIfElseIfElseStatement(FactorioScriptParser.IfElseIfElseStatementContext ctx);
82 | /**
83 | * Visit a parse tree produced by the {@code ifElseStatement}
84 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
85 | * @param ctx the parse tree
86 | * @return the visitor result
87 | */
88 | T visitIfElseStatement(FactorioScriptParser.IfElseStatementContext ctx);
89 | /**
90 | * Visit a parse tree produced by the {@code ifStatement}
91 | * labeled alternative in {@link FactorioScriptParser#statementIf}.
92 | * @param ctx the parse tree
93 | * @return the visitor result
94 | */
95 | T visitIfStatement(FactorioScriptParser.IfStatementContext ctx);
96 | /**
97 | * Visit a parse tree produced by the {@code varExp}
98 | * labeled alternative in {@link FactorioScriptParser#expression}.
99 | * @param ctx the parse tree
100 | * @return the visitor result
101 | */
102 | T visitVarExp(FactorioScriptParser.VarExpContext ctx);
103 | /**
104 | * Visit a parse tree produced by the {@code mulDivModExp}
105 | * labeled alternative in {@link FactorioScriptParser#expression}.
106 | * @param ctx the parse tree
107 | * @return the visitor result
108 | */
109 | T visitMulDivModExp(FactorioScriptParser.MulDivModExpContext ctx);
110 | /**
111 | * Visit a parse tree produced by the {@code powExp}
112 | * labeled alternative in {@link FactorioScriptParser#expression}.
113 | * @param ctx the parse tree
114 | * @return the visitor result
115 | */
116 | T visitPowExp(FactorioScriptParser.PowExpContext ctx);
117 | /**
118 | * Visit a parse tree produced by the {@code bitExp}
119 | * labeled alternative in {@link FactorioScriptParser#expression}.
120 | * @param ctx the parse tree
121 | * @return the visitor result
122 | */
123 | T visitBitExp(FactorioScriptParser.BitExpContext ctx);
124 | /**
125 | * Visit a parse tree produced by the {@code priorityExp}
126 | * labeled alternative in {@link FactorioScriptParser#expression}.
127 | * @param ctx the parse tree
128 | * @return the visitor result
129 | */
130 | T visitPriorityExp(FactorioScriptParser.PriorityExpContext ctx);
131 | /**
132 | * Visit a parse tree produced by the {@code addSubExp}
133 | * labeled alternative in {@link FactorioScriptParser#expression}.
134 | * @param ctx the parse tree
135 | * @return the visitor result
136 | */
137 | T visitAddSubExp(FactorioScriptParser.AddSubExpContext ctx);
138 | /**
139 | * Visit a parse tree produced by the {@code numExp}
140 | * labeled alternative in {@link FactorioScriptParser#expression}.
141 | * @param ctx the parse tree
142 | * @return the visitor result
143 | */
144 | T visitNumExp(FactorioScriptParser.NumExpContext ctx);
145 | /**
146 | * Visit a parse tree produced by {@link FactorioScriptParser#condition}.
147 | * @param ctx the parse tree
148 | * @return the visitor result
149 | */
150 | T visitCondition(FactorioScriptParser.ConditionContext ctx);
151 | }
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/ArithmeticConditions.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class ArithmeticConditions {
7 |
8 | public Signal first_signal;
9 | public Signal second_signal;
10 | public int constant;
11 | public String operation;
12 | public Signal output_signal;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Blueprint.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class Blueprint implements FactorioEntity {
7 |
8 | public Icon[] icons;
9 | public Entity[] entities;
10 | public String item;
11 | public long version;
12 | public String label;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/BlueprintBook.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class BlueprintBook implements FactorioEntity {
7 |
8 | public Blueprint[] blueprints;
9 | public String item;
10 | public int active_index;
11 | public long version;
12 | public String label;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/BlueprintRoot.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class BlueprintRoot implements FactorioEntity {
7 |
8 | public BlueprintBook blueprint_book;
9 | public Blueprint blueprint;
10 |
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Connection.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import java.util.ArrayList;
4 |
5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6 |
7 | @JsonIgnoreProperties(ignoreUnknown = true)
8 | public class Connection {
9 |
10 | public ArrayList red;
11 | public ArrayList green;
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/ConnectionDetail.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class ConnectionDetail {
7 |
8 | public int entity_id;
9 | public int circuit_id;
10 |
11 | public ConnectionDetail(int entity_id) {
12 | this.entity_id = entity_id;
13 | }
14 |
15 | public ConnectionDetail(int entity_id,int circuit_id) {
16 | this.entity_id = entity_id;
17 | this.circuit_id = circuit_id;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/ControlBehavior.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import java.util.ArrayList;
4 |
5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6 |
7 | @JsonIgnoreProperties(ignoreUnknown = true)
8 | public class ControlBehavior {
9 |
10 | public ArithmeticConditions arithmetic_conditions;
11 | public DeciderConditions decider_conditions;
12 | public ArrayList filters;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/DeciderConditions.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class DeciderConditions {
7 |
8 | public Signal first_signal;
9 | public Signal second_signal;
10 | public int constant;
11 | public String comparator;
12 | public Signal output_signal;
13 | public boolean copy_count_from_input;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Entity.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 |
8 | @JsonIgnoreProperties(ignoreUnknown = true)
9 | public class Entity implements FactorioEntity {
10 |
11 | private static int entity_id = 0;
12 |
13 | public int entity_number;
14 | public String name;
15 | public Position position;
16 | public int direction;
17 | public ControlBehavior control_behavior;
18 | public HashMap connections;
19 |
20 | public Entity(String name) {
21 | this.entity_number = entity_id++;
22 | this.name = name;
23 | }
24 |
25 |
26 | /**
27 | * Connects the entity with the entity associated with the given id.
28 | * @param circuitId if the wire should start at the input or output
29 | * @param color the wire color
30 | * @param entityId the entity to connect to
31 | * @param circuitIdDestination connect to the input or output of the entity
32 | */
33 | public void addConnection(String circuitId, String color, int entityId, int circuitIdDestination) {
34 | if (connections == null)
35 | connections = new HashMap<>();
36 | if (!connections.containsKey(circuitId))
37 | connections.put(circuitId, new Connection());
38 | if (color.equals("green")) {
39 | if (connections.get(circuitId).green == null)
40 | connections.get(circuitId).green = new ArrayList<>();
41 | connections.get(circuitId).green.add(new ConnectionDetail(entityId, circuitIdDestination));
42 | } else if (color.equals("red")) {
43 | if (connections.get(circuitId).red == null)
44 | connections.get(circuitId).red = new ArrayList<>();
45 | connections.get(circuitId).red.add(new ConnectionDetail(entityId, circuitIdDestination));
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/FactorioEntity.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | public interface FactorioEntity {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/FactorioEntityList.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import java.util.ArrayList;
4 |
5 | public class FactorioEntityList implements FactorioEntity {
6 |
7 | private ArrayList fel;
8 |
9 | public FactorioEntityList() {
10 | fel = new ArrayList<>();
11 | }
12 |
13 | public void add(FactorioEntity factorioEntity){
14 | fel.add(factorioEntity);
15 | }
16 |
17 | public void add(int index, FactorioEntity factorioEntity) {
18 | fel.add(index, factorioEntity);
19 | }
20 |
21 | @SuppressWarnings("unchecked")
22 | public ArrayList getList() {
23 | return (ArrayList) fel.clone();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Filter.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | public class Filter {
4 |
5 | public Signal signal;
6 | public int count;
7 | public int index;
8 |
9 | public Filter(Signal signal, int count, int index) {
10 | this.signal = signal;
11 | this.count = count;
12 | this.index = index;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Icon.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class Icon {
7 |
8 | public int index;
9 | public Signal signal;
10 |
11 | public Icon(int index, Signal signal) {
12 | this.index = index;
13 | this.signal = signal;
14 | }
15 |
16 |
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Position.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4 |
5 | @JsonIgnoreProperties(ignoreUnknown = true)
6 | public class Position {
7 |
8 | public double x;
9 | public double y;
10 |
11 | public Position(double x, double y) {
12 | this.x = x;
13 | this.y = y;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/entities/blueprint/Signal.java:
--------------------------------------------------------------------------------
1 | package entities.blueprint;
2 |
3 | import java.util.HashMap;
4 |
5 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6 |
7 | @JsonIgnoreProperties(ignoreUnknown = true)
8 | public class Signal {
9 | private static String[] types;
10 | private static HashMap nameType;
11 | private static HashMap aliases;
12 |
13 | static {
14 | types = new String[] {"item", "fluid", "virtual"};
15 | nameType = new HashMap<>();
16 | aliases = new HashMap<>();
17 |
18 | // TODO LOAD ALIASES AND VARIABLES FROM FILES
19 |
20 | // ALIASES
21 | aliases.put("a", "signal-A");
22 | aliases.put("b", "signal-B");
23 | aliases.put("c", "signal-C");
24 | aliases.put("d", "signal-D");
25 | aliases.put("e", "signal-E");
26 | aliases.put("f", "signal-F");
27 | aliases.put("g", "signal-G");
28 | aliases.put("h", "signal-H");
29 | aliases.put("i", "signal-I");
30 | aliases.put("j", "signal-J");
31 | aliases.put("k", "signal-K");
32 | aliases.put("l", "signal-L");
33 | aliases.put("m", "signal-M");
34 | aliases.put("n", "signal-N");
35 | aliases.put("o", "signal-O");
36 | aliases.put("p", "signal-P");
37 | aliases.put("q", "signal-Q");
38 | aliases.put("r", "signal-R");
39 | aliases.put("s", "signal-S");
40 | aliases.put("t", "signal-T");
41 | aliases.put("u", "signal-U");
42 | aliases.put("v", "signal-V");
43 | aliases.put("w", "signal-W");
44 | aliases.put("x", "signal-X");
45 | aliases.put("y", "signal-Y");
46 | aliases.put("z", "signal-Z");
47 |
48 |
49 | aliases.put("signal-a", "signal-A");
50 | aliases.put("signal-b", "signal-B");
51 | aliases.put("signal-c", "signal-C");
52 | aliases.put("signal-d", "signal-D");
53 | aliases.put("signal-e", "signal-E");
54 | aliases.put("signal-f", "signal-F");
55 | aliases.put("signal-g", "signal-G");
56 | aliases.put("signal-h", "signal-H");
57 | aliases.put("signal-i", "signal-I");
58 | aliases.put("signal-j", "signal-J");
59 | aliases.put("signal-k", "signal-K");
60 | aliases.put("signal-l", "signal-L");
61 | aliases.put("signal-m", "signal-M");
62 | aliases.put("signal-n", "signal-N");
63 | aliases.put("signal-o", "signal-O");
64 | aliases.put("signal-p", "signal-P");
65 | aliases.put("signal-q", "signal-Q");
66 | aliases.put("signal-r", "signal-R");
67 | aliases.put("signal-s", "signal-S");
68 | aliases.put("signal-t", "signal-T");
69 | aliases.put("signal-u", "signal-U");
70 | aliases.put("signal-v", "signal-V");
71 | aliases.put("signal-w", "signal-W");
72 | aliases.put("signal-x", "signal-X");
73 | aliases.put("signal-y", "signal-Y");
74 | aliases.put("signal-z", "signal-Z");
75 |
76 | aliases.put("red", "signal-red");
77 | aliases.put("green", "signal-green");
78 | aliases.put("blue", "signal-blue");
79 | aliases.put("yellow", "signal-yellow");
80 | aliases.put("pink", "signal-pink");
81 | aliases.put("cyan", "signal-cyan");
82 | aliases.put("white", "signal-white");
83 | aliases.put("grey", "signal-grey");
84 | aliases.put("black", "signal-black");
85 |
86 | // VIRTUAL
87 | nameType.put("signal-each", types[2]);
88 | nameType.put("signal-anything", types[2]);
89 | nameType.put("signal-everything", types[2]);
90 |
91 | nameType.put("signal-A", types[2]);
92 | nameType.put("signal-B", types[2]);
93 | nameType.put("signal-C", types[2]);
94 | nameType.put("signal-D", types[2]);
95 | nameType.put("signal-E", types[2]);
96 | nameType.put("signal-F", types[2]);
97 | nameType.put("signal-G", types[2]);
98 | nameType.put("signal-H", types[2]);
99 | nameType.put("signal-I", types[2]);
100 | nameType.put("signal-J", types[2]);
101 | nameType.put("signal-K", types[2]);
102 | nameType.put("signal-L", types[2]);
103 | nameType.put("signal-M", types[2]);
104 | nameType.put("signal-O", types[2]);
105 | nameType.put("signal-P", types[2]);
106 | nameType.put("signal-Q", types[2]);
107 | nameType.put("signal-R", types[2]);
108 | nameType.put("signal-S", types[2]);
109 | nameType.put("signal-T", types[2]);
110 | nameType.put("signal-U", types[2]);
111 | nameType.put("signal-V", types[2]);
112 | nameType.put("signal-W", types[2]);
113 | nameType.put("signal-X", types[2]);
114 | nameType.put("signal-Y", types[2]);
115 | nameType.put("signal-Z", types[2]);
116 |
117 | nameType.put("signal-0", types[2]);
118 | nameType.put("signal-1", types[2]);
119 | nameType.put("signal-2", types[2]);
120 | nameType.put("signal-3", types[2]);
121 | nameType.put("signal-4", types[2]);
122 | nameType.put("signal-6", types[2]);
123 | nameType.put("signal-7", types[2]);
124 | nameType.put("signal-8", types[2]);
125 | nameType.put("signal-9", types[2]);
126 |
127 | nameType.put("signal-red", types[2]);
128 | nameType.put("signal-green", types[2]);
129 | nameType.put("signal-blue", types[2]);
130 | nameType.put("signal-yellow", types[2]);
131 | nameType.put("signal-pink", types[2]);
132 | nameType.put("signal-cyan", types[2]);
133 | nameType.put("signal-white", types[2]);
134 | nameType.put("signal-grey", types[2]);
135 | nameType.put("signal-black", types[2]);
136 |
137 | // FLUIDS
138 | nameType.put("water", types[1]);
139 | nameType.put("crude-oil", types[1]);
140 | nameType.put("steam", types[1]);
141 | nameType.put("heavy-oil", types[1]);
142 | nameType.put("light-oil", types[1]);
143 | nameType.put("petroleum-gas", types[1]);
144 | nameType.put("sulfuric-acid", types[1]);
145 | nameType.put("lubricant", types[1]);
146 |
147 |
148 | // ITEMS
149 | //LOGISTICS
150 | nameType.put("wooden-chest", types[0]);
151 | nameType.put("iron-chest", types[0]);
152 | nameType.put("steel-chest", types[0]);
153 | nameType.put("storage-tank", types[0]);
154 |
155 | nameType.put("transport-belt", types[0]);
156 | nameType.put("fast-transport-belt", types[0]);
157 | nameType.put("express-transport-belt", types[0]);
158 | nameType.put("underground-belt", types[0]);
159 | nameType.put("fast-underground-belt", types[0]);
160 | nameType.put("express-underground-belt", types[0]);
161 | nameType.put("splitter", types[0]);
162 | nameType.put("fast-splitter", types[0]);
163 | nameType.put("express-splitter", types[0]);
164 |
165 | nameType.put("burner-inserter", types[0]);
166 | nameType.put("inserter", types[0]);
167 | nameType.put("long-handed-inserter", types[0]);
168 | nameType.put("fast-inserter", types[0]);
169 | nameType.put("filter-inserter", types[0]);
170 | nameType.put("stack-inserter", types[0]);
171 | nameType.put("stack-filter-inserter", types[0]);
172 |
173 |
174 | nameType.put("small-electric-pole", types[0]);
175 | nameType.put("medium-electric-pole", types[0]);
176 | nameType.put("big-electric-pole", types[0]);
177 | nameType.put("substation", types[0]);
178 | nameType.put("pipe", types[0]);
179 | nameType.put("pipe-to-ground", types[0]);
180 | nameType.put("pump", types[0]);
181 |
182 | nameType.put("rail", types[0]);
183 | nameType.put("train-stop", types[0]);
184 | nameType.put("rail-signal", types[0]);
185 | nameType.put("rail-chain-signal", types[0]);
186 | nameType.put("locomotive", types[0]);
187 | nameType.put("cargo-wagon", types[0]);
188 | nameType.put("fluid-wagon", types[0]);
189 | nameType.put("car", types[0]);
190 | nameType.put("tank", types[0]);
191 |
192 | nameType.put("logistic-robot", types[0]);
193 | nameType.put("construction-robot", types[0]);
194 | nameType.put("logistic-active-provider-chest", types[0]);
195 | nameType.put("logistic-passive-provider-chest", types[0]);
196 | nameType.put("logistic-requester-chest", types[0]);
197 | nameType.put("logistic-storage-chest", types[0]);
198 | nameType.put("roboport", types[0]);
199 |
200 | nameType.put("lamp", types[0]);
201 | nameType.put("red-wire", types[0]);
202 | nameType.put("green-wire", types[0]);
203 | nameType.put("arithmetic-combinator", types[0]);
204 | nameType.put("decider-combinator", types[0]);
205 | nameType.put("constant-combinator", types[0]);
206 | nameType.put("power-switch", types[0]);
207 | nameType.put("programmable-speaker", types[0]);
208 |
209 | nameType.put("stone-brick", types[0]);
210 | nameType.put("concrete", types[0]);
211 | nameType.put("hazard-concrete", types[0]);
212 | nameType.put("landfill", types[0]);
213 |
214 | // PRODUCTION
215 | nameType.put("iron-axe", types[0]);
216 | nameType.put("steel-axe", types[0]);
217 | nameType.put("repair-pack", types[0]);
218 | nameType.put("blueprint", types[0]);
219 | nameType.put("deconstruction-planner", types[0]);
220 | nameType.put("blueprint-book", types[0]);
221 |
222 | nameType.put("boiler", types[0]);
223 | nameType.put("steam-engine", types[0]);
224 | nameType.put("steam-turbine", types[0]);
225 | nameType.put("solar-panel", types[0]);
226 | nameType.put("accumulator", types[0]);
227 | nameType.put("nuclear-reactor", types[0]);
228 | nameType.put("heat-exchanger", types[0]);
229 | nameType.put("heat-pipe", types[0]);
230 |
231 | nameType.put("burner-mining-drill", types[0]);
232 | nameType.put("electric-mining-drill", types[0]);
233 | nameType.put("offshore-pump", types[0]);
234 | nameType.put("pumpjack", types[0]);
235 |
236 | nameType.put("stone-furnace", types[0]);
237 | nameType.put("steel-furnace", types[0]);
238 | nameType.put("electric-furnace", types[0]);
239 |
240 | nameType.put("assembling-machine-1", types[0]);
241 | nameType.put("assembling-machine-2", types[0]);
242 | nameType.put("assembling-machine-3", types[0]);
243 | nameType.put("oil-refinery", types[0]);
244 | nameType.put("chemical-plant", types[0]);
245 | nameType.put("centrifuge", types[0]);
246 | nameType.put("lab", types[0]);
247 |
248 | nameType.put("beacon", types[0]);
249 | nameType.put("speed-module-1", types[0]);
250 | nameType.put("speed-module-2", types[0]);
251 | nameType.put("speed-module-3", types[0]);
252 | nameType.put("efficiency-module-1", types[0]);
253 | nameType.put("efficiency-module-2", types[0]);
254 | nameType.put("efficiency-module-3", types[0]);
255 | nameType.put("productivity-module-1", types[0]);
256 | nameType.put("productivity-module-2", types[0]);
257 | nameType.put("productivity-module-3", types[0]);
258 |
259 | // INTERMEDIATE PRODUCTS
260 | nameType.put("raw-wood", types[0]);
261 | nameType.put("coal", types[0]);
262 | nameType.put("stone", types[0]);
263 | nameType.put("iron-ore", types[0]);
264 | nameType.put("copper-ore", types[0]);
265 | nameType.put("uranium-ore", types[0]);
266 | nameType.put("raw-fish", types[0]);
267 |
268 | nameType.put("wood", types[0]);
269 | nameType.put("iron-plate", types[0]);
270 | nameType.put("copper-plate", types[0]);
271 | nameType.put("solid-fuel", types[0]);
272 | nameType.put("steel-plate", types[0]);
273 | nameType.put("sulfur", types[0]);
274 | nameType.put("plastic-bar", types[0]);
275 |
276 | nameType.put("crude-oil-barrel", types[0]);
277 | nameType.put("heavy-oil-barrel", types[0]);
278 | nameType.put("light-oil-barrel", types[0]);
279 | nameType.put("lubricant-barrel", types[0]);
280 | nameType.put("petroleum-gas-barrel", types[0]);
281 | nameType.put("sulfuric-acid-barrel", types[0]);
282 | nameType.put("water-barrel", types[0]);
283 |
284 | nameType.put("copper-cable", types[0]);
285 | nameType.put("iron-stick", types[0]);
286 | nameType.put("iron-gear-wheel", types[0]);
287 | nameType.put("empty-barrel", types[0]);
288 | nameType.put("electronic-circuit", types[0]);
289 | nameType.put("advanced-circuit", types[0]);
290 | nameType.put("processing-unit", types[0]);
291 | nameType.put("engine-unit", types[0]);
292 | nameType.put("electric-engine-unit", types[0]);
293 | nameType.put("battery", types[0]);
294 |
295 | nameType.put("explosives", types[0]);
296 | nameType.put("flying-robot-frame", types[0]);
297 | nameType.put("low-density-structure", types[0]);
298 | nameType.put("rocket-fuel", types[0]);
299 | nameType.put("rocket-control-unit", types[0]);
300 | nameType.put("satellite", types[0]);
301 | nameType.put("uranium-235", types[0]);
302 | nameType.put("uranium-238", types[0]);
303 | nameType.put("uranium-fuel-cell", types[0]);
304 | nameType.put("used-up-uranium-fuel-cell", types[0]);
305 |
306 | nameType.put("science-pack-1", types[0]);
307 | nameType.put("science-pack-2", types[0]);
308 | nameType.put("science-pack-3", types[0]);
309 | nameType.put("military-science-pack", types[0]);
310 | nameType.put("production-science-pack", types[0]);
311 | nameType.put("high-tech-science-pack", types[0]);
312 | nameType.put("space-science-pack", types[0]);
313 |
314 | nameType.put("pistol", types[0]);
315 | nameType.put("submachine-gun", types[0]);
316 | nameType.put("shotgun", types[0]);
317 | nameType.put("combat-shotgun", types[0]);
318 | nameType.put("rocket-launcher", types[0]);
319 | nameType.put("flamethrower", types[0]);
320 | nameType.put("land-mine", types[0]);
321 | nameType.put("firearm-magazine", types[0]);
322 | nameType.put("piercing-rounds-magazine", types[0]);
323 | nameType.put("uranium-rounds-magazine", types[0]);
324 | nameType.put("shotgun-shells", types[0]);
325 | nameType.put("piercing-shotgun-shells", types[0]);
326 | nameType.put("uranium-shotgun-shells", types[0]);
327 | nameType.put("cannon-shell", types[0]);
328 | nameType.put("explosive-cannon-shell", types[0]);
329 | nameType.put("uranium-cannon-shell", types[0]);
330 | nameType.put("explosive-uranium-cannon-shell", types[0]);
331 | nameType.put("rocket", types[0]);
332 | nameType.put("explosive-rocket", types[0]);
333 | nameType.put("atomic-bomb", types[0]);
334 | nameType.put("flamethrower-ammo", types[0]);
335 |
336 | nameType.put("grenade", types[0]);
337 | nameType.put("cluster-grenade", types[0]);
338 | nameType.put("poison-capsule", types[0]);
339 | nameType.put("slowdown-capsule", types[0]);
340 | nameType.put("defender-capsule", types[0]);
341 | nameType.put("distractor-capsule", types[0]);
342 | nameType.put("destroyer-capsule", types[0]);
343 | nameType.put("discharge-defense-remote", types[0]);
344 |
345 | nameType.put("light-armor", types[0]);
346 | nameType.put("heavy-armor", types[0]);
347 | nameType.put("modular-armor", types[0]);
348 | nameType.put("power-armor", types[0]);
349 | nameType.put("power-armor-mk2", types[0]);
350 | nameType.put("portable-solar-panel", types[0]);
351 | nameType.put("portable-fusion-reactor", types[0]);
352 | nameType.put("energy-shield", types[0]);
353 | nameType.put("energy-shield-mk2", types[0]);
354 | nameType.put("battery", types[0]);
355 | nameType.put("battery-mk2", types[0]);
356 | nameType.put("personal-laser-defense", types[0]);
357 | nameType.put("discharge-defense", types[0]);
358 | nameType.put("exoskeleton", types[0]);
359 | nameType.put("personal-roboport", types[0]);
360 | nameType.put("personal-roboport-mk2", types[0]);
361 | nameType.put("nightvision", types[0]);
362 |
363 | nameType.put("stone-wall", types[0]);
364 | nameType.put("gate", types[0]);
365 | nameType.put("gun-turret", types[0]);
366 | nameType.put("laser-turret", types[0]);
367 | nameType.put("flamethrower-turret", types[0]);
368 | nameType.put("radar", types[0]);
369 | nameType.put("rocket-silo", types[0]);
370 | }
371 |
372 | public String type;
373 | public String name;
374 |
375 | public Signal (String name) {
376 | name = convertAlias(name);
377 | if (!nameType.containsKey(name))
378 | System.err.println("Signal " + name + " is unknown!");
379 | this.type = nameType.get(name);
380 | this.name = name;
381 | }
382 |
383 | public static boolean variableExists(String var) {
384 | return nameType.containsKey(convertAlias(var));
385 | }
386 |
387 | public static void addAlias(String oldVar, String newVar) {
388 | if (newVar != oldVar)
389 | aliases.put(newVar, oldVar);
390 | }
391 |
392 | private static String convertAlias(String var) {
393 | while (aliases.containsKey(var)) {
394 | var = aliases.get(var);
395 | }
396 | return var;
397 | }
398 |
399 | }
400 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/ArithmeticCombinator.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import entities.blueprint.ArithmeticConditions;
4 | import entities.blueprint.ControlBehavior;
5 | import entities.blueprint.Entity;
6 | import entities.blueprint.Position;
7 | import entities.blueprint.Signal;
8 |
9 | public class ArithmeticCombinator implements Combinator {
10 |
11 | private Entity entity;
12 |
13 | public CompilerEntity leftEntity;
14 | public CompilerEntity rightEntity;
15 | public String operation;
16 | public CompilerEntity outputEntity;
17 | public String outputSignal;
18 |
19 |
20 | public ArithmeticCombinator() {
21 | entity = new Entity("arithmetic-combinator");
22 | }
23 |
24 | @Override
25 | public Entity getEntity(double x, double y) {
26 | ArithmeticConditions arithmetic_conditions = new ArithmeticConditions();
27 |
28 | if (leftEntity.getClass() == Variable.class) {
29 | Variable var = (Variable) leftEntity;
30 | arithmetic_conditions.first_signal = new Signal(var.getVariable());
31 | } else if (leftEntity.getClass() == ArithmeticCombinator.class) {
32 | ArithmeticCombinator ac = (ArithmeticCombinator) leftEntity;
33 | arithmetic_conditions.first_signal = new Signal(ac.outputSignal);
34 | } else if (leftEntity.getClass() == ConstantCombinator.class) {
35 | ConstantCombinator cc = (ConstantCombinator) leftEntity;
36 | cc.addConnectionOut("green", entity.entity_number, 1);
37 | arithmetic_conditions.first_signal = cc.getSignal();
38 | }
39 |
40 | arithmetic_conditions.operation = operation;
41 |
42 | if (rightEntity.getClass() == Variable.class) {
43 | Variable var = (Variable) rightEntity;
44 | arithmetic_conditions.second_signal = new Signal(var.getVariable());
45 | } else if (rightEntity.getClass() == Number.class) {
46 | Number number = (Number) rightEntity;
47 | arithmetic_conditions.constant = number.getValue();
48 | } else if (rightEntity.getClass() == ArithmeticCombinator.class) {
49 | ArithmeticCombinator ac = (ArithmeticCombinator) rightEntity;
50 | arithmetic_conditions.second_signal = new Signal(ac.outputSignal);
51 | }
52 |
53 | arithmetic_conditions.output_signal = new Signal(outputSignal);
54 |
55 | if(outputEntity != null) {
56 | if (outputEntity.getClass() == ArithmeticCombinator.class) {
57 | ArithmeticCombinator ac = (ArithmeticCombinator) outputEntity;
58 | entity.addConnection("2", "green", ac.getId(), 1);
59 | }
60 | }
61 |
62 | entity.control_behavior = new ControlBehavior();
63 | entity.control_behavior.arithmetic_conditions = arithmetic_conditions;
64 | entity.position = new Position(x, y+0.5);
65 | entity.direction = 4;
66 |
67 | return entity;
68 | }
69 |
70 | @Override
71 | public void traverseEntities(EntityGatherer eg) {
72 |
73 | // CREATE CONNECTION
74 | if (leftEntity.getClass() == Variable.class || rightEntity.getClass() == Variable.class) {
75 | entity.addConnection("1", "red", eg.lastInputEntity.entity_number, 1);
76 | eg.lastInputEntity = entity;
77 | }
78 |
79 | // ADD ENTITIES
80 | if (leftEntity.getClass() == ArithmeticCombinator.class || leftEntity.getClass() == ConstantCombinator.class || leftEntity.getClass() == DeciderCombinator.class) {
81 | Combinator combinatorLeft = (Combinator) leftEntity;
82 | eg.entities.add(combinatorLeft.getEntity(eg.offsetX++, eg.offsetY));
83 | }
84 |
85 | if (rightEntity.getClass() == ArithmeticCombinator.class || rightEntity.getClass() == ConstantCombinator.class || rightEntity.getClass() == DeciderCombinator.class) {
86 | Combinator combinatorRight = (Combinator) rightEntity;
87 | eg.entities.add(combinatorRight.getEntity(eg.offsetX++, eg.offsetY));
88 | }
89 |
90 | // TRAVERSE ENTITIES
91 | if (leftEntity.getClass() == ArithmeticCombinator.class || leftEntity.getClass() == ConstantCombinator.class || leftEntity.getClass() == DeciderCombinator.class) {
92 | Combinator combinatorLeft = (Combinator) leftEntity;
93 | combinatorLeft.traverseEntities(eg);
94 | }
95 |
96 | if (rightEntity.getClass() == ArithmeticCombinator.class || rightEntity.getClass() == ConstantCombinator.class || rightEntity.getClass() == DeciderCombinator.class) {
97 | Combinator combinatorRight = (Combinator) rightEntity;
98 | combinatorRight.traverseEntities(eg);
99 | }
100 |
101 | }
102 |
103 |
104 | @Override
105 | public int getId() {
106 | return entity.entity_number;
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/Combinator.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import entities.blueprint.Entity;
4 |
5 | public interface Combinator extends CompilerEntity {
6 |
7 | public Entity getEntity(double x, double y);
8 |
9 | public void traverseEntities(EntityGatherer eg);
10 |
11 | public int getId();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/CompilerEntity.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | public interface CompilerEntity {
4 |
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/ConstantCombinator.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | import entities.blueprint.Connection;
7 | import entities.blueprint.ConnectionDetail;
8 | import entities.blueprint.ControlBehavior;
9 | import entities.blueprint.Entity;
10 | import entities.blueprint.Filter;
11 | import entities.blueprint.Position;
12 | import entities.blueprint.Signal;
13 |
14 | public class ConstantCombinator implements Combinator {
15 |
16 | private Entity entity;
17 |
18 | private ArrayList filters;
19 | private Connection connections;
20 |
21 | public ConstantCombinator() {
22 | entity = new Entity("constant-combinator");
23 | filters = new ArrayList<>();
24 | }
25 |
26 | /**
27 | * Adds a new signal with the given amount to the constant combinator.
28 | * @param name the signal name
29 | * @param amount the signal value
30 | */
31 | public void addSignal(String name, int amount) {
32 | filters.add(new Filter(new Signal(name), amount, filters.size()+1));
33 | }
34 |
35 | /**
36 | *
37 | * @return the first signal in the constant combinator
38 | */
39 | public Signal getSignal() {
40 | return filters.get(0).signal;
41 | }
42 |
43 | /**
44 | * Connects the constant combinator output with the entity associated with the given entity.
45 | * @param color the wire color
46 | * @param entityId the entity to connect to
47 | * @param circuitId connect to the input or output of the entity
48 | */
49 | public void addConnectionOut(String color, int entityId, int circuitId) {
50 | if (connections == null)
51 | connections = new Connection();
52 | if (color.equals("green")) {
53 | if (connections.green == null)
54 | connections.green = new ArrayList<>();
55 | connections.green.add(new ConnectionDetail(entityId, circuitId));
56 | } else if (color.equals("red")) {
57 | if (connections.red == null)
58 | connections.red = new ArrayList<>();
59 | connections.red.add(new ConnectionDetail(entityId, circuitId));
60 | }
61 | }
62 |
63 | /**
64 | * Returns the blueprint entity version with the information available.
65 | * @return the blueprint entity
66 | */
67 | @Override
68 | public Entity getEntity(double x, double y) {
69 | if (filters.size() > 0) {
70 | entity.control_behavior = new ControlBehavior();
71 | entity.control_behavior.filters = this.filters;
72 | }
73 | if (connections != null) {
74 | entity.connections = new HashMap<>();
75 | entity.connections.put("1", connections);
76 | }
77 |
78 | entity.position = new Position(x, y);
79 |
80 | return entity;
81 | }
82 |
83 |
84 |
85 | @Override
86 | public void traverseEntities(EntityGatherer eg) {
87 | // TODO Auto-generated method stub
88 |
89 | }
90 |
91 | @Override
92 | public int getId() {
93 | return entity.entity_number;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/DeciderCombinator.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import entities.blueprint.Entity;
4 | import entities.blueprint.Position;
5 |
6 | public class DeciderCombinator implements Combinator {
7 |
8 | private Entity entity;
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | /**
17 | *
18 | * @return returns the unique entity identifier value
19 | */
20 | @Override
21 | public int getId() {
22 | return entity.entity_number;
23 | }
24 |
25 | @Override
26 | public Entity getEntity(double x, double y) {
27 | // TODO Auto-generated method stub
28 | entity.position = new Position(x, y+0.5);
29 | return null;
30 | }
31 |
32 | @Override
33 | public void traverseEntities(EntityGatherer eg) {
34 | // TODO Auto-generated method stub
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/EntityGatherer.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import java.util.ArrayList;
4 |
5 | import entities.blueprint.Entity;
6 | import entities.blueprint.Position;
7 |
8 | public class EntityGatherer {
9 |
10 | public int offsetX;
11 | public int offsetY;
12 | public ArrayList entities;
13 | public PowerPoleType pole;
14 | public Entity lastOutputEntity;
15 | public Entity lastInputEntity;
16 | private int powerPolesPlaced;
17 | private int powerPoleOffset;
18 |
19 | public EntityGatherer() {
20 | this.offsetX = 0;
21 | this.offsetY = 0;
22 | this.entities = new ArrayList<>();
23 | this.pole = PowerPole.powerPoleTypes.get(PowerPole.powerPole);
24 | this.lastOutputEntity = null;
25 | this.powerPolesPlaced = 0;
26 | this.powerPoleOffset = pole.maxSpace/2 + ((PowerPole.powerPole.equals("medium")) ? 1 : 0);
27 | }
28 |
29 | public void checkForPowerPole() {
30 | // TODO improve power pole horizontal placement
31 | if (offsetY == powerPoleOffset + powerPolesPlaced * (pole.maxSpace+pole.size)) {
32 | offsetY += pole.size;
33 | powerPolesPlaced++;
34 | }
35 | if (offsetY == powerPolesPlaced * (pole.maxSpace+pole.size)) {
36 | Entity entity = new Entity(pole.name);
37 | entity.position = new Position(pole.maxSpace/2, powerPoleOffset + powerPolesPlaced * (pole.maxSpace+pole.size));
38 | entities.add(entity);
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/Number.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | public class Number implements CompilerEntity {
4 |
5 | private int value;
6 |
7 | public Number(int value) {
8 | this.value = value;
9 | }
10 |
11 | public int getValue() {
12 | return value;
13 | }
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/PowerPole.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import java.util.HashMap;
4 |
5 | public class PowerPole implements CompilerEntity {
6 |
7 |
8 | public static String powerPole;
9 | public static HashMap powerPoleTypes;
10 |
11 | static {
12 | powerPole = "small";
13 |
14 | powerPoleTypes = new HashMap<>();
15 |
16 | PowerPoleType small = new PowerPoleType("small-electric-pole", 4, 1);
17 | PowerPoleType medium = new PowerPoleType("medium-electric-pole", 6, 1);
18 | // PowerPoleType big = new PowerPoleType("big-electric-pole", 2, 2);
19 | PowerPoleType substation = new PowerPoleType("substation", 16, 2);
20 |
21 |
22 | powerPoleTypes.put("small", small);
23 | powerPoleTypes.put("SMALL", small);
24 | powerPoleTypes.put("medium", medium);
25 | powerPoleTypes.put("MEDIUM", medium);
26 | // powerPoleTypes.put("big", big);
27 | // powerPoleTypes.put("BIG", big);
28 | powerPoleTypes.put("substation", substation);
29 | powerPoleTypes.put("SUBSTATION", substation);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/PowerPoleType.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | public class PowerPoleType {
4 |
5 | public String name;
6 | public int maxSpace;
7 | public int size;
8 |
9 | public PowerPoleType(String name, int maxSpace, int size) {
10 | this.name = name;
11 | this.maxSpace = maxSpace;
12 | this.size = size;
13 | }
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/Statement.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | public interface Statement extends CompilerEntity {
4 |
5 |
6 | public void getEntities(EntityGatherer eg);
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/StatementAdd.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import entities.blueprint.Entity;
4 |
5 | public class StatementAdd implements Statement {
6 |
7 | private Variable variable;
8 | private CompilerEntity expression;
9 |
10 | public StatementAdd(Variable variable, CompilerEntity expression) {
11 | this.variable = variable;
12 | this.expression = expression;
13 | }
14 |
15 | @Override
16 | public void getEntities(EntityGatherer eg) {
17 |
18 | ArithmeticCombinator acEach = new ArithmeticCombinator();
19 | acEach.leftEntity = new Variable("signal-each");
20 | acEach.operation = "+";
21 | acEach.rightEntity = new Number(0);
22 | acEach.outputSignal = "signal-each";
23 | Entity entityAcEach = acEach.getEntity(0, eg.offsetY);
24 |
25 | if (eg.lastOutputEntity != null) {
26 | eg.lastOutputEntity.addConnection("2", "red", entityAcEach.entity_number, 1);
27 | }
28 |
29 | eg.lastOutputEntity = entityAcEach;
30 |
31 | eg.entities.add(entityAcEach);
32 |
33 |
34 | if (expression.getClass() == Number.class) {
35 | Number number = (Number) expression;
36 | ConstantCombinator cc = new ConstantCombinator();
37 | cc.addSignal(variable.getVariable(), number.getValue());
38 | cc.addConnectionOut("red", acEach.getId(), 2);
39 | eg.entities.add(cc.getEntity(1, eg.offsetY+1));
40 |
41 | } else if (expression.getClass() == Variable.class) {
42 | Variable var = (Variable) expression;
43 | ArithmeticCombinator ac = new ArithmeticCombinator();
44 | ac.leftEntity = var;
45 | ac.operation = "+";
46 | ac.rightEntity = new Number(0);
47 | ac.outputSignal = variable.getVariable();
48 | Entity entity = ac.getEntity(1, eg.offsetY);
49 | entity.addConnection("1", "red", entityAcEach.entity_number, 1);
50 | entity.addConnection("2", "red", entityAcEach.entity_number, 2);
51 | eg.entities.add(entity);
52 |
53 | } else if (expression.getClass() == ArithmeticCombinator.class) {
54 | ArithmeticCombinator ac = (ArithmeticCombinator) expression;
55 | ac.outputSignal = variable.getVariable();
56 | Entity entity = ac.getEntity(1, eg.offsetY);
57 | entity.addConnection("1", "red", entityAcEach.entity_number, 1);
58 | entity.addConnection("2", "red", entityAcEach.entity_number, 2);
59 | eg.entities.add(entity);
60 | eg.offsetX = 2;
61 | eg.lastInputEntity = entity;
62 | ac.traverseEntities(eg);
63 |
64 | } else {
65 | System.err.println("weird error");
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/StatementList.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import java.util.ArrayList;
4 |
5 |
6 | public class StatementList implements CompilerEntity {
7 |
8 |
9 | private ArrayList statements;
10 |
11 |
12 | public StatementList () {
13 | statements = new ArrayList<>();
14 | }
15 |
16 | public void addStatement(int i, Statement statement) {
17 | statements.add(i, statement);
18 | }
19 |
20 | public void getEntities(EntityGatherer entityGatherer) {
21 | for (Statement statement : statements) {
22 | if (statement.getClass() != StatementNone.class) {
23 | entityGatherer.checkForPowerPole();
24 | statement.getEntities(entityGatherer);
25 | entityGatherer.offsetY += 2;
26 | }
27 | }
28 |
29 |
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/StatementNone.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | public class StatementNone implements Statement {
4 |
5 | @Override
6 | public void getEntities(EntityGatherer eg) {
7 | // nothing
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/StatementOverwrite.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import entities.blueprint.Entity;
4 |
5 | public class StatementOverwrite implements Statement {
6 |
7 | private Variable variable;
8 | private CompilerEntity expression;
9 |
10 | public StatementOverwrite(Variable variable, CompilerEntity expression) {
11 | this.variable = variable;
12 | this.expression = expression;
13 | }
14 |
15 | @Override
16 | public void getEntities(EntityGatherer eg) {
17 |
18 | ArithmeticCombinator acEach = new ArithmeticCombinator();
19 | ArithmeticCombinator acNullifier = new ArithmeticCombinator();
20 |
21 | acEach.leftEntity = new Variable("signal-each");
22 | acEach.operation = "+";
23 | acEach.rightEntity = new Number(0);
24 | acEach.outputSignal = "signal-each";
25 |
26 | acNullifier.leftEntity = variable;
27 | acNullifier.operation = "*";
28 | acNullifier.rightEntity = new Number(-1);
29 | acNullifier.outputSignal = variable.getVariable();
30 |
31 | Entity entityAcEach = acEach.getEntity(0, eg.offsetY);
32 | Entity entityAcNullifier = acNullifier.getEntity(1, eg.offsetY);
33 |
34 | entityAcEach.addConnection("1", "red", entityAcNullifier.entity_number, 1);
35 | entityAcEach.addConnection("2", "red", entityAcNullifier.entity_number, 2);
36 |
37 | if (eg.lastOutputEntity != null) {
38 | eg.lastOutputEntity.addConnection("2", "red", entityAcEach.entity_number, 1);
39 | }
40 |
41 | eg.lastOutputEntity = entityAcEach;
42 |
43 | eg.entities.add(entityAcEach);
44 | eg.entities.add(entityAcNullifier);
45 |
46 | if (expression.getClass() == Number.class) {
47 | // constant combinator
48 | Number number = (Number) expression;
49 | ConstantCombinator cc = new ConstantCombinator();
50 | cc.addSignal(variable.getVariable(), number.getValue());
51 | cc.addConnectionOut("red", acNullifier.getId(), 2);
52 | Entity entityCc = cc.getEntity(2,eg.offsetY+1);
53 | eg.entities.add(entityCc);
54 |
55 | } else {
56 | ArithmeticCombinator ac = null;
57 | if (expression.getClass() == Variable.class) {
58 | // arithmetic combinator var + 0
59 | Variable var = (Variable) expression;
60 | ac = new ArithmeticCombinator();
61 | ac.leftEntity = var;
62 | ac.operation = "+";
63 | ac.rightEntity = new Number(0);
64 |
65 | } else { // ARITHMETICCOMBINATOR
66 | ac = (ArithmeticCombinator) expression;
67 | }
68 | ac.outputSignal = variable.getVariable();
69 | Entity entityCombinator = ac.getEntity(2, eg.offsetY);
70 | entityCombinator.addConnection("1", "red", entityAcNullifier.entity_number, 1);
71 | entityCombinator.addConnection("2", "red", entityAcNullifier.entity_number, 2);
72 | eg.entities.add(entityCombinator);
73 | eg.offsetX = 3;
74 | eg.lastInputEntity = entityCombinator;
75 | ac.traverseEntities(eg);
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/StatementSub.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | import entities.blueprint.Entity;
4 | import factorioscript.CompilerVisitor;
5 |
6 | public class StatementSub implements Statement {
7 |
8 | private Variable variable;
9 | private CompilerEntity expression;
10 |
11 | public StatementSub(Variable variable, CompilerEntity expression) {
12 | this.variable = variable;
13 | this.expression = expression;
14 | }
15 |
16 | @Override
17 | public void getEntities(EntityGatherer eg) {
18 |
19 | ArithmeticCombinator acEach = new ArithmeticCombinator();
20 | acEach.leftEntity = new Variable("signal-each");
21 | acEach.operation = "+";
22 | acEach.rightEntity = new Number(0);
23 | acEach.outputSignal = "signal-each";
24 | Entity entityAcEach = acEach.getEntity(0, eg.offsetY);
25 |
26 | if (eg.lastOutputEntity != null) {
27 | eg.lastOutputEntity.addConnection("2", "red", entityAcEach.entity_number, 1);
28 | }
29 |
30 | eg.lastOutputEntity = entityAcEach;
31 |
32 | eg.entities.add(entityAcEach);
33 |
34 |
35 | if (expression.getClass() == Number.class) {
36 | Number number = (Number) expression;
37 | ConstantCombinator cc = new ConstantCombinator();
38 | cc.addSignal(variable.getVariable(), -1*number.getValue());
39 | cc.addConnectionOut("red", acEach.getId(), 2);
40 | eg.entities.add(cc.getEntity(1, eg.offsetY+1));
41 |
42 | } else if (expression.getClass() == Variable.class) {
43 | Variable var = (Variable) expression;
44 | ArithmeticCombinator ac = new ArithmeticCombinator();
45 | ac.leftEntity = var;
46 | ac.operation = "*";
47 | ac.rightEntity = new Number(-1);
48 | ac.outputSignal = variable.getVariable();
49 | Entity entity = ac.getEntity(1, eg.offsetY);
50 | entity.addConnection("1", "red", entityAcEach.entity_number, 1);
51 | entity.addConnection("2", "red", entityAcEach.entity_number, 2);
52 | eg.entities.add(entity);
53 |
54 | } else if (expression.getClass() == ArithmeticCombinator.class) {
55 | ArithmeticCombinator acNullifier = new ArithmeticCombinator();
56 |
57 | acNullifier.leftEntity = variable;
58 | acNullifier.operation = "*";
59 | acNullifier.rightEntity = new Number(-1);
60 | acNullifier.outputSignal = variable.getVariable();
61 |
62 | Entity entityAcNullifier = acNullifier.getEntity(1, eg.offsetY);
63 |
64 | entityAcEach.addConnection("1", "red", entityAcNullifier.entity_number, 1);
65 | entityAcEach.addConnection("2", "red", entityAcNullifier.entity_number, 2);
66 |
67 | eg.entities.add(entityAcNullifier);
68 |
69 |
70 | ArithmeticCombinator ac = new ArithmeticCombinator();
71 | ArithmeticCombinator acExpression = (ArithmeticCombinator) expression;
72 | acExpression.outputSignal = CompilerVisitor.standard_right;
73 | acExpression.outputEntity = ac;
74 | ac.leftEntity = variable;
75 | ac.operation = "-";
76 | ac.rightEntity = expression;
77 | ac.outputSignal = variable.getVariable();
78 | Entity entity = ac.getEntity(2, eg.offsetY);
79 | entity.addConnection("1", "red", entityAcNullifier.entity_number, 1);
80 | entity.addConnection("2", "red", entityAcNullifier.entity_number, 2);
81 | eg.entities.add(entity);
82 | eg.offsetX = 3;
83 |
84 |
85 | eg.lastInputEntity = entity;
86 | ac.traverseEntities(eg);
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/entities/compiler/Variable.java:
--------------------------------------------------------------------------------
1 | package entities.compiler;
2 |
3 | public class Variable implements CompilerEntity {
4 |
5 | private String name;
6 |
7 | public Variable (String name) {
8 | this.name = name;
9 | }
10 |
11 | public String getVariable() {
12 | return name;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/factorioscript/App.java:
--------------------------------------------------------------------------------
1 | package factorioscript;
2 |
3 | import java.io.BufferedWriter;
4 | import java.io.ByteArrayInputStream;
5 | import java.io.ByteArrayOutputStream;
6 | import java.io.File;
7 | import java.io.FileNotFoundException;
8 | import java.io.FileOutputStream;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 | import java.io.OutputStream;
12 | import java.io.OutputStreamWriter;
13 | import java.io.UnsupportedEncodingException;
14 | import java.io.Writer;
15 | import java.nio.file.Files;
16 | import java.nio.file.Paths;
17 | import java.nio.file.StandardOpenOption;
18 | import java.util.Base64;
19 | import java.util.zip.DeflaterOutputStream;
20 | import java.util.zip.InflaterInputStream;
21 |
22 | import org.antlr.v4.runtime.ANTLRInputStream;
23 | import org.antlr.v4.runtime.CharStream;
24 | import org.antlr.v4.runtime.CommonTokenStream;
25 |
26 | import com.fasterxml.jackson.annotation.JsonInclude.Include;
27 | import com.fasterxml.jackson.core.JsonProcessingException;
28 | import com.fasterxml.jackson.databind.ObjectMapper;
29 |
30 | import antlr.FactorioScriptLexer;
31 | import antlr.FactorioScriptParser;
32 | import entities.blueprint.Blueprint;
33 | import entities.blueprint.BlueprintRoot;
34 | import entities.blueprint.Entity;
35 | import entities.blueprint.Icon;
36 | import entities.blueprint.Signal;
37 | import entities.compiler.CompilerEntity;
38 | import entities.compiler.EntityGatherer;
39 | import entities.compiler.StatementList;
40 |
41 | public class App {
42 |
43 | public static void main(String[] args) {
44 |
45 | System.out.println();
46 | System.out.println("\tFactorioScript v0.1.1");
47 | System.out.println("\tby unobtanium");
48 | System.out.println();
49 | // READ CODE IN FROM FILE
50 | System.out.println("\tReading input file: " + args[0]);
51 | String code = "";
52 | try {
53 | byte[] encoded = Files.readAllBytes(Paths.get(args[0]));
54 | code = new String(encoded, "UTF-8");
55 | } catch (IOException e) {
56 | System.err.println("ERROR! While reading file.");
57 | e.printStackTrace();
58 | return;
59 | }
60 |
61 | if (code.equals("")) {
62 | System.out.println("\tNo code available!");
63 | return;
64 | }
65 |
66 | // SEND CODE TO ANTLR LEXER AND PARSER
67 | System.out.println("\tDoing magic!");
68 | CharStream charStream = null;
69 | charStream = new ANTLRInputStream(code);
70 | FactorioScriptLexer lexer = new FactorioScriptLexer(charStream);
71 | CommonTokenStream tokens = new CommonTokenStream(lexer);
72 | FactorioScriptParser parser = new FactorioScriptParser(tokens);
73 |
74 | // SEND PARSETREE TO VISITOR
75 | System.out.println("\tMore magic!");
76 | CompilerVisitor compilerVisitor = new CompilerVisitor();
77 | CompilerEntity compilerEntity = compilerVisitor.visit(parser.statementList());
78 |
79 | // EXTRACT BLUEPRINT ENTITIES FROM COMPILER ENTITIES
80 | System.out.println("\tAlmost done!");
81 | StatementList statementList = (StatementList) compilerEntity;
82 | EntityGatherer entityGatherer = new EntityGatherer();
83 | statementList.getEntities(entityGatherer);
84 |
85 | // PUT ENTITIES IN BLUEPRINT
86 | System.out.println("\tCreating blueprint string!");
87 | Blueprint blueprint = new Blueprint();
88 | Entity[] entities = new Entity[entityGatherer.entities.size()];
89 | blueprint.entities = entityGatherer.entities.toArray(entities);
90 | blueprint.item = "blueprint";
91 | blueprint.label = "FactoryScript by unobtanium";
92 | blueprint.icons = new Icon[] { new Icon(1, new Signal("arithmetic-combinator")) };
93 | BlueprintRoot blueprintRoot = new BlueprintRoot();
94 | blueprintRoot.blueprint = blueprint;
95 |
96 | // CREATE BLUEPRINT STRING
97 | String blueprintString = "0" + encode(compress(getStringFromBlueprintRoot(blueprintRoot)));
98 | System.out.println();
99 | System.out.println(blueprintString);
100 | System.out.println();
101 |
102 | // GENERATE OUTPUT FILE
103 | File file = new File(args[0]);
104 | String path = file.getPath();
105 | String directory = path.substring(0, path.lastIndexOf(System.getProperty("file.separator")));
106 | directory += System.getProperty("file.separator") + "blueprint.txt";
107 | System.out.println("\tExporting blueprint string into: " + directory);
108 | try (
109 | Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(directory), "utf-8"))) {
110 | writer.write(blueprintString);
111 | } catch (UnsupportedEncodingException e) {
112 | e.printStackTrace();
113 | } catch (FileNotFoundException e) {
114 | e.printStackTrace();
115 | } catch (IOException e) {
116 | e.printStackTrace();
117 | }
118 |
119 | System.out.println();
120 | System.out.println("\tFinished!");
121 | System.out.println();
122 | System.out.println();
123 |
124 | //
125 | // byte[] blueprintDecoded = decode(blueprintString);
126 | //
127 | // String blueprintDecompressed = decompress(blueprintDecoded);
128 | //
129 | // System.out.println(prettify(blueprintDecompressed));
130 | //
131 | //
132 | //
133 | // BlueprintRoot blueprintRoot =
134 | // getBlueprintRootFromString(blueprintDecompressed);
135 | //
136 | // System.out.println(getStringFromBlueprintRoot(blueprintRoot));
137 | //
138 | // System.out.println(encode(compress(blueprintDecompressed)));
139 | //
140 |
141 | }
142 |
143 | public static String prettify(String str) {
144 | ObjectMapper mapper = new ObjectMapper();
145 | Object json = null;
146 | try {
147 | json = mapper.readValue(str, Object.class);
148 | } catch (IOException e) {
149 | // TODO Auto-generated catch block
150 | e.printStackTrace();
151 | }
152 | String indented = null;
153 | try {
154 | indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
155 | } catch (JsonProcessingException e) {
156 | // TODO Auto-generated catch block
157 | e.printStackTrace();
158 | }
159 | return indented;
160 | }
161 |
162 | public static BlueprintRoot getBlueprintRootFromString(String str) {
163 | ObjectMapper mapper = new ObjectMapper();
164 | BlueprintRoot blueprintRoot = null;
165 | try {
166 | blueprintRoot = mapper.readValue(str, BlueprintRoot.class);
167 | } catch (IOException e) {
168 | // TODO Auto-generated catch block
169 | e.printStackTrace();
170 | }
171 | return blueprintRoot;
172 | }
173 |
174 | public static String getStringFromBlueprintRoot(BlueprintRoot blueprintRoot) {
175 | ObjectMapper mapper = new ObjectMapper();
176 | mapper.setSerializationInclusion(Include.NON_NULL);
177 | String jsonInString = null;
178 | try {
179 | jsonInString = mapper.writeValueAsString(blueprintRoot);
180 | } catch (JsonProcessingException e) {
181 | // TODO Auto-generated catch block
182 | e.printStackTrace();
183 | }
184 | return jsonInString;
185 | }
186 |
187 | public static byte[] decode(String str) {
188 | byte[] decoded = null;
189 | try {
190 | decoded = Base64.getDecoder().decode(str.substring(1, str.length()).getBytes("UTF-8"));
191 | } catch (UnsupportedEncodingException e1) {
192 | e1.printStackTrace();
193 | }
194 | return decoded;
195 | }
196 |
197 | public static String encode(byte[] bytes) {
198 | String encoded = null;
199 | encoded = Base64.getEncoder().encodeToString(bytes);
200 | return encoded;
201 | }
202 |
203 | public static String decompress(byte[] bytes) {
204 | InputStream in = new InflaterInputStream(new ByteArrayInputStream(bytes));
205 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
206 | try {
207 | byte[] buffer = new byte[8192];
208 | int len;
209 | while ((len = in.read(buffer)) > 0)
210 | baos.write(buffer, 0, len);
211 | return new String(baos.toByteArray(), "UTF-8");
212 | } catch (IOException e) {
213 | throw new AssertionError(e);
214 | }
215 | }
216 |
217 | public static byte[] compress(String text) {
218 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
219 | try {
220 | OutputStream out = new DeflaterOutputStream(baos);
221 | out.write(text.getBytes("UTF-8"));
222 | out.close();
223 | } catch (IOException e) {
224 | throw new AssertionError(e);
225 | }
226 | return baos.toByteArray();
227 | }
228 |
229 | }
230 |
--------------------------------------------------------------------------------
/src/main/java/factorioscript/CompilerVisitor.java:
--------------------------------------------------------------------------------
1 | package factorioscript;
2 |
3 | import antlr.FactorioScriptBaseVisitor;
4 | import antlr.FactorioScriptParser.AddStatementAssignContext;
5 | import antlr.FactorioScriptParser.AddSubExpContext;
6 | import antlr.FactorioScriptParser.BitExpContext;
7 | import antlr.FactorioScriptParser.CompilerAliasContext;
8 | import antlr.FactorioScriptParser.CompilerPowerpoleContext;
9 | import antlr.FactorioScriptParser.CompilerStandardContext;
10 | import antlr.FactorioScriptParser.MulDivModExpContext;
11 | import antlr.FactorioScriptParser.MultipleStatementListContext;
12 | import antlr.FactorioScriptParser.NumExpContext;
13 | import antlr.FactorioScriptParser.OverwriteStatementAssignContext;
14 | import antlr.FactorioScriptParser.PowExpContext;
15 | import antlr.FactorioScriptParser.PriorityExpContext;
16 | import antlr.FactorioScriptParser.SingleStatementListContext;
17 | import antlr.FactorioScriptParser.StatementContext;
18 | import antlr.FactorioScriptParser.SubStatementAssignContext;
19 | import antlr.FactorioScriptParser.VarExpContext;
20 | import entities.blueprint.Signal;
21 | import entities.compiler.ArithmeticCombinator;
22 | import entities.compiler.CompilerEntity;
23 | import entities.compiler.ConstantCombinator;
24 | import entities.compiler.Statement;
25 | import entities.compiler.StatementAdd;
26 | import entities.compiler.StatementList;
27 | import entities.compiler.StatementNone;
28 | import entities.compiler.StatementOverwrite;
29 | import entities.compiler.StatementSub;
30 | import entities.compiler.Number;
31 | import entities.compiler.PowerPole;
32 | import entities.compiler.Variable;
33 |
34 | public class CompilerVisitor extends FactorioScriptBaseVisitor {
35 |
36 | public static String standard_left;
37 | public static String standard_right;
38 |
39 | static {
40 | standard_left = "signal-Y";
41 | standard_right = "signal-Z";
42 | }
43 |
44 | @Override
45 | public CompilerEntity visitMultipleStatementList(MultipleStatementListContext ctx) {
46 | log("MultipleStatementList");
47 |
48 | Statement statement = (Statement) visit(ctx.s);
49 |
50 | StatementList statementList = (StatementList) visit(ctx.sl);
51 |
52 | statementList.addStatement(0, statement);
53 |
54 | return statementList;
55 | }
56 |
57 | @Override
58 | public CompilerEntity visitSingleStatementList(SingleStatementListContext ctx) {
59 | log("SingleStatementList");
60 |
61 | Statement statement = (Statement) visit(ctx.s);
62 |
63 | StatementList statementList = new StatementList();
64 |
65 | statementList.addStatement(0, statement);
66 |
67 | return statementList;
68 | }
69 |
70 | @Override
71 | public CompilerEntity visitStatement(StatementContext ctx) {
72 | log("StatementList");
73 | return visit(ctx.getChild(0));
74 | }
75 |
76 | @Override
77 | public CompilerEntity visitCompilerStandard(CompilerStandardContext ctx) {
78 | log("CompilerStandard");
79 | standard_left = ctx.varLeft.getText();
80 | standard_right = ctx.varRight.getText();
81 | return new StatementNone();
82 | }
83 |
84 | @Override
85 | public CompilerEntity visitCompilerAlias(CompilerAliasContext ctx) {
86 | log("CompilerAlias");
87 | Signal.addAlias(ctx.varOld.getText(), ctx.varAlias.getText());
88 | return new StatementNone();
89 | }
90 |
91 | @Override
92 | public CompilerEntity visitCompilerPowerpole(CompilerPowerpoleContext ctx) {
93 | log("CompilerPowerpole");
94 |
95 | PowerPole.powerPole = ctx.pole.getText();
96 |
97 | return new StatementNone();
98 | }
99 |
100 |
101 |
102 | @Override
103 | public CompilerEntity visitOverwriteStatementAssign(OverwriteStatementAssignContext ctx) {
104 | log("OverwriteStatementAssign");
105 |
106 | Variable variable = new Variable(ctx.var.getText());
107 | CompilerEntity expression = visit(ctx.expr);
108 |
109 | return new StatementOverwrite(variable, expression);
110 | }
111 |
112 | @Override
113 | public CompilerEntity visitAddStatementAssign(AddStatementAssignContext ctx) {
114 | log("AddStatementAssign");
115 |
116 | Variable variable = new Variable(ctx.var.getText());
117 | CompilerEntity expression = visit(ctx.expr);
118 |
119 | return new StatementAdd(variable, expression);
120 | }
121 |
122 | @Override
123 | public CompilerEntity visitSubStatementAssign(SubStatementAssignContext ctx) {
124 | log("SubStatementAssign");
125 |
126 | Variable variable = new Variable(ctx.var.getText());
127 | CompilerEntity expression = visit(ctx.expr);
128 |
129 | return new StatementSub(variable, expression);
130 | }
131 |
132 | @Override
133 | public CompilerEntity visitPriorityExp(PriorityExpContext ctx) {
134 | log("PriorityExp");
135 | return visit(ctx.expr);
136 | }
137 |
138 |
139 | @Override
140 | public CompilerEntity visitMulDivModExp(MulDivModExpContext ctx) {
141 | log("MulDivExp");
142 |
143 | ArithmeticCombinator ac = new ArithmeticCombinator();
144 | ac.leftEntity = visit(ctx.left);
145 | ac.operation = ctx.operand.getText();
146 | ac.rightEntity = visit(ctx.right);
147 |
148 | // NUMBER OPTIMIZATION
149 | boolean leftIsNumber = ac.leftEntity.getClass() == Number.class;
150 | boolean rightIsNumber = ac.rightEntity.getClass() == Number.class;
151 |
152 | if ( (ac.operation.equals("/") || ac.operation.equals("%") ) && rightIsNumber) {
153 | Number right = (Number) ac.rightEntity;
154 | if (right.getValue() == 0)
155 | System.err.println("Dont divide/modulo by 0, you maniac!");
156 | }
157 |
158 |
159 | if (leftIsNumber && rightIsNumber) {
160 | if (ac.operation.equals("*")) {
161 | Number left = (Number) ac.leftEntity;
162 | Number right = (Number) ac.rightEntity;
163 | return new Number(left.getValue() * right.getValue());
164 | } else if (ac.operation.equals("/")) {
165 | Number left = (Number) ac.leftEntity;
166 | Number right = (Number) ac.rightEntity;
167 | return new Number((int) ((0d + left.getValue()) / right.getValue()));
168 | }
169 | }
170 |
171 | // SWITCH NUMBER TO RIGHT SIDE
172 | if (ac.operation.equals("*") && ac.leftEntity.getClass() == Number.class) {
173 | CompilerEntity temp = ac.leftEntity;
174 | ac.leftEntity = ac.rightEntity;
175 | ac.rightEntity = temp;
176 | }
177 |
178 | // CREATE CONSTANT COMBINATOR IF LEFT IS NUMBER
179 | if ( (ac.operation.equals("/") || ac.operation.equals("%") ) && leftIsNumber) {
180 | ConstantCombinator cc = new ConstantCombinator();
181 | Number number = (Number) ac.leftEntity;
182 | cc.addSignal(standard_left, number.getValue());
183 | ac.leftEntity = cc;
184 | }
185 |
186 | // SET PARENT OF LEFT AND RIGHT ARITHMETICCOMBINATORS
187 | if (ac.leftEntity.getClass() == ArithmeticCombinator.class) {
188 | ArithmeticCombinator left = (ArithmeticCombinator) ac.leftEntity;
189 | left.outputEntity = ac;
190 | left.outputSignal = standard_left;
191 | }
192 | if (ac.rightEntity.getClass() == ArithmeticCombinator.class) {
193 | ArithmeticCombinator right = (ArithmeticCombinator) ac.rightEntity;
194 | right.outputEntity = ac;
195 | right.outputSignal = standard_right;
196 | }
197 |
198 | return ac;
199 | }
200 |
201 | @Override
202 | public CompilerEntity visitAddSubExp(AddSubExpContext ctx) {
203 | log("AddSubExp");
204 |
205 | ArithmeticCombinator ac = new ArithmeticCombinator();
206 | ac.leftEntity = visit(ctx.left);
207 | ac.operation = ctx.operand.getText();
208 | ac.rightEntity = visit(ctx.right);
209 |
210 | // NUMBER OPTIMIZATION
211 | boolean leftIsNumber = ac.leftEntity.getClass() == Number.class;
212 | boolean rightIsNumber = ac.rightEntity.getClass() == Number.class;
213 | if (ac.operation.equals("+")) {
214 | if (leftIsNumber && rightIsNumber) {
215 | Number left = (Number) ac.leftEntity;
216 | Number right = (Number) ac.rightEntity;
217 | return new Number(left.getValue() + right.getValue());
218 | } else if (leftIsNumber) {
219 | CompilerEntity temp = ac.leftEntity;
220 | ac.leftEntity = ac.rightEntity;
221 | ac.rightEntity = temp;
222 | }
223 | } else {
224 | if (leftIsNumber && rightIsNumber) {
225 | Number left = (Number) ac.leftEntity;
226 | Number right = (Number) ac.rightEntity;
227 | return new Number(left.getValue() - right.getValue());
228 | } else if (leftIsNumber) {
229 | // CREATE CONSTANT COMBINATOR IF LEFT IS NUMBER
230 | ConstantCombinator cc = new ConstantCombinator();
231 | Number number = (Number) ac.leftEntity;
232 | cc.addSignal(standard_left, number.getValue());
233 | ac.leftEntity = cc;
234 | }
235 | }
236 |
237 |
238 |
239 | // SET PARENT OF LEFT AND RIGHT ARITHMETICCOMBINATORS
240 | if (ac.leftEntity.getClass() == ArithmeticCombinator.class) {
241 | ArithmeticCombinator left = (ArithmeticCombinator) ac.leftEntity;
242 | left.outputEntity = ac;
243 | left.outputSignal = standard_left;
244 | }
245 | if (ac.rightEntity.getClass() == ArithmeticCombinator.class) {
246 | ArithmeticCombinator right = (ArithmeticCombinator) ac.rightEntity;
247 | right.outputEntity = ac;
248 | right.outputSignal = standard_right;
249 | }
250 |
251 | return ac;
252 | }
253 |
254 | @Override
255 | public CompilerEntity visitBitExp(BitExpContext ctx) {
256 | log("BitExp");
257 |
258 | ArithmeticCombinator ac = new ArithmeticCombinator();
259 | ac.leftEntity = visit(ctx.left);
260 | ac.operation = ctx.operand.getText();
261 | ac.rightEntity = visit(ctx.right);
262 |
263 | // NUMBER OPTIMIZATION
264 | boolean leftIsNumber = ac.leftEntity.getClass() == Number.class;
265 | boolean rightIsNumber = ac.rightEntity.getClass() == Number.class;
266 | if (leftIsNumber && rightIsNumber) {
267 | // CALCUALTE
268 | Number left = (Number) ac.leftEntity;
269 | Number right = (Number) ac.rightEntity;
270 | if (ac.operation.equals("<<")) {
271 | return new Number( left.getValue() << right.getValue() );
272 | } else if (ac.operation.equals(">>")) {
273 | return new Number( left.getValue() >> right.getValue() );
274 | } else if (ac.operation.equals("AND")) {
275 | return new Number( left.getValue() & right.getValue() );
276 | } else if (ac.operation.equals("OR")) {
277 | return new Number( left.getValue() | right.getValue() );
278 | } else /* XOR */ {
279 | return new Number( left.getValue() ^ right.getValue() );
280 | }
281 | } else if (leftIsNumber) {
282 | // CREATE CONSTANT COMBINATOR IF LEFT IS NUMBER
283 | ConstantCombinator cc = new ConstantCombinator();
284 | Number number = (Number) ac.leftEntity;
285 | cc.addSignal(standard_left, number.getValue());
286 | ac.leftEntity = cc;
287 | }
288 |
289 |
290 | // SET PARENT OF LEFT AND RIGHT ARITHMETICCOMBINATORS
291 | if (ac.leftEntity.getClass() == ArithmeticCombinator.class) {
292 | ArithmeticCombinator left = (ArithmeticCombinator) ac.leftEntity;
293 | left.outputEntity = ac;
294 | left.outputSignal = standard_left;
295 | }
296 | if (ac.rightEntity.getClass() == ArithmeticCombinator.class) {
297 | ArithmeticCombinator right = (ArithmeticCombinator) ac.rightEntity;
298 | right.outputEntity = ac;
299 | right.outputSignal = standard_right;
300 | }
301 |
302 | return ac;
303 | }
304 |
305 | @Override
306 | public CompilerEntity visitPowExp(PowExpContext ctx) {
307 | log("PowExp");
308 |
309 | ArithmeticCombinator ac = new ArithmeticCombinator();
310 | ac.leftEntity = visit(ctx.left);
311 | ac.operation = "^";
312 | ac.rightEntity = visit(ctx.right);
313 |
314 | // NUMBER OPTIMIZATION
315 | boolean leftIsNumber = ac.leftEntity.getClass() == Number.class;
316 | boolean rightIsNumber = ac.rightEntity.getClass() == Number.class;
317 | if (leftIsNumber && rightIsNumber) {
318 | // CALCUALTE
319 | Number left = (Number) ac.leftEntity;
320 | Number right = (Number) ac.rightEntity;
321 | return new Number( (int) Math.pow(left.getValue(), right.getValue()) );
322 | } else if (leftIsNumber) {
323 | // CREATE CONSTANT COMBINATOR IF LEFT IS NUMBER
324 | ConstantCombinator cc = new ConstantCombinator();
325 | Number number = (Number) ac.leftEntity;
326 | cc.addSignal(standard_left, number.getValue());
327 | ac.leftEntity = cc;
328 | }
329 |
330 |
331 | // SET PARENT OF LEFT AND RIGHT ARITHMETICCOMBINATORS
332 | if (ac.leftEntity.getClass() == ArithmeticCombinator.class) {
333 | ArithmeticCombinator left = (ArithmeticCombinator) ac.leftEntity;
334 | left.outputEntity = ac;
335 | left.outputSignal = standard_left;
336 | }
337 | if (ac.rightEntity.getClass() == ArithmeticCombinator.class) {
338 | ArithmeticCombinator right = (ArithmeticCombinator) ac.rightEntity;
339 | right.outputEntity = ac;
340 | right.outputSignal = standard_right;
341 | }
342 |
343 | return ac;
344 | }
345 |
346 |
347 | @Override
348 | public CompilerEntity visitVarExp(VarExpContext ctx) {
349 | log("VarExp");
350 | if (!Signal.variableExists(ctx.getText()))
351 | System.err.println("Variable " + ctx.getText() + " does not exist!");
352 | return new Variable(ctx.getText());
353 | }
354 |
355 | @Override
356 | public CompilerEntity visitNumExp(NumExpContext ctx) {
357 | log("NumExp");
358 | return new Number(Integer.parseInt(ctx.number.getText()));
359 | }
360 |
361 |
362 |
363 |
364 |
365 | public void log(String str) {
366 | //System.out.println(str);
367 | }
368 | }
369 |
--------------------------------------------------------------------------------