fuck yeah
This commit is contained in:
parent
05ba6f6e7f
commit
4d16b6fb08
3 changed files with 14 additions and 15 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
#include "../build/parser.hpp"
|
#include "../build/parser.hpp"
|
||||||
#include "../src/scanner.hpp"
|
#include "../src/scanner.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
yy::parser p;
|
Scanner scanner(&std::cin);
|
||||||
return p.parse();
|
yy::parser parser(&scanner);
|
||||||
|
return parser.parse();
|
||||||
}
|
}
|
||||||
10
src/parser.y
10
src/parser.y
|
|
@ -8,17 +8,20 @@
|
||||||
|
|
||||||
%code requires {
|
%code requires {
|
||||||
#include <string>
|
#include <string>
|
||||||
|
class Scanner; // Forward declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
%code {
|
%code {
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../src/scanner.hpp"
|
||||||
|
|
||||||
int scanner_lex(yy::parser::semantic_type* yylval);
|
// Define yylex to use the scanner's lex method
|
||||||
|
|
||||||
#undef yylex
|
#undef yylex
|
||||||
#define yylex scanner_lex
|
#define yylex scanner->lex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%parse-param { Scanner* scanner }
|
||||||
|
|
||||||
%token <std::string> WORD
|
%token <std::string> WORD
|
||||||
%token NUMBER
|
%token NUMBER
|
||||||
%token CHAR
|
%token CHAR
|
||||||
|
|
@ -36,7 +39,6 @@ element:
|
||||||
;
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
namespace yy {
|
namespace yy {
|
||||||
void parser::error(const std::string& msg)
|
void parser::error(const std::string& msg)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// fucking piece of shit flex, doesn't even have proper macro directives
|
|
||||||
#ifndef yyFlexLexer
|
#ifndef yyFlexLexer
|
||||||
#include <FlexLexer.h>
|
#include <FlexLexer.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -8,16 +7,14 @@
|
||||||
#include "../build/parser.hpp"
|
#include "../build/parser.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class yyFlexLexer;
|
|
||||||
|
|
||||||
class Scanner : public yyFlexLexer
|
class Scanner : public yyFlexLexer
|
||||||
{
|
{
|
||||||
public:
|
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();
|
return yylex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,5 +22,3 @@ private:
|
||||||
virtual int yylex();
|
virtual int yylex();
|
||||||
yy::parser::semantic_type *yylval;
|
yy::parser::semantic_type *yylval;
|
||||||
};
|
};
|
||||||
|
|
||||||
int scanner_lex(yy::parser::semantic_type *yylval);
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue