moved scanner elsehere

This commit is contained in:
bronku 2025-11-21 08:35:37 +01:00
parent 909a43114b
commit 0018a97b1e
3 changed files with 30 additions and 23 deletions

View file

@ -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

View file

@ -3,28 +3,7 @@
%option yyclass="Scanner"
%{
#include "../build/parser.hpp"
#include <string>
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"
%}
%%

28
src/scanner.hpp Normal file
View file

@ -0,0 +1,28 @@
#pragma once
#include "../build/parser.hpp"
#include <string>
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);
}