summaryrefslogtreecommitdiff
path: root/src/system.yy
blob: af64eddb22a9f3953b17e7e5bbcd94f352548392 (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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();
}