moved scanner elsehere
This commit is contained in:
parent
909a43114b
commit
0018a97b1e
3 changed files with 30 additions and 23 deletions
2
makefile
2
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
|
build/parser.cpp build/parser.hpp: src/parser.y | build
|
||||||
$(BISON) -d -o build/parser.cpp src/parser.y
|
$(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
|
$(FLEX) --header-file=build/lexer.hpp -o build/lexer.cpp src/lexer.l
|
||||||
|
|
||||||
build/%.o: build/%.cpp
|
build/%.o: build/%.cpp
|
||||||
|
|
|
||||||
23
src/lexer.l
23
src/lexer.l
|
|
@ -3,28 +3,7 @@
|
||||||
%option yyclass="Scanner"
|
%option yyclass="Scanner"
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include "../build/parser.hpp"
|
#include "../src/scanner.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);
|
|
||||||
}
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
|
||||||
28
src/scanner.hpp
Normal file
28
src/scanner.hpp
Normal 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);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue