diff --git a/src/config.cpp b/src/config.cpp index 7e313b2..7b31a76 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -24,6 +24,7 @@ Configuration::Configuration(int argc, char **argv) debug_lexer = true; break; default: + std::cerr << "Please specify input arguments\n"; } } valid = true; diff --git a/src/lexer.l b/src/lexer.l index 68f93b0..56bfb38 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -2,12 +2,13 @@ %{ #include +#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" %} diff --git a/src/main.cpp b/src/main.cpp index 97ca6da..82a4845 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,44 @@ #include "../build/parser.hpp" +#include "../build/lexer.hpp" #include "../src/config.hpp" +#include "../src/ParserCtx.hpp" +#include +#include + +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(); } \ No newline at end of file