summaryrefslogtreecommitdiff
path: root/src/system.yy
diff options
context:
space:
mode:
Diffstat (limited to 'src/system.yy')
-rw-r--r--src/system.yy90
1 files changed, 90 insertions, 0 deletions
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 <fstream>
+#include <filesystem>
+#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 <cstdint>
+#include "lexer.h"
+}
+
+%parse-param {Lexer<symbol_type> &lexer}
+
+%token <uint64_t> NUM
+%token <double> 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($<uint64_t>3);
+ }
+ ;
+
+block_end:
+ END BLANK NUM BREAK {
+ if ($<uint64_t>3 != msg.epoch()) {
+ msg.Clear();
+ cout << $<uint64_t>3 << endl;
+ } else {
+ cout << $<uint64_t>3 << endl;
+ auto p = filesystem::path("proto");
+ p /= to_string($<uint64_t>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<yy::parser::symbol_type> lexer;
+ yy::parser parse(lexer);
+
+ return parse();
+}