-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
executable file
·114 lines (108 loc) · 3.02 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
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
104
105
106
107
108
109
110
111
112
113
114
/*
* PH GoYa - Programming Language
*
* Author: Pierre-Henry Soria <[email protected]>
* Copyright: (c) 2012-2013, Pierre-Henry Soria. All Rights Reserved.
*
* For the full copyright and license information, please view the PH_GOYA_LICENSE.txt and PH_GOYA_COPYRIGHT.txt
* file that was distributed with this source code.
*/
#include <cstdlib> // C library
#include <cstring> // C library
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include "GoYa/Main.hpp"
#include "Parser/Token.hpp"
#include "Interpreter/Base.hpp"
#include "Err/Msg.hpp"
#include "Err/Exception.hpp"
using namespace std;
int main(int argc, char** const argv)
{
try
{
Func::Core::system();
Parser::Token sequence;
string input;
if( argc > 1 )
{
if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "-version"))
{
cout << GoYa::Main::softwareVersion();
return EXIT_SUCCESS;
}
else if (!strcmp(argv[1], "-H") || !strcmp(argv[1], "-help"))
{
cout << GoYa::Main::showHelp();
return EXIT_SUCCESS;
}
else if (!strcmp(argv[1], "-license"))
{
cout << GoYa::Main::showLicense();
return EXIT_SUCCESS;
}
else if (!strcmp(argv[1], "-credits"))
{
cout << GoYa::Main::showCredits();
return EXIT_SUCCESS;
}
else
{
ifstream iFile( argv[1] );
if( iFile.is_open() )
{
while( !iFile.eof() )
{
getline(iFile, input);
Parser::Token sequence( sequence.get(input) );;
Interpreter::Base::interpret(sequence);
}
}
else
{
Err::Msg::showErr("Couldn't open file '" + (string)argv[1] + "'");
}
iFile.close();
}
}
else
{
cout << GoYa::Main::welcome();
while(1)
{
cout << ">>> ";
getline(cin, input);
Parser::Token sequence( sequence.get(input) );
Interpreter::Base::interpret(sequence);
cout << endl;
}
}
return 0;
}
catch (Err::Exception const& e)
{
cerr << GoYa::Main::NAME << "Exception: " << e.what() << endl;
}
catch (string const& text)
{
cerr << text << endl;
}
catch (int digit)
{
cerr << "Integer Exception: " << digit << endl;
}
catch (double digit)
{
cerr << "Double Exception: " << digit << endl;
}
catch (runtime_error const& e)
{
cerr << "Exception during runtime: " << e.what() << endl;
}
catch (exception const& e)
{
cerr << e.what() << endl;
}
}