4
Copyright (c) 2022 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo
9
#include "simodo/interpret/SemanticOperationsEnumsLoader.h"
11
#include "simodo/variable/json/LexicalParametersLoader.h"
12
#include "simodo/inout/token/Tokenizer.h"
13
#include "simodo/inout/token/FileStream.h"
14
#include "simodo/inout/convert/functions.h"
16
#if __cplusplus >= __cpp_2017
18
namespace fs = std::filesystem;
20
#include <experimental/filesystem>
21
namespace fs = std::filesystem::experimental;
25
namespace simodo::interpret
27
variable::VariableSet_t readSemanticModuleOperations(const std::string & file_path, inout::LexicalParameters & lex)
29
variable::VariableSet_t res;
31
inout::FileStream in(file_path);
36
inout::Tokenizer tokenizer(0, in, lex);
37
inout::Token t = tokenizer.getToken();
39
while(t.type() != inout::LexemeType::Empty) {
40
if (t.type() != inout::LexemeType::Id)
43
std::u16string id = t.lexeme();
45
t = tokenizer.getToken();
47
if (t.type() != inout::LexemeType::Punctuation || t.lexeme() != u"=")
50
t = tokenizer.getToken();
52
if (t.type() != inout::LexemeType::Number
53
|| t.qualification() != inout::TokenQualification::Integer)
56
int64_t number = std::stol(inout::toU8(t.lexeme()));
58
t = tokenizer.getToken();
60
if (t.type() != inout::LexemeType::Punctuation || t.lexeme() != u",")
63
res.push_back({id, number});
65
t = tokenizer.getToken();
71
variable::VariableSet_t loadSemanticOperationsEnums(const std::string & grammar_dir)
73
variable::VariableSet_t res;
74
const fs::path path_to_grammar {grammar_dir};
76
if (!fs::exists(path_to_grammar))
79
inout::LexicalParameters lex;
81
bool ok = variable::loadLexicalParameters((path_to_grammar/"lex"/"cpp.json").string(), lex);
86
const fs::path path_to_ops { path_to_grammar / "ops"};
88
for (auto const & f : fs::directory_iterator{path_to_ops}) {
89
std::u16string extension = f.path().extension().u16string();
90
std::u16string host_name = extension.empty() ? u"" : extension.substr(1);
91
variable::VariableSet_t ops = readSemanticModuleOperations(f.path().string(), lex);
92
variable::VariableSet_t host {{
94
{u"op", variable::Object {ops}},
97
res.push_back({f.path().stem().u16string(), variable::Object {host}});