-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathael.cpp
More file actions
executable file
·91 lines (84 loc) · 1.64 KB
/
ael.cpp
File metadata and controls
executable file
·91 lines (84 loc) · 1.64 KB
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
/*
Author: Willie Lawrence - cptx032@gmail.com
*/
#include "ael.h"
#include "ael_io.h"
#include "ael_string.h"
std::vector<tok> args;
//[doc] retorna true se o argumento foi
// passado nos parametros
bool args_contains(std::string key)
{
for(int i=0; i < args.size(); i++)
{
if(args[i] == key)
{
return true;
}
}
return false;
}
//[doc] pega o valor do parametro
std::string param_get(std::string key)
{
for(int i=0; i < args.size(); i++)
{
if(args[i] == key)
{
if(args.size() >= (i + 2))
return args[i+1];
else
return "";
}
}
return "";
}
void ael_argv(aelinterpreter &ael, phrase &ph)
{
if(ph.size() != 3)
{
std::cerr << "Error: " << ph[0] << " takes exactly 2 arguments (" << ph.size()-1 << " given)" << std::endl;
return;
}
int arg_index = atoi(ael.get_value(ph[1]).c_str());
ael.dictionary[ph[2]] = args[arg_index];
}
aelinterpreter i;
int main(int argc, char *argv[])
{
load_main_ael_functions(i);
load_io_functions(i);
load_string_functions(i);
for(int i=0; i < argc; i++)
{
args.push_back(argv[i]);
}
i.dictionary["argc"] = to_string(argc);
i.functions["argv"] = ael_argv;
if (argc == 1)
{ // [fixme] > here document with interpreter
std::cerr << argv[0] << ": missing file operand" << std::endl;
return -1;
}
for(int i=0; i < argc; i++)
{
args.push_back(argv[i]);
}
if(args_contains("-v"))
{
std::cout << "Ael Version: " << AEL_VERSION << std::endl;
return 0;
}
phrase ph;
if(param_get("-c") != "")
{
i.to_tokens(param_get("-c").c_str(), ph);
}
else
{
std::string script_file = get_file_content(argv[1]);
i.to_tokens(script_file.c_str(), ph);
}
i.interprets(ph);
return 0;
}