-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
71 lines (59 loc) · 2.77 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import alex.AnalizadorLexicoTiny;
import asint.AnalizadorSintacticoTiny;
import ast.Program;
public class Main {
//@formatter:off
public static final String BASE_FOLDER = "test-files/";
public static final String AST_DISPLAY_FOLDER = BASE_FOLDER+"ast/";
public static final String ERROR_RECOVERY_FOLDER = BASE_FOLDER+"error-recovery/";
public static final String SEMANTIC_ANALYSIS_FOLDER = BASE_FOLDER+"sem-analysis/";
public static final String CODE_GENERATION_FOLDER = BASE_FOLDER+"code-gen/";
public static final String TEST_ALL = BASE_FOLDER+"input.txt";
// AST construction and display test files
public static final String TEST_INSTRUCTIONS_DISPLAY = "instructions_ast.txt";
public static final String TEST_ACCESSES_DISPLAY = "accesses_ast.txt";
public static final String TEST_EXPRESSIONS_DISPLAY = "expressions_ast.txt";
public static final String TEST_TYPES_DISPLAY = "types_ast.txt";
// Error recovery test files
public static final String TEST_ERROR_RECOVERY = "error_recovery.txt";
public static final String TEST_TYPE_ERROR_RECOVERY = "types_er.txt";
public static final String TEST_EXP_ERROR_RECOVERY = "expressions_er.txt";
public static final String TEST_INST_ERROR_RECOVERY = "instructions_er.txt";
public static final String TEST_COMMON_ERROR_RECOVERY= "common_er.txt";
// Semantic analysis tests files
public static final String TEST_SEMANTIC_ANALYSIS = "sem_errors.txt";
public static final String TEST_EXP_SEMANTIC_ANALYSIS = "expressions_sa.txt";
public static final String TEST_TYPE_SEMANTIC_ANALYSIS = "types_sa.txt";
public static final String TEST_INST_SEMANTIC_ANALYSIS = "instructions_sa.txt";
public static final String TEST_COMMON_SEMANTIC_ANALYSIS= "common_sa.txt";
//@formatter:on
public static void main(String[] args) throws Exception {
// Input file
String input_file;
if (args.length > 0)
input_file = args[0];
else
input_file = "test-files/input.txt";
// Read and parse the input
Reader input = new InputStreamReader(new FileInputStream(input_file));
AnalizadorLexicoTiny alex = new AnalizadorLexicoTiny(input);
AnalizadorSintacticoTiny asint = new AnalizadorSintacticoTiny(alex);
Program pr = (Program) asint.parseInput();
pr.checkSemantics();
// Generate code for p-machine and print it to the desired output
PrintStream stream;
if (args.length == 2) {
pr.printAST();
stream = new PrintStream(args[1]);
}
else
stream = System.out;
pr.printPCode(stream);
stream.close();
}
}