-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
53 lines (43 loc) · 1.15 KB
/
main.cpp
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
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include "Assembler.h"
using namespace std;
int main()
{
string input;
vector<string> inputCommand;
int lineNo = 0;
Assembler assembler;
// First pass of commands
while (getline(cin, input)) {
if (input[0] != '/' && !input.empty()) {
// Check for command
if ( (input.find(";") != string::npos) || (input.find("=") != string::npos) || (input.find("@") != string::npos)
|| (input[0] == '(')) {
// Remove carriage return
if (input[input.size() - 1] == '\r') {
input.erase(input.size()-1);
}
// Remove whitespace
input.erase(remove(input.begin(), input.end(), ' '), input.end());
// Remove comments
input = input.substr(0, input.find("//", 0));
// Store commands for second pass
inputCommand.push_back(input);
if (input[0] != '(') {
lineNo++;
}
// First pass of program
assembler.firstPass(input, lineNo);
}
}
}
// Second pass of program
for (int i=0; i<inputCommand.size(); i++) {
assembler.secondPass(inputCommand[i]);
}
return 0;
}