This repository was archived by the owner on Apr 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cxx
More file actions
59 lines (48 loc) · 1.67 KB
/
main.cxx
File metadata and controls
59 lines (48 loc) · 1.67 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
#include <iostream>
#include <string>
#include "parse.h"
#include "lexeme.h"
#include "syntax.h"
#include "program_tree.h"
#include "program_stucture.h"
#include <fstream>
#include <streambuf>
int main( int argc, char* argv[] )
{
if (2 > argc) {
std::cout << "Little python parser by Michael Pogoda.\n"
<< "Usage:\n"
<< argv[0] << "[ file to parse ]\n";
return 1;
}
const sap::Table table = sap::createTable();
const sap::Stack ss{ { { sap::lex::type::COUNT, 0u }
, { sap::lex::type::RULE, sap::lex::rule::START }
} };
while (1 < argc--) {
std::ifstream in{ argv[ argc ] };
in.unsetf( std::ios::skipws );
const std::string str{ std::istreambuf_iterator< char >{ in }
, std::istreambuf_iterator< char >{} };
std::cout << "File `\033[0;33m" << argv[ argc ] << "\033[0m'\n";
try {
sap::Lexems lexems = sap::parse( str );
for (const auto& lexem : lexems ) {
std::cout << lexem << '\n';
}
sap::Queue queue = sap::parse( table, lexems.begin(), lexems.end(), ss );
sap::LIterator it = lexems.begin();
sap::node node{ queue, it };
std::cout << node << std::endl;
sap::Program program{ node };
std::cout << program.scope_;
sap::ProgramCode::instance().reset();
program();
std::cout << sap::ProgramCode::instance();
} catch ( std::exception& ex ) {
std::cerr << ex.what();
}
std::cout << "\n\n";
}
return 0;
}