50 lines
1.3 KiB
C++
50 lines
1.3 KiB
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, y: boolean;
|
|
|
|
proc f();
|
|
begin
|
|
x := 8
|
|
end;
|
|
|
|
begin
|
|
while false do inc(5)
|
|
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())
|
|
{
|
|
if (auto const_definition = dynamic_cast<elna::source::constant_definition *>(definition.get()))
|
|
{
|
|
std::cout << "const " << const_definition->identifier() << " = "
|
|
<< const_definition->body().number() << std::endl;
|
|
}
|
|
else if (auto proc_definition = dynamic_cast<elna::source::procedure_definition *>(definition.get()))
|
|
{
|
|
std::cout << "const " << proc_definition->identifier() << "()" << std::endl;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|