From 4d16b6fb08539bd7c7fe7a49a97f42f62c74f7c8 Mon Sep 17 00:00:00 2001 From: bronku Date: Fri, 21 Nov 2025 09:43:40 +0100 Subject: [PATCH] fuck yeah --- src/main.cpp | 6 ++++-- src/parser.y | 10 ++++++---- src/scanner.hpp | 13 ++++--------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b836b3a..da83ca3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ #include "../build/parser.hpp" #include "../src/scanner.hpp" +#include int main() { - yy::parser p; - return p.parse(); + Scanner scanner(&std::cin); + yy::parser parser(&scanner); + return parser.parse(); } \ No newline at end of file diff --git a/src/parser.y b/src/parser.y index 31721a0..8465227 100644 --- a/src/parser.y +++ b/src/parser.y @@ -8,17 +8,20 @@ %code requires { #include + class Scanner; // Forward declaration } %code { #include + #include "../src/scanner.hpp" - int scanner_lex(yy::parser::semantic_type* yylval); - + // Define yylex to use the scanner's lex method #undef yylex - #define yylex scanner_lex + #define yylex scanner->lex } +%parse-param { Scanner* scanner } + %token WORD %token NUMBER %token CHAR @@ -36,7 +39,6 @@ element: ; %% - namespace yy { void parser::error(const std::string& msg) { diff --git a/src/scanner.hpp b/src/scanner.hpp index 30e9769..5593f25 100644 --- a/src/scanner.hpp +++ b/src/scanner.hpp @@ -1,6 +1,5 @@ #pragma once -// fucking piece of shit flex, doesn't even have proper macro directives #ifndef yyFlexLexer #include #endif @@ -8,22 +7,18 @@ #include "../build/parser.hpp" #include -class yyFlexLexer; - class Scanner : public yyFlexLexer { public: - Scanner(std::istream *in) : yyFlexLexer(in) {} + Scanner(std::istream *in) : yyFlexLexer(in), yylval(nullptr) {} - int lex(yy::parser::semantic_type *yylval) + int lex(yy::parser::semantic_type *lval) { - this->yylval = yylval; + this->yylval = lval; return yylex(); } private: virtual int yylex(); yy::parser::semantic_type *yylval; -}; - -int scanner_lex(yy::parser::semantic_type *yylval); \ No newline at end of file +}; \ No newline at end of file