<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
I think an explanation for this can be found in the following comment in parse-tree.h.<br>
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>"// These are the unavoidable recursively-defined productions of Fortran.<br>
</span>
<div>// Some references to the representations of their parses require<br>
</div>
<div>// indirection.  The Indirect<> pointer wrapper class is used to<br>
</div>
<div>// enforce ownership semantics and non-nullability."<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Consider the definition of action-stmt (copied from <a href="https://github.com/llvm/llvm-project/blob/master/flang/documentation/f2018-grammar.txt">https://github.com/llvm/llvm-project/blob/master/flang/documentation/f2018-grammar.txt</a>) given below.
 You can see that action-stmt is recursively defined in terms of itself through the if-stmt. We know that C/C++ does not support recursively defined types (structs, tuples, variants). But it is possible to have a reference or pointer to the same type. Hence
 the use of the indirection.<br>
<a href="https://stackoverflow.com/questions/588623/self-referential-struct-definition" id="LPNoLP855338">https://stackoverflow.com/questions/588623/self-referential-struct-definition</a><br>
<br>
<br>
</div>
<div></div>
</div>
<span>"R515 action-stmt -><br>
</span>
<div>       allocate-stmt | assignment-stmt | backspace-stmt | call-stmt |<br>
</div>
<div>       close-stmt | continue-stmt | cycle-stmt | deallocate-stmt |<br>
</div>
<div>       endfile-stmt | error-stop-stmt | event-post-stmt | event-wait-stmt |<br>
</div>
<div>       exit-stmt | fail-image-stmt | flush-stmt | form-team-stmt |<br>
</div>
<div>       goto-stmt | if-stmt | inquire-stmt | lock-stmt | nullify-stmt |<br>
</div>
<div>       open-stmt | pointer-assignment-stmt | print-stmt | read-stmt |<br>
</div>
<div>       return-stmt | rewind-stmt | stop-stmt | sync-all-stmt |<br>
</div>
<div>       sync-images-stmt | sync-memory-stmt | sync-team-stmt | unlock-stmt |<br>
</div>
<div>       wait-stmt | where-stmt | write-stmt | computed-goto-stmt | forall-stmt<br>
</div>
<div><br>
</div>
<span>R1139 if-stmt -> IF ( scalar-logical-expr ) action-stmt"</span>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span></span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
--Kiran</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> flang-dev <flang-dev-bounces@lists.llvm.org> on behalf of ankit sharma via flang-dev <flang-dev@lists.llvm.org><br>
<b>Sent:</b> 30 April 2020 11:23<br>
<b>To:</b> flang-dev@lists.llvm.org <flang-dev@lists.llvm.org><br>
<b>Subject:</b> [flang-dev] Indirect reference in grammar.h</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div>Hi,</div>
<div><br>
</div>
<div>I am looking into source code and in grammar.h file, few production rules include indirect reference to parser's return type e.g. in ProgramUnit and ActionStmt.</div>
<div>How these productions are different from others by using indirect reference?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Ankit<br>
</div>
</div>
</div>
</body>
</html>