-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (68 loc) · 1.62 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>
#include "Parser.h"
#include "CodeWriter.h"
#include "Parser.cpp"
#include "CodeWriter.cpp"
#include <boost/algorithm/string.hpp>
using namespace std;
int main()
{
char filename[100];
CodeWriter CodewriterObj;
Parser ParserObj;
string Name, OutFile;
cout << "Enter the File/Directory Name: ";
getline(cin, Name);
strcpy(filename, Name.c_str());
string Extension = (Name.substr(Name.length() - 3));
if (boost::iequals(Extension, ".vm") == true)
{
ParserObj.setFileName(filename);
CodewriterObj.setFileName(filename);
}
else
{
CodewriterObj.setOutputFileName(filename);
}
while (ParserObj.hasMoreCommands())
{
ParserObj.advance();
if (ParserObj.commandType() == C_ARITHMETIC)
{
CodewriterObj.WArithmetic(ParserObj.arg1());
}
else if (ParserObj.commandType() == C_POP)
{
CodewriterObj.WPushPop(C_POP, ParserObj.arg1(), ParserObj.arg2());
}
else if (ParserObj.commandType() == C_PUSH)
{
CodewriterObj.WPushPop(C_PUSH, ParserObj.arg1(), ParserObj.arg2());
}
else if (ParserObj.commandType() == C_LABEL)
{
CodewriterObj.WLabel(ParserObj.arg1());
}
else if (ParserObj.commandType() == C_GOTO)
{
CodewriterObj.WGoto(ParserObj.arg1());
}
else if (ParserObj.commandType() == C_IF)
{
CodewriterObj.WIf(ParserObj.arg1());
}
else if (ParserObj.commandType() == C_FUNCTION)
{
CodewriterObj.WFunction(ParserObj.arg1(), ParserObj.arg2());
}
else if (ParserObj.commandType() == C_RETURN)
{
CodewriterObj.WReturn();
}
else if (ParserObj.commandType() == C_CALL)
{
CodewriterObj.WCall(ParserObj.arg1(), ParserObj.arg2());
}
}
}