elna/cli/main.cc

42 lines
902 B
C++
Raw Normal View History

2024-12-23 13:54:11 +01:00
#include <elna/source/driver.h>
#include "parser.hh"
2024-12-21 00:08:48 +01:00
#include <sstream>
2024-12-23 13:54:11 +01:00
constexpr std::size_t pointer_size = 4;
2024-12-21 00:08:48 +01:00
int main()
{
2024-12-21 14:05:27 +01:00
elna::source::driver driver{ "-" };
std::istringstream inp(R"(
proc f();
begin
end;
2024-12-21 00:08:48 +01:00
2024-12-27 10:51:46 +01:00
var x: Int;
2024-12-21 14:05:27 +01:00
begin
2024-12-27 10:51:46 +01:00
x := 4 + 2
2024-12-21 14:05:27 +01:00
end.
)");
2024-12-21 00:08:48 +01:00
2024-12-21 14:05:27 +01:00
elna::source::lexer lexer(inp);
yy::parser parser(lexer, driver);
if (auto result = parser())
2024-12-21 00:08:48 +01:00
{
2024-12-21 14:05:27 +01:00
for (const auto& error : driver.errors())
{
2024-12-27 10:51:46 +01:00
std::cerr << error->path << ':'
2024-12-21 14:05:27 +01:00
<< error->line() << ':' << error->column()
<< ": error: " << error->what()
<< '.' << std::endl;
}
return result;
}
for (auto& definition : driver.tree->definitions())
{
2024-12-27 10:51:46 +01:00
std::cout << "Definition identifier: " << definition->identifier() << std::endl;
2024-12-21 00:08:48 +01:00
}
2024-12-21 14:05:27 +01:00
return 0;
2024-12-21 00:08:48 +01:00
}