token dump
This commit is contained in:
parent
fd2d08fb24
commit
660306f6a5
3 changed files with 34 additions and 2 deletions
|
|
@ -24,6 +24,7 @@ Configuration::Configuration(int argc, char **argv)
|
||||||
debug_lexer = true;
|
debug_lexer = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
std::cerr << "Please specify input arguments\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
valid = true;
|
valid = true;
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../build/parser.hpp"
|
||||||
|
|
||||||
#define YY_DECL yy::Parser::symbol_type yylex(yyscan_t yyscanner, yy::location& loc)
|
#define YY_DECL yy::Parser::symbol_type yylex(yyscan_t yyscanner, yy::location& loc)
|
||||||
|
|
||||||
#define YY_USER_ACTION loc.columns(yyleng);
|
#define YY_USER_ACTION loc.columns(yyleng);
|
||||||
#define yyterminate() return yy::Parser::make_END(loc)
|
#define yyterminate() return yy::Parser::make_END(loc)
|
||||||
|
|
||||||
#include "../build/parser.hpp"
|
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
|
||||||
32
src/main.cpp
32
src/main.cpp
|
|
@ -1,14 +1,44 @@
|
||||||
#include "../build/parser.hpp"
|
#include "../build/parser.hpp"
|
||||||
|
#include "../build/lexer.hpp"
|
||||||
#include "../src/config.hpp"
|
#include "../src/config.hpp"
|
||||||
|
#include "../src/ParserCtx.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
yy::Parser::symbol_type yylex(yyscan_t yyscanner, yy::location &loc);
|
||||||
|
|
||||||
|
void dump_tokens(Elite::ParserCtx &ctx)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
auto tok = yylex(ctx.lexer, *ctx.loc);
|
||||||
|
|
||||||
|
std::cout
|
||||||
|
<< "Token: "
|
||||||
|
<< yy::Parser::symbol_name(tok.kind())
|
||||||
|
<< ", Location: " << tok.location
|
||||||
|
<< '\n';
|
||||||
|
|
||||||
|
if (tok.kind() == yy::Parser::token::END)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
Elite::ParserCtx ctx;
|
||||||
Configuration config(argc, argv);
|
Configuration config(argc, argv);
|
||||||
if (!config.valid)
|
if (!config.valid)
|
||||||
{
|
{
|
||||||
std::cout << "Please provide a valid configuration\n";
|
std::cout << "Please provide a valid configuration\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Elite::ParserCtx ctx;
|
|
||||||
|
if (config.debug_lexer)
|
||||||
|
{
|
||||||
|
dump_tokens(ctx);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.parser->parse();
|
return ctx.parser->parse();
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue