diff --git a/makefile b/makefile index 50e3f00..7c33a05 100644 --- a/makefile +++ b/makefile @@ -11,7 +11,7 @@ $(TARGET): build/parser.o build/lexer.o build/main.o build/parser.cpp build/parser.hpp: src/parser.y | build $(BISON) -d -o build/parser.cpp src/parser.y -build/lexer.cpp build/lexer.hpp: src/lexer.l build/parser.hpp | build +build/lexer.cpp build/lexer.hpp: src/lexer.l build/parser.hpp src/scanner.hpp | build $(FLEX) --header-file=build/lexer.hpp -o build/lexer.cpp src/lexer.l build/%.o: build/%.cpp diff --git a/src/lexer.l b/src/lexer.l index c89a0c2..c2afe7e 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -3,28 +3,7 @@ %option yyclass="Scanner" %{ -#include "../build/parser.hpp" -#include - -class Scanner : public yyFlexLexer { -public: - Scanner(std::istream* in) : yyFlexLexer(in) {} - - int yylex(); - - int lex(yy::parser::semantic_type* yylval) { - this->yylval = yylval; - return yylex(); - } - -private: - yy::parser::semantic_type* yylval; -}; - -int scanner_lex(yy::parser::semantic_type* yylval) { - static Scanner scanner(&std::cin); - return scanner.lex(yylval); -} +#include "../src/scanner.hpp" %} %% diff --git a/src/scanner.hpp b/src/scanner.hpp new file mode 100644 index 0000000..1a84b48 --- /dev/null +++ b/src/scanner.hpp @@ -0,0 +1,28 @@ +#pragma once +#include "../build/parser.hpp" +#include + +class yyFlexLexer; + +class Scanner : public yyFlexLexer +{ +public: + Scanner(std::istream *in) : yyFlexLexer(in) {} + + int yylex(); + + int lex(yy::parser::semantic_type *yylval) + { + this->yylval = yylval; + return yylex(); + } + +private: + 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