[flang-dev] Question on the parser code
Mark Dewing via flang-dev
flang-dev at lists.llvm.org
Tue Dec 3 13:59:54 PST 2019
Hi,
I'm trying to understand the F18 parser and the parse tree code by
creating some simple examples. I would like to create a simple parser and
also create a parse tree programmatically, but I'm running into some
problems.
For the first step, I added a constructor to ParseState that accepts a
std::string (to avoid constructing a CookedSource object). The following
code works:
#include "token-parsers.h"
using namespace Fortran::parser;
int main()
{
std::string test("b");
ParseState p(test);
auto p1 = "a"_ch;
auto res = p1.Parse(p);
std::cout << " res = " << res.value_or("no result") << std::endl;
return 0;
}
For the second step, I would like to create a parse tree programmatically
and call unparse.
The first problem is I am unable to build a MainProgram with a minimal set
of inputs.
So far, the code to create some of the elements is as follows:
SpecificationPart spec{std::list<OpenMPDeclarativeConstruct>{},
std::list<Statement<Fortran::common::Indirection<UseStmt>>>{} ,
std::list<Statement<Fortran::common::Indirection<ImportStmt>>>{},
ImplicitPart{std::list<ImplicitPartStmt>{}},
std::list<DeclarationConstruct>{}};
ExecutionPart exec{std::list<ExecutionPartConstruct>{}};
Statement<EndProgramStmt> end{Statement<EndProgramStmt>{std::nullopt,
EndProgramStmt{std::nullopt}}};
The problem is constructing the tuple for the MainProgram - all these
objects cause compile errors when placed in a tuple ("no matching
constructor" errors). If anyone has better example code, or instructions
on how to do this properly, I would appreciate it.
Thanks,
Mark Dewing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/flang-dev/attachments/20191203/f2585951/attachment.html>
More information about the flang-dev
mailing list