-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
105 lines (99 loc) · 2.54 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
//
// JoraLang
//
// Created by Pierre-Henry Soria on 31/07/2016.
// Copyright © 2016 Pierre-Henry Soria. All rights reserved.
//
#include <cstdlib> // C library
#include <cstring> // C library
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "Core.hpp"
#include "Parser.hpp"
#include "Lexer.hpp"
using namespace std;
using namespace JoraLang;
// Main program entry point
int main(int argc, char *argv[]) {
try
{
Parser seq;
string input;
if( argc > 1 )
{
if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "-version"))
{
cout << Core::softwareVersion();
return EXIT_SUCCESS;
}
else if (!strcmp(argv[1], "-H") || !strcmp(argv[1], "-help"))
{
cout << Core::showHelp();
return EXIT_SUCCESS;
}
else if (!strcmp(argv[1], "-license"))
{
cout << Core::showLicense();
return EXIT_SUCCESS;
}
else if (!strcmp(argv[1], "-credits"))
{
cout << Core::showCredits();
return EXIT_SUCCESS;
}
else
{
ifstream iFile( argv[1] );
if( iFile.is_open() )
{
while( !iFile.eof() )
{
getline(iFile, input);
Parser sequence( seq.get(input) );
Lexer::interpret(sequence);
}
}
else
{
cerr << "Couldn't open file '" + (string)argv[1] + "'" << endl;
}
iFile.close();
}
}
else
{
cout << Core::softwareInfo();
while(1)
{
cout << ">>> ";
getline(cin, input);
Parser sequence( seq.get(input) );
Lexer::interpret(sequence);
cout << endl;
}
}
return 0;
}
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;
}
}