From e0139539359c0f3bec41b8ba37438f8026975774 Mon Sep 17 00:00:00 2001 From: Mubashshir Date: Fri, 15 Nov 2024 03:04:06 +0600 Subject: Initial commit Signed-off-by: Mubashshir --- src/system.yy | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/system.yy (limited to 'src/system.yy') diff --git a/src/system.yy b/src/system.yy new file mode 100644 index 0000000..af64edd --- /dev/null +++ b/src/system.yy @@ -0,0 +1,90 @@ +/* parser.y (Bison file) */ +%{ +#define PARSER_SOURCE +#include +#include +#include "system.pb.h" // Include the generated protobuf header +#include "lexer.h" +#define yylex lexer.yynlex + +using namespace std; + +Entry::System msg; + +%} + +%language "c++" +%require "3.2" +%define api.token.constructor +%define api.value.type variant + +%code requires // *.hh +{ +#include +#include "lexer.h" +} + +%parse-param {Lexer &lexer} + +%token NUM +%token FRC +%token BREAK BLANK START END VERSION CPU BASE USER NICE +%token SYSP IDLE IOWP IRQP SIRQ CORE MEM TOTAL CACHE SHARED +%token TSWAP USWAP TEMP CURR TMIN TMAX TAVG COLON SLASH + +%% + +// Grammar Rules +start: + block + | start block + ; + +block: + block_start data block_end + ; + +block_start: + START BLANK NUM BREAK { + msg.set_epoch($3); + } + ; + +block_end: + END BLANK NUM BREAK { + if ($3 != msg.epoch()) { + msg.Clear(); + cout << $3 << endl; + } else { + cout << $3 << endl; + auto p = filesystem::path("proto"); + p /= to_string($3); + p += string(".proto"); + ofstream f(p, ios_base::out | ios_base::binary); + msg.SerializeToOstream(&f); + f.close(); + } + } + +data: +; +%% + +namespace yy +{ + // Report an error to the user. + auto parser::error (const std::string& msg) -> void + { + std::cerr << msg << '\n'; + } +} + +#undef PARSER_SOURCE +#include "lexer.h" + +int main() { + Lexer lexer; + yy::parser parse(lexer); + + return parse(); +} -- cgit v1.2.3