From 05ba6f6e7f8beaec8bc1f8791642fdaec03703dc Mon Sep 17 00:00:00 2001 From: bronku Date: Fri, 21 Nov 2025 09:14:35 +0100 Subject: [PATCH] fixed scanner.hpp --- makefile | 4 ++-- src/main.cpp | 1 + src/scanner.cpp | 7 +++++++ src/scanner.hpp | 15 ++++++++------- 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 src/scanner.cpp diff --git a/makefile b/makefile index 7c33a05..366ef4d 100644 --- a/makefile +++ b/makefile @@ -5,7 +5,7 @@ FLEX = flex TARGET = build/py2rb -$(TARGET): build/parser.o build/lexer.o build/main.o +$(TARGET): build/parser.o build/lexer.o build/main.o build/scanner.o $(CXX) $^ -o $@ build/parser.cpp build/parser.hpp: src/parser.y | build @@ -17,7 +17,7 @@ build/lexer.cpp build/lexer.hpp: src/lexer.l build/parser.hpp src/scanner.hpp | build/%.o: build/%.cpp $(CXX) -c $(ARGS) $< -o $@ -build/main.o: src/main.cpp | build +build/%.o: src/%.cpp | build $(CXX) -c $(ARGS) $< -o $@ build: diff --git a/src/main.cpp b/src/main.cpp index 61e64b1..b836b3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include "../build/parser.hpp" +#include "../src/scanner.hpp" int main() { diff --git a/src/scanner.cpp b/src/scanner.cpp new file mode 100644 index 0000000..9aa112c --- /dev/null +++ b/src/scanner.cpp @@ -0,0 +1,7 @@ +#include "../src/scanner.hpp" + +int scanner_lex(yy::parser::semantic_type *yylval) +{ + static Scanner scanner(&std::cin); + return scanner.lex(yylval); +} \ No newline at end of file diff --git a/src/scanner.hpp b/src/scanner.hpp index 1a84b48..30e9769 100644 --- a/src/scanner.hpp +++ b/src/scanner.hpp @@ -1,4 +1,10 @@ #pragma once + +// fucking piece of shit flex, doesn't even have proper macro directives +#ifndef yyFlexLexer +#include +#endif + #include "../build/parser.hpp" #include @@ -9,8 +15,6 @@ class Scanner : public yyFlexLexer public: Scanner(std::istream *in) : yyFlexLexer(in) {} - int yylex(); - int lex(yy::parser::semantic_type *yylval) { this->yylval = yylval; @@ -18,11 +22,8 @@ public: } private: + virtual int yylex(); yy::parser::semantic_type *yylval; }; -int scanner_lex(yy::parser::semantic_type *yylval) -{ - static Scanner scanner(&std::cin); - return scanner.lex(yylval); -} \ No newline at end of file +int scanner_lex(yy::parser::semantic_type *yylval); \ No newline at end of file