/* 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(); }