38 lines
990 B
C++
38 lines
990 B
C++
#include <elna/source/driver.hpp>
|
|
#include "parser.hpp"
|
|
#include <sstream>
|
|
|
|
int main()
|
|
{
|
|
elna::source::driver driver{ "-" };
|
|
std::istringstream inp(R"(
|
|
const world = 5, hello = 7;
|
|
var x: int;
|
|
begin
|
|
end.
|
|
)");
|
|
|
|
elna::source::lexer lexer(inp);
|
|
yy::parser parser(lexer, driver);
|
|
|
|
if (auto result = parser())
|
|
{
|
|
for (const auto& error : driver.errors())
|
|
{
|
|
std::cerr << error->path().string() << ':'
|
|
<< error->line() << ':' << error->column()
|
|
<< ": error: " << error->what()
|
|
<< '.' << std::endl;
|
|
}
|
|
return result;
|
|
}
|
|
for (auto& definition : driver.tree->definitions())
|
|
{
|
|
auto const_definition = dynamic_cast<elna::source::constant_definition *>(definition.get());
|
|
|
|
std::cout << "const " << const_definition->identifier() << " = "
|
|
<< const_definition->body().number() << std::endl;
|
|
}
|
|
return 0;
|
|
}
|