-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCompiler.java
More file actions
30 lines (26 loc) · 980 Bytes
/
Compiler.java
File metadata and controls
30 lines (26 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package component_construction;
import code_generation.CodeGenerator;
import grammar_objects.Token;
import lexical_analysis.LexicalAnalyser;
import syntax_analysis.SyntaxAnalyser;
import syntax_analysis.parsing.ParseFailedException;
import syntax_analysis.parsing.ParseState;
public class Compiler {
protected LexicalAnalyser lexicalAnalyser;
protected SyntaxAnalyser syntaxAnalyser;
protected CodeGenerator codeGenerator;
public Compiler(
LexicalAnalyser lexicalAnalyser,
SyntaxAnalyser syntaxAnalyser,
CodeGenerator codeGenerator
) {
this.lexicalAnalyser = lexicalAnalyser;
this.syntaxAnalyser = syntaxAnalyser;
this.codeGenerator = codeGenerator;
}
public String compile(String input) throws ParseFailedException {
Token[] tokens = lexicalAnalyser.analyse(input);
ParseState parseRoot = syntaxAnalyser.analyse(tokens);
return codeGenerator.generate(parseRoot);
}
}