token dump

This commit is contained in:
bronku 2025-11-20 13:09:53 +01:00
parent fd2d08fb24
commit 660306f6a5
3 changed files with 34 additions and 2 deletions

View file

@ -24,6 +24,7 @@ Configuration::Configuration(int argc, char **argv)
debug_lexer = true;
break;
default:
std::cerr << "Please specify input arguments\n";
}
}
valid = true;

View file

@ -2,12 +2,13 @@
%{
#include <iostream>
#include "../build/parser.hpp"
#define YY_DECL yy::Parser::symbol_type yylex(yyscan_t yyscanner, yy::location& loc)
#define YY_USER_ACTION loc.columns(yyleng);
#define yyterminate() return yy::Parser::make_END(loc)
#include "../build/parser.hpp"
%}

View file

@ -1,14 +1,44 @@
#include "../build/parser.hpp"
#include "../build/lexer.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[])
{
Elite::ParserCtx ctx;
Configuration config(argc, argv);
if (!config.valid)
{
std::cout << "Please provide a valid configuration\n";
return -1;
}
Elite::ParserCtx ctx;
if (config.debug_lexer)
{
dump_tokens(ctx);
return 0;
}
return ctx.parser->parse();
}