Parse variable declarations
This commit is contained in:
49
cli/main.cpp
49
cli/main.cpp
@ -1,22 +1,49 @@
|
||||
#include <elna/source/driver.hpp>
|
||||
#include "parser.hpp"
|
||||
#include <sstream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::istringstream inp("const world = 5, hello = 7;");
|
||||
elna::source::driver driver{ "-" };
|
||||
std::istringstream inp(R"(
|
||||
const world = 5, hello = 7;
|
||||
var x: int, y: boolean;
|
||||
|
||||
std::unique_ptr<elna::source::program> program;
|
||||
proc f();
|
||||
begin
|
||||
x := 8
|
||||
end;
|
||||
|
||||
elna::syntax::FooLexer lexer(inp);
|
||||
yy::parser parser(lexer, program);
|
||||
auto result = parser();
|
||||
begin
|
||||
while false do inc(5)
|
||||
end.
|
||||
)");
|
||||
|
||||
for (auto& definition : program->definitions())
|
||||
elna::source::lexer lexer(inp);
|
||||
yy::parser parser(lexer, driver);
|
||||
|
||||
if (auto result = parser())
|
||||
{
|
||||
auto const_definition = dynamic_cast<elna::source::constant_definition *>(definition.get());
|
||||
|
||||
std::cout << "const " << const_definition->identifier() << " = "
|
||||
<< const_definition->body().number() << std::endl;
|
||||
for (const auto& error : driver.errors())
|
||||
{
|
||||
std::cerr << error->path().string() << ':'
|
||||
<< error->line() << ':' << error->column()
|
||||
<< ": error: " << error->what()
|
||||
<< '.' << std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user