-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrapira.cpp
103 lines (91 loc) · 2.35 KB
/
rapira.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// ReRap Version 0.9
// Copyright 2011 Matthew Mikolay.
//
// This file is part of ReRap.
//
// ReRap is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ReRap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ReRap. If not, see <http://www.gnu.org/licenses/>.
//#include <vld.h>
#include "lexer.h"
#include "parser.h"
#include <clocale>
std::string filename;
/*** Return an error ***/
void error(std::exception& e)
{
std::cerr << filename;
std::cerr << ':' << "Interpreter error";
std::cerr << ':' << e.what() << std::endl;
}
/*** Return an error ***/
void error(Excep& e)
{
std::cerr << "***Error occured in file \"" + filename + "\"!***" << std::endl;
std::cerr << " ++Line number: " << e.getLineNumber() << std::endl;
std::cerr << " ++Column number: " << e.getColumnNumber() << std::endl;
std::cerr << '\t' << e.getMessage() << std::endl;
}
int main(int argc, char* argv[])
{
std::setlocale(LC_ALL, "en_US.utf8");
if(argc != 2)
{
std::cerr << "Invalid number of arguments!" << std::endl;
std::cerr << "Usage: rapira [filename]" << std::endl;
return 1;
}
// Set the filename
filename = argv[1];
// Initialize the lexer
Lexer lexer(argv[1]);
// Confirm that the input file has been opened correctly
if(!lexer.isOpen())
{
std::cerr << "Error opening file!" << std::endl;
//system("PAUSE");
return 1;
}
// Create a vector of tokens to store
std::vector<Token> tokens;
while(lexer.hasMoreTokens())
{
try
{
Token tok = lexer.getNextToken();
tokens.push_back(tok);
}
catch(Excep& e)
{
error(e);
//system("PAUSE");
return 1;
}
}
// Send the token list to a parser
Parser parser(filename, tokens);
try
{
parser.parse();
#ifndef PARSERONLY
parser.executeProgram();
#endif
}
catch(Excep& e)
{
error(e);
//system("PAUSE");
return 1;
}
//system("PAUSE");
return 0;
}