Add first parser draft for temp prfiles.
This commit is contained in:
parent
dc6e973d52
commit
223de7f190
1
tprcc/.gitignore
vendored
1
tprcc/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*.o
|
||||
build/*
|
||||
.cache/*
|
||||
|
@ -2,13 +2,16 @@ cmake_minimum_required(VERSION 3.8)
|
||||
project(tprcc LANGUAGES CXX)
|
||||
|
||||
set (CMAKE_CXX_STANDARD 17)
|
||||
add_compile_options(-Wall -Wextra)
|
||||
|
||||
aux_source_directory("src" SRC_DIR)
|
||||
aux_source_directory("src/tpr" SRC_TPR_DIR)
|
||||
|
||||
set (SRC_GENERATED "${CMAKE_CURRENT_BINARY_DIR}/tpr-parser.cpp" "${CMAKE_CURRENT_BINARY_DIR}/tpr-scanner.cpp")
|
||||
|
||||
set (SOURCES
|
||||
${SRC_DIR}
|
||||
${SRC_TPR_DIR}
|
||||
${SRC_GENERATED}
|
||||
)
|
||||
|
||||
|
52
tprcc/include/lang/temp-lang-frontend.hpp
Normal file
52
tprcc/include/lang/temp-lang-frontend.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef _TEMP_LANG_FRONTEND_HPP_
|
||||
#define _TEMP_LANG_FRONTEND_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <istream>
|
||||
#include <streambuf>
|
||||
|
||||
class TempLangFrontend {
|
||||
public:
|
||||
enum class LogLevel {
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR,
|
||||
};
|
||||
|
||||
|
||||
TempLangFrontend(const std::string &source_file)
|
||||
{
|
||||
m_source_file = source_file;
|
||||
}
|
||||
|
||||
int analyze();
|
||||
|
||||
const std::string &get_src_file()
|
||||
{
|
||||
return m_source_file;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string m_source_file;
|
||||
|
||||
void log(LogLevel lvl, const std::string &message) const
|
||||
{
|
||||
switch (lvl) {
|
||||
case LogLevel::ERROR:
|
||||
std::cerr << "[ERR]" << message << std::endl;
|
||||
break;
|
||||
case LogLevel::WARNING:
|
||||
std::cerr << "[WARN]" << message << std::endl;
|
||||
break;
|
||||
default:
|
||||
std::cout << message << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* _TEMP_LANG_FRONTEND_HPP_ */
|
21
tprcc/include/tpr/tpr-frontend.hpp
Normal file
21
tprcc/include/tpr/tpr-frontend.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef _TPR_FRONTEND_HPP_
|
||||
#define _TPR_FRONTEND_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <lang/temp-lang-frontend.hpp>
|
||||
#include <tpr/tpr-scanner.hpp>
|
||||
|
||||
namespace tpr {
|
||||
|
||||
class TprFrontend : public TempLangFrontend {
|
||||
private:
|
||||
public:
|
||||
TprFrontend(const std::string &source_file);
|
||||
|
||||
int analyze();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* _TPR_FRONTEND_HPP_ */
|
@ -22,6 +22,9 @@ SPACE "\t"|" "
|
||||
NUM [-+]?([0-9]*\.[0-9]+|[0-9]+)
|
||||
|
||||
%%
|
||||
%{
|
||||
yylval = lval;
|
||||
%}
|
||||
|
||||
<*>{SPACE} { /*Ignore spaces */}
|
||||
{COMMENT_LINE} {loc->lines(); return token::lineend;}
|
||||
@ -40,4 +43,9 @@ digio_conf { return token::kw_digio_conf; }
|
||||
digio_set { return token::kw_digio_set; }
|
||||
digio_wait { return token::kw_digio_wait; }
|
||||
|
||||
. {
|
||||
std::cerr << "[ERR] Failed to parse: " << yytext << " @ " << *loc << std::endl;
|
||||
return token::unexpected_input;
|
||||
}
|
||||
|
||||
%%
|
||||
|
@ -43,6 +43,7 @@
|
||||
%token kw_digio_conf
|
||||
%token kw_digio_set
|
||||
%token kw_digio_wait
|
||||
%token unexpected_input
|
||||
|
||||
%%
|
||||
|
||||
@ -71,7 +72,8 @@ tpr_command_inner: cmd_pid_conf;
|
||||
|
||||
cmd_pid_conf: kw_pid_conf number number number number number number;
|
||||
|
||||
cmd_temp_set: kw_temp_set number;
|
||||
cmd_temp_set: kw_temp_set number {std::cout << "Set Temperature" << $2 << std::endl;}
|
||||
;
|
||||
|
||||
cmd_wait_temp: kw_wait_temp number;
|
||||
|
||||
@ -95,6 +97,6 @@ cmd_digio_wait: kw_digio_wait number number;
|
||||
|
||||
void tpr::TempProfileParser::error(const location_type &l, const std::string &err_message)
|
||||
{
|
||||
std::cerr << "Error " << err_message << " at " << l << std::endl;
|
||||
std::cerr << "[ERR] Parser Error: '" << err_message << "' at " << l << std::endl;
|
||||
std::abort();
|
||||
}
|
@ -1,8 +1,15 @@
|
||||
#include <iostream>
|
||||
#include <tpr/tpr-frontend.hpp>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cout << "Hello world" << std::endl;
|
||||
|
||||
if (argc > 1) {
|
||||
auto fe = tpr::TprFrontend(std::string(argv[1]));
|
||||
|
||||
fe.analyze();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
26
tprcc/src/tpr/tpr-frontend.cpp
Normal file
26
tprcc/src/tpr/tpr-frontend.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <tpr/tpr-frontend.hpp>
|
||||
|
||||
namespace tpr {
|
||||
|
||||
TprFrontend::TprFrontend(const std::string &source_file) : TempLangFrontend(source_file)
|
||||
{
|
||||
}
|
||||
|
||||
int TprFrontend::analyze()
|
||||
{
|
||||
std::ifstream input_stream(m_source_file);
|
||||
|
||||
if (!input_stream.good()) {
|
||||
log(TempLangFrontend::LogLevel::ERROR, "Cannot read input file " + m_source_file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
auto scanner = TempProfileScanner(&input_stream);
|
||||
auto parser = TempProfileParser(scanner);
|
||||
|
||||
parser.parse();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user