This repository has been archived by the owner on Sep 18, 2022. It is now read-only.
forked from LucasCatchlove/Cmin_Cross_Assembler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossAssembler.java
90 lines (73 loc) · 2.62 KB
/
CrossAssembler.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import analysers.FileReader;
import analysers.ILexicalAnalyser;
import analysers.LexicalAnalyser;
import analysers.SyntaxAnalyser;
import errorReporters.*;
import components.SymbolTable;
import errorReporters.IErrorReporter;
import generators.CodeGenerator;
import generators.Listing;
import interfaces.*;
import components.Options;
/**
* main class for cross assembler
*/
public class CrossAssembler {
public static void main(String[] args) {
System.out.println("\nFor more information about the cross-assemblers optional features, please include the " +
"\"-h\" flag following the file name");
Options options = new Options(args);
String srcFile = "";
//"Sprint Listing/rela02.asm";
//for command line file name specification
if(args.length > 0) {
if (args.length != 1 && !options.helpEnabled())
srcFile = fileName(args[args.length - 1] );
else
{
System.out.println("File not specified");
System.exit(404);
}
}else{
System.out.println("File not specified");
System.exit(404);
}
IFileReader reader = new FileReader(srcFile);
//Creation of Error Reporter
IErrorReporter errRep = new ErrorReporter(srcFile);
//creation of symbol table
ISymbolTable symbolTable = new SymbolTable();
//creation of line components.IR and subsequent line statements
ILexicalAnalyser lexer = new LexicalAnalyser(reader, symbolTable, errRep);
ISyntaxAnalyser parser = new SyntaxAnalyser(symbolTable, lexer, errRep);
//creation of objects used to traverse components.IR
IIR intRep = parser.parse();
//IListing list = new Listing(intRep);
if (!errRep.isEmpty()) {
errRep.reportErrors();
}
//generates .lst file
CodeGenerator codeGenerator = new CodeGenerator(intRep, symbolTable, options, errRep, srcFile);
}
private static String fileName(String srcFile)
{
String fileName = "";
boolean hasExtension = false;
for(int i=0;i<srcFile.length();i++)
{
if(srcFile.charAt(i)=='.' && srcFile.length()==i+4)
{
hasExtension = true;
if(srcFile.substring(i,srcFile.length()-1)==".asm"){
fileName = srcFile.substring(0,srcFile.length()-4);
}else{
fileName=srcFile;
}
}
}
if(!hasExtension){
fileName=srcFile;
}
return fileName;
}
}