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