fortran.y 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225
  1. /******************************************************************************/
  2. /* */
  3. /* CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran) */
  4. /* */
  5. /* Copyright or or Copr. Laurent Debreu (Laurent.Debreu@imag.fr) */
  6. /* Cyril Mazauric (Cyril_Mazauric@yahoo.fr) */
  7. /* This software is governed by the CeCILL-C license under French law and */
  8. /* abiding by the rules of distribution of free software. You can use, */
  9. /* modify and/ or redistribute the software under the terms of the CeCILL-C */
  10. /* license as circulated by CEA, CNRS and INRIA at the following URL */
  11. /* "http ://www.cecill.info". */
  12. /* */
  13. /* As a counterpart to the access to the source code and rights to copy, */
  14. /* modify and redistribute granted by the license, users are provided only */
  15. /* with a limited warranty and the software's author, the holder of the */
  16. /* economic rights, and the successive licensors have only limited */
  17. /* liability. */
  18. /* */
  19. /* In this respect, the user's attention is drawn to the risks associated */
  20. /* with loading, using, modifying and/or developing or reproducing the */
  21. /* software by the user in light of its specific status of free software, */
  22. /* that may mean that it is complicated to manipulate, and that also */
  23. /* therefore means that it is reserved for developers and experienced */
  24. /* professionals having in-depth computer knowledge. Users are therefore */
  25. /* encouraged to load and test the software's suitability as regards their */
  26. /* requirements in conditions enabling the security of their systems and/or */
  27. /* data to be ensured and, more generally, to use and operate it in the */
  28. /* same conditions as regards security. */
  29. /* */
  30. /* The fact that you are presently reading this means that you have had */
  31. /* knowledge of the CeCILL-C license and that you accept its terms. */
  32. /******************************************************************************/
  33. /* version 1.7 */
  34. /******************************************************************************/
  35. %{
  36. #define YYMAXDEPTH 1000
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include "decl.h"
  41. extern int line_num_input;
  42. extern char *fortran_text;
  43. char c_selectorname[LONG_M];
  44. char ligne[LONG_M];
  45. char truename[LONG_VNAME];
  46. char identcopy[LONG_VNAME];
  47. int c_selectorgiven=0;
  48. listvar *curlistvar;
  49. typedim c_selectordim;
  50. listcouple *coupletmp;
  51. int removeline=0;
  52. listvar *test;
  53. int fortran_error(const char *s)
  54. {
  55. printf("%s line %d, file %s motclef = |%s|\n", s, line_num_input, cur_filename, fortran_text);
  56. exit(1);
  57. }
  58. %}
  59. %union {
  60. char na[LONG_M];
  61. listdim *d;
  62. listvar *l;
  63. listcouple *lc;
  64. listname *lnn;
  65. typedim dim1;
  66. variable *v;
  67. }
  68. %left ','
  69. %nonassoc ':'
  70. %right '='
  71. %left TOK_EQV TOK_NEQV
  72. %left TOK_OR TOK_XOR
  73. %left TOK_AND
  74. %left TOK_NOT
  75. %nonassoc TOK_LT TOK_GT TOK_LE TOK_GE TOK_EQ TOK_NE
  76. %left TOK_DSLASH
  77. %left '+' '-'
  78. %left '*' TOK_SLASH
  79. %right TOK_DASTER
  80. %token TOK_SEMICOLON
  81. %token TOK_PARAMETER
  82. %token TOK_RESULT
  83. %token TOK_ONLY
  84. %token TOK_INCLUDE
  85. %token TOK_SUBROUTINE
  86. %token TOK_PROGRAM
  87. %token TOK_FUNCTION
  88. %token TOK_FORMAT
  89. %token TOK_MAX
  90. %token TOK_TANH
  91. %token TOK_WHERE
  92. %token TOK_ELSEWHEREPAR
  93. %token TOK_ELSEWHERE
  94. %token TOK_ENDWHERE
  95. %token TOK_MAXVAL
  96. %token TOK_TRIM
  97. %token TOK_NULL_PTR
  98. %token TOK_SUM
  99. %token TOK_SQRT
  100. %token TOK_CASE
  101. %token TOK_SELECTCASE
  102. %token TOK_FILE
  103. %token TOK_UNIT
  104. %token TOK_FMT
  105. %token TOK_NML
  106. %token TOK_END
  107. %token TOK_EOR
  108. %token TOK_ERR
  109. %token TOK_EXIST
  110. %token TOK_MIN
  111. %token TOK_FLOAT
  112. %token TOK_EXP
  113. %token TOK_COS
  114. %token TOK_COSH
  115. %token TOK_ACOS
  116. %token TOK_NINT
  117. %token TOK_CYCLE
  118. %token TOK_SIN
  119. %token TOK_SINH
  120. %token TOK_ASIN
  121. %token TOK_EQUIVALENCE
  122. %token TOK_BACKSPACE
  123. %token TOK_LOG
  124. %token TOK_TAN
  125. %token TOK_ATAN
  126. %token TOK_RECURSIVE
  127. %token TOK_ABS
  128. %token TOK_MOD
  129. %token TOK_SIGN
  130. %token TOK_MINLOC
  131. %token TOK_MAXLOC
  132. %token TOK_EXIT
  133. %token TOK_MINVAL
  134. %token TOK_PUBLIC
  135. %token TOK_PRIVATE
  136. %token TOK_ALLOCATABLE
  137. %token TOK_RETURN
  138. %token TOK_THEN
  139. %token TOK_ELSEIF
  140. %token TOK_ELSE
  141. %token TOK_ENDIF
  142. %token TOK_PRINT
  143. %token TOK_PLAINGOTO
  144. %token TOK_LOGICALIF
  145. %token TOK_PLAINDO
  146. %token TOK_CONTAINS
  147. %token TOK_ENDDO
  148. %token TOK_MODULE
  149. %token TOK_ENDMODULE
  150. %token TOK_WHILE
  151. %token TOK_CONCURRENT
  152. %token TOK_ALLOCATE
  153. %token TOK_OPEN
  154. %token TOK_CLOSE
  155. %token TOK_INQUIRE
  156. %token TOK_WRITE
  157. %token TOK_FLUSH
  158. %token TOK_READ
  159. %token TOK_REWIND
  160. %token TOK_DEALLOCATE
  161. %token TOK_NULLIFY
  162. %token TOK_DIMENSION
  163. %token TOK_ENDSELECT
  164. %token TOK_EXTERNAL
  165. %token TOK_INTENT
  166. %token TOK_INTRINSIC
  167. %token TOK_NAMELIST
  168. %token TOK_DEFAULT
  169. %token TOK_OPTIONAL
  170. %token TOK_POINTER
  171. %token TOK_CONTINUE
  172. %token TOK_SAVE
  173. %token TOK_TARGET
  174. %token TOK_IMPLICIT
  175. %token TOK_NONE
  176. %token TOK_CALL
  177. %token TOK_STAT
  178. %token TOK_POINT_TO
  179. %token TOK_COMMON
  180. %token TOK_GLOBAL
  181. %token TOK_LEFTAB
  182. %token TOK_RIGHTAB
  183. %token TOK_PAUSE
  184. %token TOK_PROCEDURE
  185. %token TOK_STOP
  186. %token TOK_REAL8
  187. %token TOK_FOURDOTS
  188. %token <na> TOK_HEXA
  189. %token <na> TOK_ASSIGNTYPE
  190. %token <na> TOK_OUT
  191. %token <na> TOK_INOUT
  192. %token <na> TOK_IN
  193. %token <na> TOK_USE
  194. %token <na> TOK_DSLASH
  195. %token <na> TOK_DASTER
  196. %token <na> TOK_EQ
  197. %token <na> TOK_EQV
  198. %token <na> TOK_GT
  199. %token <na> TOK_LT
  200. %token <na> TOK_GE
  201. %token <na> TOK_NE
  202. %token <na> TOK_NEQV
  203. %token <na> TOK_LE
  204. %token <na> TOK_OR
  205. %token <na> TOK_XOR
  206. %token <na> TOK_NOT
  207. %token <na> TOK_AND
  208. %token <na> TOK_TRUE
  209. %token <na> TOK_FALSE
  210. %token <na> TOK_LABEL
  211. %token <na> TOK_TYPE
  212. %token <na> TOK_TYPEPAR
  213. %token <na> TOK_ENDTYPE
  214. %token <na> TOK_REAL
  215. %token <na> TOK_INTEGER
  216. %token <na> TOK_LOGICAL
  217. %token <na> TOK_DOUBLEPRECISION
  218. %token <na> TOK_ENDSUBROUTINE
  219. %token <na> TOK_ENDFUNCTION
  220. %token <na> TOK_ENDPROGRAM
  221. %token <na> TOK_ENDUNIT
  222. %token <na> TOK_CHARACTER
  223. %token <na> TOK_CHAR_CONSTANT
  224. %token <na> TOK_CHAR_CUT
  225. %token <na> TOK_DATA
  226. %token <na> TOK_CHAR_MESSAGE
  227. %token <na> TOK_CSTREAL
  228. %token <na> TOK_COMPLEX
  229. %token <na> TOK_DOUBLECOMPLEX
  230. %token <na> TOK_NAME
  231. %token <na> TOK_SLASH
  232. %token <na> TOK_CSTINT
  233. %token ','
  234. %token ':'
  235. %token '('
  236. %token ')'
  237. %token '<'
  238. %token '>'
  239. %type <l> dcl
  240. %type <l> after_type
  241. %type <l> dimension
  242. %type <l> paramlist
  243. %type <l> args
  244. %type <l> arglist
  245. %type <lc> only_list
  246. %type <lc> only_name
  247. %type <lc> rename_list
  248. %type <lc> rename_name
  249. %type <d> dims
  250. %type <d> dimlist
  251. %type <dim1> dim
  252. %type <v> paramitem
  253. %type <na> comblock
  254. %type <na> name_routine
  255. %type <na> opt_name
  256. %type <na> type
  257. %type <na> word_endsubroutine
  258. %type <na> word_endfunction
  259. %type <na> word_endprogram
  260. %type <na> word_endunit
  261. %type <na> typespec
  262. %type <na> string_constant
  263. %type <na> simple_const
  264. %type <na> ident
  265. %type <na> intent_spec
  266. %type <na> signe
  267. %type <na> opt_signe
  268. %type <na> filename
  269. %type <na> attribute
  270. %type <na> complex_const
  271. %type <na> begin_array
  272. %type <na> clause
  273. %type <na> arg
  274. %type <na> uexpr
  275. %type <na> minmaxlist
  276. %type <na> lhs
  277. %type <na> vec
  278. %type <na> outlist
  279. %type <na> other
  280. %type <na> dospec
  281. %type <na> expr_data
  282. %type <na> structure_component
  283. %type <na> array_ele_substring_func_ref
  284. %type <na> funarglist
  285. %type <na> funarg
  286. %type <na> funargs
  287. %type <na> triplet
  288. %type <na> substring
  289. %type <na> opt_substring
  290. %type <na> opt_expr
  291. %type <na> optexpr
  292. %type <lnn> data_stmt_value_list
  293. %type <lnn> datanamelist
  294. %type <na> after_slash
  295. %type <na> after_equal
  296. %type <na> predefinedfunction
  297. %type <na> expr
  298. %type <na> ubound
  299. %type <na> operation
  300. %type <na> proper_lengspec
  301. %type <lnn> use_name_list
  302. %type <lnn> public
  303. %%
  304. input :
  305. | input line
  306. ;
  307. line : line-break
  308. | suite_line_list
  309. | TOK_LABEL suite_line_list
  310. | error {yyerrok;yyclearin;}
  311. ;
  312. line-break:
  313. '\n' fin_line
  314. | TOK_SEMICOLON
  315. | line-break '\n' fin_line
  316. | line-break TOK_SEMICOLON
  317. | line-break TOK_LABEL
  318. ;
  319. suite_line_list :
  320. suite_line
  321. | suite_line_list TOK_SEMICOLON '\n'
  322. | suite_line_list TOK_SEMICOLON suite_line
  323. ;
  324. suite_line :
  325. entry fin_line /* subroutine, function, module */
  326. | spec fin_line /* declaration */
  327. | TOK_INCLUDE filename fin_line
  328. {
  329. if (inmoduledeclare == 0 )
  330. {
  331. pos_end = setposcur();
  332. RemoveWordSET_0(fortran_out,pos_curinclude,pos_end-pos_curinclude);
  333. }
  334. }
  335. | execution-part-construct
  336. ;
  337. fin_line : { pos_cur = setposcur(); }
  338. ;
  339. opt_recursive : { isrecursive = 0; }
  340. | TOK_RECURSIVE { isrecursive = 1; }
  341. ;
  342. opt_result : { is_result_present = 0; }
  343. | TOK_RESULT arglist_after_result { is_result_present = 1; }
  344. ;
  345. entry : opt_recursive TOK_SUBROUTINE name_routine arglist
  346. {
  347. insubroutinedeclare = 1;
  348. if ( firstpass )
  349. Add_SubroutineArgument_Var_1($4);
  350. else
  351. WriteBeginof_SubLoop();
  352. }
  353. | TOK_PROGRAM name_routine
  354. {
  355. insubroutinedeclare = 1;
  356. inprogramdeclare = 1;
  357. /* in the second step we should write the head of */
  358. /* the subroutine sub_loop_<subroutinename> */
  359. if ( ! firstpass )
  360. WriteBeginof_SubLoop();
  361. }
  362. | opt_recursive TOK_FUNCTION name_routine arglist opt_result
  363. {
  364. insubroutinedeclare = 1;
  365. strcpy(DeclType, "");
  366. /* we should to list of the subroutine argument the */
  367. /* name of the function which has to be defined */
  368. if ( firstpass )
  369. {
  370. Add_SubroutineArgument_Var_1($4);
  371. if ( ! is_result_present )
  372. Add_FunctionType_Var_1($3);
  373. }
  374. else
  375. /* in the second step we should write the head of */
  376. /* the subroutine sub_loop_<subroutinename> */
  377. WriteBeginof_SubLoop();
  378. }
  379. | TOK_MODULE TOK_NAME
  380. {
  381. GlobalDeclaration = 0;
  382. strcpy(curmodulename,$2);
  383. strcpy(subroutinename,"");
  384. Add_NameOfModule_1($2);
  385. if ( inmoduledeclare == 0 )
  386. {
  387. /* To know if there are in the module declaration */
  388. inmoduledeclare = 1;
  389. /* to know if a module has been met */
  390. inmodulemeet = 1;
  391. /* to know if we are after the keyword contains */
  392. aftercontainsdeclare = 0 ;
  393. }
  394. }
  395. ;
  396. /* R312 : label */
  397. label: TOK_CSTINT
  398. | label TOK_CSTINT
  399. ;
  400. name_routine : TOK_NAME { strcpy($$, $1); strcpy(subroutinename, $1); }
  401. ;
  402. filename : TOK_CHAR_CONSTANT { Add_Include_1($1); }
  403. ;
  404. arglist : { if ( firstpass ) $$=NULL; }
  405. | '(' ')' { if ( firstpass ) $$=NULL; }
  406. | '(' args ')' { if ( firstpass ) $$=$2; }
  407. ;
  408. arglist_after_result:
  409. | '(' ')'
  410. | '(' args ')' { if ( firstpass ) Add_SubroutineArgument_Var_1($2); }
  411. ;
  412. args : arg
  413. {
  414. if ( firstpass == 1 )
  415. {
  416. strcpy(nameinttypenameback,nameinttypename);
  417. strcpy(nameinttypename,"");
  418. curvar = createvar($1,NULL);
  419. strcpy(nameinttypename,nameinttypenameback);
  420. curlistvar = insertvar(NULL,curvar);
  421. $$ = settype("",curlistvar);
  422. }
  423. }
  424. | args ',' arg
  425. {
  426. if ( firstpass == 1 )
  427. {
  428. strcpy(nameinttypenameback,nameinttypename);
  429. strcpy(nameinttypename,"");
  430. curvar = createvar($3,NULL);
  431. strcpy(nameinttypename,nameinttypenameback);
  432. $$ = insertvar($1,curvar);
  433. }
  434. }
  435. ;
  436. arg : TOK_NAME { strcpy($$,$1); }
  437. | '*' { strcpy($$,"*"); }
  438. ;
  439. spec : type after_type
  440. | TOK_TYPE opt_spec opt_sep opt_name { inside_type_declare = 1; }
  441. | TOK_ENDTYPE opt_name { inside_type_declare = 0; }
  442. | TOK_POINTER list_couple
  443. | before_parameter '(' paramlist ')'
  444. {
  445. if ( ! inside_type_declare )
  446. {
  447. if ( firstpass )
  448. {
  449. if ( insubroutinedeclare ) Add_Parameter_Var_1($3);
  450. else Add_GlobalParameter_Var_1($3);
  451. }
  452. else
  453. {
  454. pos_end = setposcur();
  455. RemoveWordSET_0(fortran_out, pos_cur_decl, pos_end-pos_cur_decl);
  456. }
  457. }
  458. VariableIsParameter = 0 ;
  459. }
  460. | before_parameter paramlist
  461. {
  462. if ( ! inside_type_declare )
  463. {
  464. if ( firstpass )
  465. {
  466. if ( insubroutinedeclare ) Add_Parameter_Var_1($2);
  467. else Add_GlobalParameter_Var_1($2);
  468. }
  469. else
  470. {
  471. pos_end = setposcur();
  472. RemoveWordSET_0(fortran_out,pos_cur_decl,pos_end-pos_cur_decl);
  473. }
  474. }
  475. VariableIsParameter = 0 ;
  476. }
  477. | common
  478. | save
  479. {
  480. pos_end = setposcur();
  481. RemoveWordSET_0(fortran_out,pos_cursave,pos_end-pos_cursave);
  482. }
  483. | implicit
  484. | dimension
  485. {
  486. /* if the variable is a parameter we can suppose that is */
  487. /* value is the same on each grid. It is not useless to */
  488. /* create a copy of it on each grid */
  489. if ( ! inside_type_declare )
  490. {
  491. if ( firstpass )
  492. {
  493. Add_Globliste_1($1);
  494. /* if variableparamlists has been declared in a subroutine */
  495. if ( insubroutinedeclare ) Add_Dimension_Var_1($1);
  496. }
  497. else
  498. {
  499. pos_end = setposcur();
  500. RemoveWordSET_0(fortran_out,pos_curdimension,pos_end-pos_curdimension);
  501. }
  502. }
  503. PublicDeclare = 0;
  504. PrivateDeclare = 0;
  505. ExternalDeclare = 0;
  506. strcpy(NamePrecision,"");
  507. c_star = 0;
  508. InitialValueGiven = 0 ;
  509. strcpy(IntentSpec,"");
  510. VariableIsParameter = 0 ;
  511. Allocatabledeclare = 0 ;
  512. Targetdeclare = 0 ;
  513. SaveDeclare = 0;
  514. pointerdeclare = 0;
  515. optionaldeclare = 0 ;
  516. dimsgiven=0;
  517. c_selectorgiven=0;
  518. strcpy(nameinttypename,"");
  519. strcpy(c_selectorname,"");
  520. }
  521. | public
  522. {
  523. if (firstpass == 0)
  524. {
  525. if ($1)
  526. {
  527. removeglobfromlist(&($1));
  528. pos_end = setposcur();
  529. RemoveWordSET_0(fortran_out,pos_cur,pos_end-pos_cur);
  530. writelistpublic($1);
  531. }
  532. }
  533. }
  534. | private
  535. | use_stat
  536. | module_proc_stmt
  537. | namelist
  538. | TOK_BACKSPACE '(' expr ')'
  539. | TOK_EXTERNAL opt_sep use_name_list
  540. | TOK_INTRINSIC opt_sep use_intrinsic_list
  541. | TOK_EQUIVALENCE list_expr_equi
  542. | data_stmt '\n'
  543. {
  544. /* we should remove the data declaration */
  545. pos_end = setposcur();
  546. RemoveWordSET_0(fortran_out,pos_curdata,pos_end-pos_curdata);
  547. if ( aftercontainsdeclare == 1 && firstpass == 0 )
  548. {
  549. ReWriteDataStatement_0(fortran_out);
  550. pos_end = setposcur();
  551. }
  552. }
  553. ;
  554. opt_spec :
  555. | access_spec
  556. {
  557. PublicDeclare = 0 ;
  558. PrivateDeclare = 0 ;
  559. }
  560. ;
  561. name_intrinsic :
  562. TOK_SUM
  563. | TOK_TANH
  564. | TOK_MAXVAL
  565. | TOK_MIN
  566. | TOK_MINVAL
  567. | TOK_TRIM
  568. | TOK_SQRT
  569. | TOK_NINT
  570. | TOK_FLOAT
  571. | TOK_EXP
  572. | TOK_COS
  573. | TOK_COSH
  574. | TOK_ACOS
  575. | TOK_SIN
  576. | TOK_SINH
  577. | TOK_ASIN
  578. | TOK_LOG
  579. | TOK_TAN
  580. | TOK_ATAN
  581. | TOK_MOD
  582. | TOK_SIGN
  583. | TOK_MINLOC
  584. | TOK_MAXLOC
  585. | TOK_NAME
  586. ;
  587. use_intrinsic_list :
  588. name_intrinsic
  589. | use_intrinsic_list ',' name_intrinsic
  590. ;
  591. list_couple :
  592. '(' list_expr ')'
  593. | list_couple ',' '(' list_expr ')'
  594. ;
  595. list_expr_equi :
  596. expr_equi
  597. | list_expr_equi ',' expr_equi
  598. ;
  599. expr_equi : '(' list_expr_equi1 ')'
  600. ;
  601. list_expr_equi1 :
  602. ident dims
  603. | list_expr_equi1 ',' ident dims
  604. ;
  605. list_expr :
  606. expr
  607. | list_expr ',' expr
  608. ;
  609. opt_sep :
  610. | TOK_FOURDOTS
  611. ;
  612. after_type :
  613. dcl nodimsgiven
  614. {
  615. /* if the variable is a parameter we can suppose that is*/
  616. /* value is the same on each grid. It is not useless */
  617. /* to create a copy of it on each grid */
  618. if ( ! inside_type_declare )
  619. {
  620. pos_end = setposcur();
  621. RemoveWordSET_0(fortran_out,pos_cur_decl,pos_end-pos_cur_decl);
  622. ReWriteDeclarationAndAddTosubroutine_01($1);
  623. pos_cur_decl = setposcur();
  624. if ( firstpass == 0 && GlobalDeclaration == 0
  625. && insubroutinedeclare == 0 )
  626. {
  627. fprintf(fortran_out,"\n#include \"Module_Declar_%s.h\"\n", curmodulename);
  628. sprintf(ligne, "Module_Declar_%s.h", curmodulename);
  629. module_declar = open_for_write(ligne);
  630. GlobalDeclaration = 1 ;
  631. pos_cur_decl = setposcur();
  632. }
  633. $$ = $1;
  634. if ( firstpass )
  635. {
  636. Add_Globliste_1($1);
  637. if ( insubroutinedeclare )
  638. {
  639. if ( pointerdeclare ) Add_Pointer_Var_From_List_1($1);
  640. Add_Parameter_Var_1($1);
  641. }
  642. else
  643. Add_GlobalParameter_Var_1($1);
  644. /* If there's a SAVE declaration in module's subroutines we should */
  645. /* remove it from the subroutines declaration and add it in the */
  646. /* global declarations */
  647. if ( aftercontainsdeclare && SaveDeclare )
  648. {
  649. if ( inmodulemeet ) Add_SubroutineDeclarationSave_Var_1($1);
  650. else Add_Save_Var_dcl_1($1);
  651. }
  652. }
  653. }
  654. else
  655. {
  656. $$ = (listvar *) NULL;
  657. }
  658. PublicDeclare = 0;
  659. PrivateDeclare = 0;
  660. ExternalDeclare = 0;
  661. strcpy(NamePrecision,"");
  662. c_star = 0;
  663. InitialValueGiven = 0 ;
  664. strcpy(IntentSpec,"");
  665. VariableIsParameter = 0 ;
  666. Allocatabledeclare = 0 ;
  667. Targetdeclare = 0 ;
  668. SaveDeclare = 0;
  669. pointerdeclare = 0;
  670. optionaldeclare = 0 ;
  671. dimsgiven=0;
  672. c_selectorgiven=0;
  673. strcpy(nameinttypename,"");
  674. strcpy(c_selectorname,"");
  675. GlobalDeclarationType = 0;
  676. }
  677. | before_function name_routine arglist
  678. {
  679. insubroutinedeclare = 1;
  680. if ( firstpass )
  681. {
  682. Add_SubroutineArgument_Var_1($3);
  683. Add_FunctionType_Var_1($2);
  684. }
  685. else
  686. WriteBeginof_SubLoop();
  687. strcpy(nameinttypename,"");
  688. }
  689. ;
  690. before_function : TOK_FUNCTION { functiondeclarationisdone = 1; }
  691. ;
  692. before_parameter : TOK_PARAMETER { VariableIsParameter = 1; pos_curparameter = setposcur()-9; }
  693. ;
  694. data_stmt : /* R534 */
  695. TOK_DATA data_stmt_set_list
  696. data_stmt_set_list :
  697. data_stmt_set
  698. | data_stmt_set_list opt_comma data_stmt_set
  699. data_stmt_set : /* R535 */
  700. TOK_NAME TOK_SLASH data_stmt_value_list TOK_SLASH
  701. {
  702. createstringfromlistname(ligne,$3);
  703. if (firstpass == 1) Add_Data_Var_1(&List_Data_Var,$1,ligne);
  704. else Add_Data_Var_1(&List_Data_Var_Cur,$1,ligne);
  705. }
  706. | datanamelist TOK_SLASH data_stmt_value_list TOK_SLASH
  707. {
  708. if (firstpass == 1) Add_Data_Var_Names_01(&List_Data_Var,$1,$3);
  709. else Add_Data_Var_Names_01(&List_Data_Var_Cur,$1,$3);
  710. }
  711. | '(' lhs ',' dospec ')' TOK_SLASH data_stmt_value_list TOK_SLASH
  712. {
  713. createstringfromlistname(ligne,$7);
  714. printf("###################################################################################################################\n");
  715. printf("## CONV Error : data_implied_do statements (R537) are not yet supported. Please complain to the proper authorities.\n");
  716. printf("l.%4d -- data_stmt_set : ( lhs , dospec ) /data_stmt_value_list/ -- lhs=|%s| dospec=|%s| data_stmt_value_list=|%s|\n",
  717. line_num_input,$2,$4,ligne);
  718. printf("## But, are you SURE you NEED a DATA construct ?\n");
  719. printf("###################################################################################################################\n");
  720. exit(1);
  721. }
  722. ;
  723. data_stmt_value_list :
  724. expr_data { $$ = Insertname(NULL,$1,0); }
  725. | expr_data ',' data_stmt_value_list { $$ = Insertname($3,$1,1); }
  726. ;
  727. save : before_save varsave
  728. | before_save comblock varsave
  729. | save opt_comma comblock opt_comma varsave
  730. | save ',' varsave
  731. ;
  732. before_save :
  733. TOK_SAVE { pos_cursave = setposcur()-4; }
  734. ;
  735. varsave :
  736. | TOK_NAME dims { if ( ! inside_type_declare ) Add_Save_Var_1($1,$2); }
  737. ;
  738. datanamelist :
  739. TOK_NAME { $$ = Insertname(NULL,$1,0); }
  740. | TOK_NAME '(' expr ')' { printf("l.%4d -- INSTRUCTION NON TRAITEE : INITIALISATION DE DATA AVEC EXPRESSION\n",line_num_input); exit(0); }
  741. | datanamelist ',' datanamelist { $$ = concat_listname($1,$3); }
  742. ;
  743. expr_data :
  744. opt_signe simple_const { sprintf($$,"%s%s",$1,$2); }
  745. | expr_data '+' expr_data { sprintf($$,"%s+%s",$1,$3); }
  746. | expr_data '-' expr_data { sprintf($$,"%s-%s",$1,$3); }
  747. | expr_data '*' expr_data { sprintf($$,"%s*%s",$1,$3); }
  748. | expr_data '/' expr_data { sprintf($$,"%s/%s",$1,$3); }
  749. ;
  750. opt_signe : { strcpy($$,""); }
  751. | signe { strcpy($$,$1); }
  752. ;
  753. namelist :
  754. TOK_NAMELIST ident
  755. | TOK_NAMELIST comblock ident
  756. | namelist opt_comma comblock opt_comma ident
  757. | namelist ',' ident
  758. ;
  759. before_dimension :
  760. TOK_DIMENSION
  761. {
  762. positioninblock = 0;
  763. pos_curdimension = setposcur()-9;
  764. }
  765. dimension :
  766. before_dimension opt_comma TOK_NAME dims lengspec
  767. {
  768. printf("l.%4d -- dimension : before_dimension opt_comma TOK_NAME = |%s| -- MHCHECK\n",line_num_input,$3);
  769. if ( inside_type_declare ) break;
  770. curvar = createvar($3,$4);
  771. CreateAndFillin_Curvar("", curvar);
  772. curlistvar=insertvar(NULL, curvar);
  773. $$ = settype("",curlistvar);
  774. strcpy(vallengspec,"");
  775. }
  776. | dimension ',' TOK_NAME dims lengspec
  777. {
  778. printf("l.%4d -- dimension : dimension ',' TOK_NAME dims lengspec = |%s| -- MHCHECK\n",line_num_input,$3);
  779. if ( inside_type_declare ) break;
  780. curvar = createvar($3,$4);
  781. CreateAndFillin_Curvar("", curvar);
  782. curlistvar = insertvar($1, curvar);
  783. $$ = curlistvar;
  784. strcpy(vallengspec,"");
  785. }
  786. ;
  787. private :
  788. TOK_PRIVATE '\n'
  789. | TOK_PRIVATE opt_sep use_name_list
  790. ;
  791. public :
  792. TOK_PUBLIC '\n' { $$ = (listname *) NULL; }
  793. | TOK_PUBLIC opt_sep use_name_list { $$ = $3; }
  794. ;
  795. use_name_list :
  796. TOK_NAME { $$ = Insertname(NULL,$1,0); }
  797. | TOK_ASSIGNTYPE { $$ = Insertname(NULL,$1,0); }
  798. | use_name_list ',' TOK_NAME { $$ = Insertname($1,$3,0); }
  799. | use_name_list ',' TOK_ASSIGNTYPE { $$ = Insertname($1,$3,0); }
  800. ;
  801. common :
  802. before_common var_common_list
  803. {
  804. if ( inside_type_declare ) break;
  805. pos_end = setposcur();
  806. RemoveWordSET_0(fortran_out,pos_curcommon,pos_end-pos_curcommon);
  807. }
  808. | before_common comblock var_common_list
  809. {
  810. if ( inside_type_declare ) break;
  811. sprintf(charusemodule,"%s",$2);
  812. Add_NameOfCommon_1($2,subroutinename);
  813. pos_end = setposcur();
  814. RemoveWordSET_0(fortran_out,pos_curcommon,pos_end-pos_curcommon);
  815. }
  816. | common opt_comma comblock opt_comma var_common_list
  817. {
  818. if ( inside_type_declare ) break;
  819. sprintf(charusemodule,"%s",$3);
  820. Add_NameOfCommon_1($3,subroutinename);
  821. pos_end = setposcur();
  822. RemoveWordSET_0(fortran_out,pos_curcommon,pos_end-pos_curcommon);
  823. }
  824. ;
  825. before_common :
  826. TOK_COMMON { positioninblock = 0; pos_curcommon = setposcur()-6; }
  827. | TOK_GLOBAL TOK_COMMON { positioninblock = 0; pos_curcommon = setposcur()-6-7; }
  828. ;
  829. var_common_list :
  830. var_common { if ( ! inside_type_declare ) Add_Common_var_1(); }
  831. | var_common_list ',' var_common { if ( ! inside_type_declare ) Add_Common_var_1(); }
  832. ;
  833. var_common :
  834. TOK_NAME dims
  835. {
  836. positioninblock = positioninblock + 1 ;
  837. strcpy(commonvar,$1);
  838. commondim = $2;
  839. }
  840. ;
  841. comblock :
  842. TOK_DSLASH
  843. {
  844. strcpy($$,"");
  845. positioninblock=0;
  846. strcpy(commonblockname,"");
  847. }
  848. | TOK_SLASH TOK_NAME TOK_SLASH
  849. {
  850. strcpy($$,$2);
  851. positioninblock=0;
  852. strcpy(commonblockname,$2);
  853. }
  854. ;
  855. opt_comma :
  856. | ','
  857. ;
  858. paramlist :
  859. paramitem { $$=insertvar(NULL,$1); }
  860. | paramlist ',' paramitem { $$=insertvar($1,$3); }
  861. ;
  862. paramitem :
  863. TOK_NAME '=' expr
  864. {
  865. if ( inside_type_declare ) break;
  866. curvar=(variable *) calloc(1,sizeof(variable));
  867. Init_Variable(curvar);
  868. curvar->v_VariableIsParameter = 1;
  869. strcpy(curvar->v_nomvar,$1);
  870. strcpy(curvar->v_subroutinename,subroutinename);
  871. strcpy(curvar->v_modulename,curmodulename);
  872. strcpy(curvar->v_initialvalue,$3);
  873. strcpy(curvar->v_commoninfile,cur_filename);
  874. Save_Length($3,14);
  875. $$ = curvar;
  876. }
  877. ;
  878. module_proc_stmt :
  879. TOK_PROCEDURE proc_name_list
  880. ;
  881. proc_name_list :
  882. TOK_NAME
  883. | proc_name_list ',' TOK_NAME
  884. ;
  885. implicit :
  886. TOK_IMPLICIT TOK_NONE
  887. {
  888. if ( insubroutinedeclare == 1 )
  889. {
  890. Add_ImplicitNoneSubroutine_1();
  891. pos_end = setposcur();
  892. RemoveWordSET_0(fortran_out,pos_end-13,13);
  893. }
  894. }
  895. | TOK_IMPLICIT TOK_REAL8
  896. ;
  897. dcl : options TOK_NAME dims lengspec initial_value
  898. {
  899. if ( ! inside_type_declare )
  900. {
  901. if (dimsgiven == 1) curvar = createvar($2,curdim);
  902. else curvar = createvar($2,$3);
  903. CreateAndFillin_Curvar(DeclType, curvar);
  904. curlistvar = insertvar(NULL, curvar);
  905. if (!strcasecmp(DeclType,"character"))
  906. {
  907. if (c_selectorgiven == 1)
  908. {
  909. strcpy(c_selectordim.first,"1");
  910. strcpy(c_selectordim.last,c_selectorname);
  911. Save_Length(c_selectorname,1);
  912. change_dim_char(insertdim(NULL,c_selectordim),curlistvar);
  913. }
  914. }
  915. $$=settype(DeclType,curlistvar);
  916. }
  917. strcpy(vallengspec,"");
  918. }
  919. | dcl ',' TOK_NAME dims lengspec initial_value
  920. {
  921. if ( ! inside_type_declare )
  922. {
  923. if (dimsgiven == 1) curvar = createvar($3, curdim);
  924. else curvar = createvar($3, $4);
  925. CreateAndFillin_Curvar($1->var->v_typevar,curvar);
  926. strcpy(curvar->v_typevar, $1->var->v_typevar);
  927. curvar->v_catvar = get_cat_var(curvar);
  928. curlistvar = insertvar($1, curvar);
  929. if (!strcasecmp(DeclType,"character"))
  930. {
  931. if (c_selectorgiven == 1)
  932. {
  933. strcpy(c_selectordim.first,"1");
  934. strcpy(c_selectordim.last,c_selectorname);
  935. Save_Length(c_selectorname,1);
  936. change_dim_char(insertdim(NULL,c_selectordim),curlistvar);
  937. }
  938. }
  939. $$=curlistvar;
  940. }
  941. strcpy(vallengspec,"");
  942. }
  943. ;
  944. nodimsgiven : { dimsgiven = 0; }
  945. ;
  946. type : typespec selector { strcpy(DeclType,$1); }
  947. | before_character c_selector { strcpy(DeclType,"character"); }
  948. | typespec '*' TOK_CSTINT { strcpy(DeclType,$1); strcpy(nameinttypename,$3); }
  949. | TOK_TYPEPAR attribute ')' { strcpy(DeclType,"type"); GlobalDeclarationType = 1; }
  950. ;
  951. c_selector :
  952. | '*' TOK_CSTINT { c_selectorgiven = 1; strcpy(c_selectorname,$2); }
  953. | '*' '(' c_attribute ')' { c_star = 1;}
  954. | '(' c_attribute ')'
  955. ;
  956. c_attribute :
  957. TOK_NAME clause opt_clause
  958. | TOK_NAME '=' clause opt_clause
  959. | clause opt_clause
  960. ;
  961. before_character : TOK_CHARACTER { pos_cur_decl = setposcur()-9; }
  962. ;
  963. typespec :
  964. TOK_INTEGER { strcpy($$,"integer"); pos_cur_decl = setposcur()-7; }
  965. | TOK_LOGICAL { strcpy($$,"logical"); pos_cur_decl = setposcur()-7; }
  966. | TOK_REAL { strcpy($$,"real"); pos_cur_decl = setposcur()-4; }
  967. | TOK_COMPLEX { strcpy($$,"complex"); pos_cur_decl = setposcur()-7; }
  968. | TOK_DOUBLECOMPLEX { strcpy($$,"double complex"); pos_cur_decl = setposcur()-14; }
  969. | TOK_DOUBLEPRECISION { pos_cur_decl = setposcur()-16; strcpy($$,"real"); strcpy(nameinttypename,"8"); }
  970. ;
  971. lengspec :
  972. | '*' proper_lengspec {strcpy(vallengspec,$2);}
  973. ;
  974. proper_lengspec :
  975. expr { sprintf($$,"*%s",$1); }
  976. | '(' '*' ')' { strcpy($$,"*(*)"); }
  977. ;
  978. selector :
  979. | '*' proper_selector
  980. | '(' attribute ')'
  981. ;
  982. proper_selector : expr
  983. | '(' '*' ')'
  984. ;
  985. attribute :
  986. TOK_NAME clause
  987. | TOK_NAME '=' clause
  988. {
  989. if ( strstr($3,"0.d0") )
  990. {
  991. strcpy(nameinttypename,"8");
  992. strcpy(NamePrecision,"");
  993. }
  994. else
  995. sprintf(NamePrecision,"%s = %s",$1,$3);
  996. }
  997. | TOK_NAME { strcpy(NamePrecision,$1); }
  998. | TOK_CSTINT { strcpy(NamePrecision,$1); }
  999. | TOK_ASSIGNTYPE { strcpy(NamePrecision,$1); }
  1000. ;
  1001. clause :
  1002. expr { strcpy(CharacterSize,$1); strcpy($$,$1); }
  1003. | '*' { strcpy(CharacterSize,"*"); strcpy($$,"*"); }
  1004. ;
  1005. opt_clause :
  1006. | ',' TOK_NAME clause
  1007. ;
  1008. options :
  1009. | TOK_FOURDOTS
  1010. | ',' attr_spec_list TOK_FOURDOTS
  1011. ;
  1012. attr_spec_list : attr_spec
  1013. | attr_spec_list ',' attr_spec
  1014. ;
  1015. attr_spec :
  1016. TOK_PARAMETER { VariableIsParameter = 1; }
  1017. | access_spec
  1018. | TOK_ALLOCATABLE { Allocatabledeclare = 1; }
  1019. | TOK_DIMENSION dims { dimsgiven = 1; curdim = $2; }
  1020. | TOK_EXTERNAL { ExternalDeclare = 1; }
  1021. | TOK_INTENT '(' intent_spec ')'
  1022. { strcpy(IntentSpec,$3); }
  1023. | TOK_INTRINSIC
  1024. | TOK_OPTIONAL { optionaldeclare = 1 ; }
  1025. | TOK_POINTER { pointerdeclare = 1 ; }
  1026. | TOK_SAVE { SaveDeclare = 1 ; }
  1027. | TOK_TARGET { Targetdeclare = 1; }
  1028. ;
  1029. intent_spec :
  1030. TOK_IN { strcpy($$,$1); }
  1031. | TOK_OUT { strcpy($$,$1); }
  1032. | TOK_INOUT { strcpy($$,$1); }
  1033. ;
  1034. access_spec :
  1035. TOK_PUBLIC { PublicDeclare = 1; }
  1036. | TOK_PRIVATE { PrivateDeclare = 1; }
  1037. ;
  1038. dims : { $$ = (listdim*) NULL; }
  1039. | '(' dimlist ')'
  1040. {
  1041. $$ = (listdim*) NULL;
  1042. if ( inside_type_declare ) break;
  1043. if ( created_dimensionlist == 1 || agrif_parentcall == 1 ) $$=$2;
  1044. }
  1045. ;
  1046. dimlist :
  1047. dim
  1048. {
  1049. $$ = (listdim*) NULL;
  1050. if ( inside_type_declare ) break;
  1051. if ( created_dimensionlist == 1 || agrif_parentcall == 1 ) $$=insertdim(NULL,$1);
  1052. }
  1053. | dimlist ',' dim
  1054. {
  1055. $$ = (listdim*) NULL;
  1056. if ( inside_type_declare ) break;
  1057. if ( (!inside_type_declare) && created_dimensionlist == 1 ) $$=insertdim($1,$3);
  1058. }
  1059. ;
  1060. dim : ubound { strcpy($$.first,"1"); strcpy($$.last,$1); Save_Length($1,1); }
  1061. | ':' { strcpy($$.first,""); strcpy($$.last,""); }
  1062. | expr ':' { strcpy($$.first,$1); Save_Length($1,2); strcpy($$.last,""); }
  1063. | ':' expr { strcpy($$.first,""); strcpy($$.last,$2); Save_Length($2,1); }
  1064. | expr ':' ubound { strcpy($$.first,$1); Save_Length($1,2); strcpy($$.last,$3); Save_Length($3,1); }
  1065. ;
  1066. ubound :
  1067. '*' { strcpy($$,"*"); }
  1068. | expr { strcpy($$,$1); }
  1069. ;
  1070. expr : uexpr { strcpy($$,$1); }
  1071. | complex_const { strcpy($$,$1); }
  1072. | predefinedfunction { strcpy($$,$1); }
  1073. | '(' expr ')' { sprintf($$,"(%s)",$2); }
  1074. ;
  1075. predefinedfunction :
  1076. TOK_SUM minmaxlist ')' { sprintf($$,"SUM(%s)",$2);}
  1077. | TOK_MAX minmaxlist ')' { sprintf($$,"MAX(%s)",$2);}
  1078. | TOK_TANH '(' minmaxlist ')' { sprintf($$,"TANH(%s)",$3);}
  1079. | TOK_MAXVAL '(' minmaxlist ')' { sprintf($$,"MAXVAL(%s)",$3);}
  1080. | TOK_MIN minmaxlist ')' { sprintf($$,"MIN(%s)",$2);}
  1081. | TOK_MINVAL '(' minmaxlist ')' { sprintf($$,"MINVAL(%s)",$3);}
  1082. | TOK_TRIM '(' expr ')' { sprintf($$,"TRIM(%s)",$3);}
  1083. | TOK_SQRT expr ')' { sprintf($$,"SQRT(%s)",$2);}
  1084. | TOK_REAL '(' minmaxlist ')' { sprintf($$,"REAL(%s)",$3);}
  1085. | TOK_NINT '(' expr ')' { sprintf($$,"NINT(%s)",$3);}
  1086. | TOK_FLOAT '(' expr ')' { sprintf($$,"FLOAT(%s)",$3);}
  1087. | TOK_EXP '(' expr ')' { sprintf($$,"EXP(%s)",$3);}
  1088. | TOK_COS '(' expr ')' { sprintf($$,"COS(%s)",$3);}
  1089. | TOK_COSH '(' expr ')' { sprintf($$,"COSH(%s)",$3);}
  1090. | TOK_ACOS '(' expr ')' { sprintf($$,"ACOS(%s)",$3);}
  1091. | TOK_SIN '(' expr ')' { sprintf($$,"SIN(%s)",$3);}
  1092. | TOK_SINH '(' expr ')' { sprintf($$,"SINH(%s)",$3);}
  1093. | TOK_ASIN '(' expr ')' { sprintf($$,"ASIN(%s)",$3);}
  1094. | TOK_LOG '(' expr ')' { sprintf($$,"LOG(%s)",$3);}
  1095. | TOK_TAN '(' expr ')' { sprintf($$,"TAN(%s)",$3);}
  1096. | TOK_ATAN '(' expr ')' { sprintf($$,"ATAN(%s)",$3);}
  1097. | TOK_ABS expr ')' { sprintf($$,"ABS(%s)",$2);}
  1098. | TOK_MOD '(' minmaxlist ')' { sprintf($$,"MOD(%s)",$3);}
  1099. | TOK_SIGN minmaxlist ')' { sprintf($$,"SIGN(%s)",$2);}
  1100. | TOK_MINLOC '(' minmaxlist ')' { sprintf($$,"MINLOC(%s)",$3);}
  1101. | TOK_MAXLOC '(' minmaxlist ')' { sprintf($$,"MAXLOC(%s)",$3);}
  1102. ;
  1103. minmaxlist : expr {strcpy($$,$1);}
  1104. | minmaxlist ',' expr { sprintf($$,"%s,%s",$1,$3); }
  1105. ;
  1106. uexpr : lhs { strcpy($$,$1); }
  1107. | simple_const { strcpy($$,$1); }
  1108. | vec { strcpy($$,$1); }
  1109. | expr operation { sprintf($$,"%s%s",$1,$2); }
  1110. | signe expr %prec '*' { sprintf($$,"%s%s",$1,$2); }
  1111. | TOK_NOT expr { sprintf($$,"%s%s",$1,$2); }
  1112. ;
  1113. signe : '+' { strcpy($$,"+"); }
  1114. | '-' { strcpy($$,"-"); }
  1115. ;
  1116. operation :
  1117. '+' expr %prec '+' { sprintf($$,"+%s",$2); }
  1118. | '-' expr %prec '+' { sprintf($$,"-%s",$2); }
  1119. | '*' expr { sprintf($$,"*%s",$2); }
  1120. | TOK_DASTER expr { sprintf($$,"%s%s",$1,$2); }
  1121. | TOK_EQ expr %prec TOK_EQ { sprintf($$,"%s%s",$1,$2); }
  1122. | TOK_EQV expr %prec TOK_EQV { sprintf($$,"%s%s",$1,$2); }
  1123. | TOK_GT expr %prec TOK_EQ { sprintf($$,"%s%s",$1,$2); }
  1124. | '>' expr %prec TOK_EQ { sprintf($$," > %s",$2); }
  1125. | '<' expr %prec TOK_EQ { sprintf($$," < %s",$2); }
  1126. | '>''=' expr %prec TOK_EQ { sprintf($$," >= %s",$3); }
  1127. | '<''=' expr %prec TOK_EQ { sprintf($$," <= %s",$3); }
  1128. | TOK_LT expr %prec TOK_EQ { sprintf($$,"%s%s",$1,$2); }
  1129. | TOK_GE expr %prec TOK_EQ { sprintf($$,"%s%s",$1,$2); }
  1130. | TOK_LE expr %prec TOK_EQ { sprintf($$,"%s%s",$1,$2); }
  1131. | TOK_NE expr %prec TOK_EQ { sprintf($$,"%s%s",$1,$2); }
  1132. | TOK_NEQV expr %prec TOK_EQV { sprintf($$,"%s%s",$1,$2); }
  1133. | TOK_XOR expr { sprintf($$,"%s%s",$1,$2); }
  1134. | TOK_OR expr { sprintf($$,"%s%s",$1,$2); }
  1135. | TOK_AND expr { sprintf($$,"%s%s",$1,$2); }
  1136. | TOK_SLASH after_slash { sprintf($$,"%s",$2); }
  1137. | '=' after_equal { sprintf($$,"%s",$2); }
  1138. after_slash : { strcpy($$,""); }
  1139. | expr { sprintf($$,"/%s",$1); }
  1140. | '=' expr %prec TOK_EQ { sprintf($$,"/= %s",$2);}
  1141. | TOK_SLASH expr { sprintf($$,"//%s",$2); }
  1142. ;
  1143. after_equal :
  1144. '=' expr %prec TOK_EQ { sprintf($$,"==%s",$2); }
  1145. | expr { sprintf($$,"= %s",$1); }
  1146. ;
  1147. lhs : ident { strcpy($$,$1); }
  1148. | structure_component { strcpy($$,$1); }
  1149. | array_ele_substring_func_ref { strcpy($$,$1); }
  1150. ;
  1151. beforefunctionuse :
  1152. {
  1153. agrif_parentcall = 0;
  1154. if ( !strcasecmp(identcopy, "Agrif_Parent") ) agrif_parentcall = 1;
  1155. if ( Agrif_in_Tok_NAME(identcopy) )
  1156. {
  1157. inagrifcallargument = 1;
  1158. Add_SubroutineWhereAgrifUsed_1(subroutinename, curmodulename);
  1159. }
  1160. }
  1161. ;
  1162. array_ele_substring_func_ref :
  1163. begin_array { strcpy($$,$1); if ( incalldeclare == 0 ) inagrifcallargument = 0; }
  1164. | begin_array substring { sprintf($$," %s %s ",$1,$2); }
  1165. | structure_component '(' funarglist ')' { sprintf($$," %s ( %s )",$1,$3); }
  1166. | structure_component '(' funarglist ')' substring { sprintf($$," %s ( %s ) %s ",$1,$3,$5); }
  1167. ;
  1168. begin_array :
  1169. ident '(' funarglist ')'
  1170. {
  1171. if ( inside_type_declare ) break;
  1172. sprintf($$," %s ( %s )",$1,$3);
  1173. ModifyTheAgrifFunction_0($3);
  1174. agrif_parentcall = 0;
  1175. }
  1176. ;
  1177. structure_component :
  1178. lhs '%' declare_after_percent lhs
  1179. {
  1180. sprintf($$," %s %% %s ",$1,$4);
  1181. if ( incalldeclare == 0 ) inagrifcallargument = 0;
  1182. }
  1183. ;
  1184. vec :
  1185. TOK_LEFTAB outlist TOK_RIGHTAB { sprintf($$,"(/%s/)",$2); }
  1186. ;
  1187. funarglist :
  1188. beforefunctionuse { strcpy($$," "); }
  1189. | beforefunctionuse funargs { strcpy($$,$2); }
  1190. ;
  1191. funargs :
  1192. funarg { strcpy($$,$1); }
  1193. | funargs ',' funarg { sprintf($$,"%s,%s",$1,$3); }
  1194. ;
  1195. funarg :
  1196. expr {strcpy($$,$1);}
  1197. | triplet {strcpy($$,$1);}
  1198. ;
  1199. triplet :
  1200. expr ':' expr { sprintf($$,"%s :%s",$1,$3);}
  1201. | expr ':' expr ':' expr { sprintf($$,"%s :%s :%s",$1,$3,$5);}
  1202. | ':' expr ':' expr { sprintf($$,":%s :%s",$2,$4);}
  1203. | ':' ':' expr { sprintf($$,": : %s",$3);}
  1204. | ':' expr { sprintf($$,":%s",$2);}
  1205. | expr ':' { sprintf($$,"%s :",$1);}
  1206. | ':' { sprintf($$,":");}
  1207. ;
  1208. ident : TOK_NAME
  1209. {
  1210. if ( afterpercent == 0 )
  1211. {
  1212. if ( Agrif_in_Tok_NAME($1) ) Add_SubroutineWhereAgrifUsed_1(subroutinename, curmodulename);
  1213. if ( !strcasecmp($1,"Agrif_Parent") ) agrif_parentcall = 1;
  1214. if ( VariableIsFunction($1) )
  1215. {
  1216. if ( inagrifcallargument == 1 )
  1217. {
  1218. if ( !strcasecmp($1,identcopy) )
  1219. {
  1220. strcpy(sameagrifname,identcopy);
  1221. sameagrifargument = 1;
  1222. }
  1223. }
  1224. strcpy(identcopy,$1);
  1225. pointedvar = 0;
  1226. if (variscoupled_0($1)) strcpy(truename, getcoupledname_0($1));
  1227. else strcpy(truename, $1);
  1228. if ( VarIsNonGridDepend(truename) == 0 && (! Variableshouldberemoved(truename)) )
  1229. {
  1230. if ( inagrifcallargument == 1 || varispointer_0(truename) == 1 )
  1231. {
  1232. if ( (IsinListe(List_UsedInSubroutine_Var,$1) == 1) || (inagrifcallargument == 1) )
  1233. {
  1234. if (varistyped_0(truename) == 0) ModifyTheVariableName_0(truename,strlen($1));
  1235. }
  1236. }
  1237. if ( inagrifcallargument != 1 || sameagrifargument ==1 )
  1238. {
  1239. Add_UsedInSubroutine_Var_1(truename);
  1240. }
  1241. }
  1242. NotifyAgrifFunction_0(truename);
  1243. }
  1244. }
  1245. else
  1246. {
  1247. afterpercent = 0;
  1248. }
  1249. }
  1250. ;
  1251. simple_const :
  1252. TOK_TRUE { strcpy($$,".TRUE.");}
  1253. | TOK_FALSE { strcpy($$,".FALSE.");}
  1254. | TOK_NULL_PTR { strcpy($$,"NULL()"); }
  1255. | TOK_CSTINT { strcpy($$,$1); }
  1256. | TOK_CSTREAL { strcpy($$,$1); }
  1257. | TOK_HEXA { strcpy($$,$1); }
  1258. | simple_const TOK_NAME
  1259. { sprintf($$,"%s%s",$1,$2); }
  1260. | string_constant opt_substring
  1261. ;
  1262. string_constant :
  1263. TOK_CHAR_CONSTANT { strcpy($$,$1);}
  1264. | string_constant TOK_CHAR_CONSTANT
  1265. | TOK_CHAR_MESSAGE { strcpy($$,$1);}
  1266. | TOK_CHAR_CUT { strcpy($$,$1);}
  1267. ;
  1268. opt_substring : { strcpy($$," ");}
  1269. | substring { strcpy($$,$1);}
  1270. ;
  1271. substring :
  1272. '(' optexpr ':' optexpr ')' { sprintf($$,"(%s :%s)",$2,$4);}
  1273. ;
  1274. optexpr : { strcpy($$," ");}
  1275. | expr { strcpy($$,$1);}
  1276. ;
  1277. opt_expr :
  1278. '\n' { strcpy($$," ");}
  1279. | expr { strcpy($$,$1);}
  1280. ;
  1281. initial_value : { InitialValueGiven = 0; }
  1282. | '=' expr
  1283. {
  1284. if ( inside_type_declare ) break;
  1285. strcpy(InitValue,$2);
  1286. InitialValueGiven = 1;
  1287. }
  1288. | TOK_POINT_TO expr
  1289. {
  1290. if ( inside_type_declare ) break;
  1291. strcpy(InitValue,$2);
  1292. InitialValueGiven = 2;
  1293. }
  1294. ;
  1295. complex_const :
  1296. '(' uexpr ',' uexpr ')' {sprintf($$,"(%s,%s)",$2,$4); }
  1297. ;
  1298. use_stat :
  1299. word_use TOK_NAME
  1300. {
  1301. /* if variables has been declared in a subroutine */
  1302. sprintf(charusemodule, "%s", $2);
  1303. if ( firstpass )
  1304. {
  1305. Add_NameOfModuleUsed_1($2);
  1306. }
  1307. else
  1308. {
  1309. if ( insubroutinedeclare )
  1310. copyuse_0($2);
  1311. if ( inmoduledeclare == 0 )
  1312. {
  1313. pos_end = setposcur();
  1314. RemoveWordSET_0(fortran_out,pos_curuse,pos_end-pos_curuse);
  1315. }
  1316. }
  1317. }
  1318. | word_use TOK_NAME ',' rename_list
  1319. {
  1320. if ( firstpass )
  1321. {
  1322. if ( insubroutinedeclare )
  1323. {
  1324. Add_CouplePointed_Var_1($2,$4);
  1325. coupletmp = $4;
  1326. strcpy(ligne,"");
  1327. while ( coupletmp )
  1328. {
  1329. strcat(ligne, coupletmp->c_namevar);
  1330. strcat(ligne, " => ");
  1331. strcat(ligne, coupletmp->c_namepointedvar);
  1332. coupletmp = coupletmp->suiv;
  1333. if ( coupletmp ) strcat(ligne,",");
  1334. }
  1335. sprintf(charusemodule,"%s",$2);
  1336. }
  1337. Add_NameOfModuleUsed_1($2);
  1338. }
  1339. if ( inmoduledeclare == 0 )
  1340. {
  1341. pos_end = setposcur();
  1342. RemoveWordSET_0(fortran_out,pos_curuse,pos_end-pos_curuse);
  1343. }
  1344. }
  1345. | word_use TOK_NAME ',' TOK_ONLY ':' '\n'
  1346. {
  1347. /* if variables has been declared in a subroutine */
  1348. sprintf(charusemodule,"%s",$2);
  1349. if ( firstpass )
  1350. {
  1351. Add_NameOfModuleUsed_1($2);
  1352. }
  1353. else
  1354. {
  1355. if ( insubroutinedeclare )
  1356. copyuseonly_0($2);
  1357. if ( inmoduledeclare == 0 )
  1358. {
  1359. pos_end = setposcur();
  1360. RemoveWordSET_0(fortran_out,pos_curuse,pos_end-pos_curuse);
  1361. }
  1362. }
  1363. }
  1364. | word_use TOK_NAME ',' TOK_ONLY ':' only_list
  1365. {
  1366. /* if variables has been declared in a subroutine */
  1367. if ( firstpass )
  1368. {
  1369. if ( insubroutinedeclare )
  1370. {
  1371. Add_CouplePointed_Var_1($2,$6);
  1372. coupletmp = $6;
  1373. strcpy(ligne,"");
  1374. while ( coupletmp )
  1375. {
  1376. strcat(ligne,coupletmp->c_namevar);
  1377. if ( strcasecmp(coupletmp->c_namepointedvar,"") ) strcat(ligne," => ");
  1378. strcat(ligne,coupletmp->c_namepointedvar);
  1379. coupletmp = coupletmp->suiv;
  1380. if ( coupletmp ) strcat(ligne,",");
  1381. }
  1382. sprintf(charusemodule,"%s",$2);
  1383. }
  1384. Add_NameOfModuleUsed_1($2);
  1385. }
  1386. else /* if ( firstpass == 0 ) */
  1387. {
  1388. if ( inmoduledeclare == 0 )
  1389. {
  1390. pos_end = setposcur();
  1391. RemoveWordSET_0(fortran_out,pos_curuse,pos_end-pos_curuse);
  1392. if (oldfortran_out) variableisglobalinmodule($6,$2,oldfortran_out,pos_curuseold);
  1393. }
  1394. else
  1395. {
  1396. /* if we are in the module declare and if the */
  1397. /* onlylist is a list of global variable */
  1398. variableisglobalinmodule($6, $2, fortran_out,pos_curuse);
  1399. }
  1400. }
  1401. }
  1402. ;
  1403. word_use :
  1404. TOK_USE
  1405. {
  1406. pos_curuse = setposcur()-strlen($1);
  1407. if (firstpass == 0 && oldfortran_out) pos_curuseold = setposcurname(oldfortran_out);
  1408. }
  1409. ;
  1410. rename_list :
  1411. rename_name
  1412. {
  1413. $$ = $1;
  1414. }
  1415. | rename_list ',' rename_name
  1416. {
  1417. /* insert the variable in the list $1 */
  1418. $3->suiv = $1;
  1419. $$ = $3;
  1420. }
  1421. ;
  1422. rename_name : TOK_NAME TOK_POINT_TO TOK_NAME
  1423. {
  1424. coupletmp = (listcouple *) calloc(1,sizeof(listcouple));
  1425. strcpy(coupletmp->c_namevar,$1);
  1426. strcpy(coupletmp->c_namepointedvar,$3);
  1427. coupletmp->suiv = NULL;
  1428. $$ = coupletmp;
  1429. }
  1430. ;
  1431. only_list :
  1432. only_name { $$ = $1; }
  1433. | only_list ',' only_name
  1434. {
  1435. /* insert the variable in the list $1 */
  1436. $3->suiv = $1;
  1437. $$ = $3;
  1438. }
  1439. ;
  1440. only_name :
  1441. TOK_NAME TOK_POINT_TO TOK_NAME
  1442. {
  1443. coupletmp = (listcouple *)calloc(1,sizeof(listcouple));
  1444. strcpy(coupletmp->c_namevar,$1);
  1445. strcpy(coupletmp->c_namepointedvar,$3);
  1446. coupletmp->suiv = NULL;
  1447. $$ = coupletmp;
  1448. pointedvar = 1;
  1449. Add_UsedInSubroutine_Var_1($1);
  1450. }
  1451. | TOK_NAME
  1452. {
  1453. coupletmp = (listcouple *)calloc(1,sizeof(listcouple));
  1454. strcpy(coupletmp->c_namevar,$1);
  1455. strcpy(coupletmp->c_namepointedvar,"");
  1456. coupletmp->suiv = NULL;
  1457. $$ = coupletmp;
  1458. }
  1459. ;
  1460. /* R209 : execution-part-construct */
  1461. execution-part-construct:
  1462. executable-construct
  1463. | format-stmt
  1464. ;
  1465. /* R213 : executable-construct */
  1466. executable-construct:
  1467. action-stmt
  1468. | do-construct
  1469. | case-construct
  1470. | if-construct
  1471. | where-construct
  1472. ;
  1473. /* R214 : action-stmt */
  1474. action-stmt :
  1475. TOK_CONTINUE
  1476. | ident_dims after_ident_dims
  1477. | goto
  1478. | call
  1479. | iofctl ioctl
  1480. | read option_read
  1481. | TOK_WRITE ioctl
  1482. | TOK_WRITE ioctl outlist
  1483. | TOK_REWIND after_rewind
  1484. | TOK_ALLOCATE '(' allocation_list opt_stat_spec ')' { inallocate = 0; }
  1485. | TOK_DEALLOCATE '(' allocate_object_list opt_stat_spec ')' { inallocate = 0; }
  1486. | TOK_EXIT optexpr
  1487. | TOK_RETURN opt_expr
  1488. | TOK_CYCLE opt_expr
  1489. | stop opt_expr
  1490. | int_list
  1491. | TOK_NULLIFY '(' pointer_name_list ')'
  1492. | word_endunit
  1493. {
  1494. GlobalDeclaration = 0 ;
  1495. if ( firstpass == 0 && strcasecmp(subroutinename,"") )
  1496. {
  1497. if ( module_declar && insubroutinedeclare == 0 ) fclose(module_declar);
  1498. }
  1499. if ( strcasecmp(subroutinename,"") )
  1500. {
  1501. if ( inmodulemeet == 1 )
  1502. {
  1503. /* we are in a module */
  1504. if ( insubroutinedeclare == 1 )
  1505. {
  1506. /* it is like an end subroutine <name> */
  1507. insubroutinedeclare = 0 ;
  1508. pos_cur = setposcur();
  1509. closeandcallsubloopandincludeit_0(1);
  1510. functiondeclarationisdone = 0;
  1511. }
  1512. else
  1513. {
  1514. /* it is like an end module <name> */
  1515. inmoduledeclare = 0 ;
  1516. inmodulemeet = 0 ;
  1517. }
  1518. }
  1519. else
  1520. {
  1521. insubroutinedeclare = 0;
  1522. pos_cur = setposcur();
  1523. closeandcallsubloopandincludeit_0(2);
  1524. functiondeclarationisdone = 0;
  1525. }
  1526. }
  1527. strcpy(subroutinename,"");
  1528. }
  1529. | word_endprogram opt_name
  1530. {
  1531. insubroutinedeclare = 0;
  1532. inprogramdeclare = 0;
  1533. pos_cur = setposcur();
  1534. closeandcallsubloopandincludeit_0(3);
  1535. functiondeclarationisdone = 0;
  1536. strcpy(subroutinename,"");
  1537. }
  1538. | word_endsubroutine opt_name
  1539. {
  1540. if ( strcasecmp(subroutinename,"") )
  1541. {
  1542. insubroutinedeclare = 0;
  1543. pos_cur = setposcur();
  1544. closeandcallsubloopandincludeit_0(1);
  1545. functiondeclarationisdone = 0;
  1546. strcpy(subroutinename,"");
  1547. }
  1548. }
  1549. | word_endfunction opt_name
  1550. {
  1551. insubroutinedeclare = 0;
  1552. pos_cur = setposcur();
  1553. closeandcallsubloopandincludeit_0(0);
  1554. functiondeclarationisdone = 0;
  1555. strcpy(subroutinename,"");
  1556. }
  1557. | TOK_ENDMODULE opt_name
  1558. {
  1559. /* if we never meet the contains keyword */
  1560. if ( firstpass == 0 )
  1561. {
  1562. RemoveWordCUR_0(fortran_out, strlen($2)+11); // Remove word "end module"
  1563. if ( inmoduledeclare && ! aftercontainsdeclare )
  1564. {
  1565. Write_Closing_Module(1);
  1566. }
  1567. fprintf(fortran_out,"\n end module %s\n", curmodulename);
  1568. if ( module_declar && insubroutinedeclare == 0 )
  1569. {
  1570. fclose(module_declar);
  1571. }
  1572. }
  1573. inmoduledeclare = 0 ;
  1574. inmodulemeet = 0 ;
  1575. aftercontainsdeclare = 1;
  1576. strcpy(curmodulename, "");
  1577. GlobalDeclaration = 0 ;
  1578. }
  1579. | if-stmt
  1580. | where-stmt
  1581. | TOK_CONTAINS
  1582. {
  1583. if ( inside_type_declare ) break;
  1584. if ( inmoduledeclare )
  1585. {
  1586. if ( firstpass == 0 )
  1587. {
  1588. RemoveWordCUR_0(fortran_out,9); // Remove word 'contains'
  1589. Write_Closing_Module(0);
  1590. }
  1591. inmoduledeclare = 0 ;
  1592. aftercontainsdeclare = 1;
  1593. }
  1594. else if ( insubroutinedeclare )
  1595. {
  1596. incontainssubroutine = 1;
  1597. insubroutinedeclare = 0;
  1598. incontainssubroutine = 0;
  1599. functiondeclarationisdone = 0;
  1600. if ( firstpass )
  1601. List_ContainsSubroutine = Addtolistnom(subroutinename, List_ContainsSubroutine, 0);
  1602. else
  1603. closeandcallsubloop_contains_0();
  1604. strcpy(subroutinename, "");
  1605. }
  1606. else printf("l.%4d -- TOK_CONTAINS -- MHCHECK\n",line_num_input);
  1607. }
  1608. ;
  1609. /* R601 : variable */
  1610. //variable : expr
  1611. // ;
  1612. /* R734 : assignment-stmt */
  1613. // assignment-stmt: variable '=' expr
  1614. // ;
  1615. assignment-stmt: expr
  1616. ;
  1617. /* R741 : where-stmt */
  1618. where-stmt: TOK_WHERE '(' mask-expr ')' where-assignment-stmt
  1619. ;
  1620. /* R742 : where-construct */
  1621. where-construct: where-construct-stmt line-break opt-where-body-construct opt-masked-elsewhere-construct opt-elsewhere-construct end-where-stmt
  1622. ;
  1623. opt-where-body-construct:
  1624. | opt-where-body-construct where-body-construct line-break
  1625. ;
  1626. opt-masked-elsewhere-construct :
  1627. | opt-masked-elsewhere-construct masked-elsewhere-stmt line-break opt-where-body-construct
  1628. ;
  1629. opt-elsewhere-construct:
  1630. | opt-elsewhere-construct elsewhere-stmt line-break opt-where-body-construct
  1631. ;
  1632. /* R743 : where-construct-stmt */
  1633. where-construct-stmt:
  1634. TOK_WHERE '(' mask-expr ')'
  1635. ;
  1636. /* R744 : where-body-construct */
  1637. where-body-construct: where-assignment-stmt
  1638. | where-stmt
  1639. | where-construct
  1640. ;
  1641. /* R745 : where-assignment-stmt */
  1642. where-assignment-stmt: assignment-stmt
  1643. ;
  1644. /* R746 : mask-expr */
  1645. mask-expr: expr
  1646. ;
  1647. /* R747 : masked-elsewhere-stmt */
  1648. masked-elsewhere-stmt:
  1649. TOK_ELSEWHEREPAR mask-expr ')'
  1650. | TOK_ELSEWHEREPAR mask-expr ')' TOK_NAME
  1651. ;
  1652. /* R748: elsewhere-stmt */
  1653. elsewhere-stmt:
  1654. TOK_ELSEWHERE
  1655. | TOK_ELSEWHERE TOK_NAME
  1656. ;
  1657. /* R749: end-where-stmt */
  1658. end-where-stmt:
  1659. TOK_ENDWHERE
  1660. | TOK_ENDWHERE TOK_NAME
  1661. ;
  1662. /* R752 : forall-header */
  1663. forall-header :
  1664. ;
  1665. /* R801 : block */
  1666. block:
  1667. |block execution-part-construct
  1668. |block execution-part-construct line-break
  1669. ;
  1670. /* R813 : do-construct */
  1671. do-construct:
  1672. block-do-construct
  1673. ;
  1674. /* R814 : block-do-construct */
  1675. block-do-construct:
  1676. do-stmt line-break do-block end-do
  1677. ;
  1678. /* R815 : do-stmt */
  1679. do-stmt:
  1680. label-do-stmt
  1681. | nonlabel-do-stmt
  1682. ;
  1683. /* R816 : label-do-stmt */
  1684. label-do-stmt:
  1685. TOK_NAME ':' TOK_PLAINDO label
  1686. | TOK_PLAINDO label
  1687. | TOK_NAME ':' TOK_PLAINDO label loop-control
  1688. | TOK_PLAINDO label loop-control
  1689. ;
  1690. /* R817 : nonlabel-do-stmt */
  1691. nonlabel-do-stmt:
  1692. TOK_NAME ':' TOK_PLAINDO
  1693. | TOK_PLAINDO
  1694. | TOK_NAME ':' TOK_PLAINDO loop-control
  1695. | TOK_PLAINDO loop-control
  1696. ;
  1697. /* R818 : loop-control */
  1698. loop-control:
  1699. opt_comma do-variable '=' expr ',' expr
  1700. | opt_comma do-variable '=' expr ',' expr ',' expr
  1701. | opt_comma TOK_WHILE '(' expr ')'
  1702. | opt_comma TOK_CONCURRENT forall-header
  1703. ;
  1704. /* R819 : do-variable */
  1705. do-variable : ident
  1706. ;
  1707. /* R820 : do-block */
  1708. do-block: block
  1709. ;
  1710. /* R821 : end-do */
  1711. end-do: end-do-stmt
  1712. | continue-stmt
  1713. ;
  1714. /* R822 : end-do-stmt */
  1715. end-do-stmt:
  1716. TOK_ENDDO
  1717. | TOK_ENDDO TOK_NAME
  1718. ;
  1719. /* R832 : if-construct */
  1720. if-construct: if-then-stmt line-break block opt-else-if-stmt-block opt-else-stmt-block end-if-stmt
  1721. ;
  1722. opt-else-if-stmt-block:
  1723. | else-if-stmt-block
  1724. | opt-else-if-stmt-block else-if-stmt-block
  1725. ;
  1726. else-if-stmt-block:
  1727. else-if-stmt line-break block
  1728. ;
  1729. opt-else-stmt-block:
  1730. | else-stmt-block
  1731. | opt-else-stmt-block else-if-stmt-block
  1732. ;
  1733. else-stmt-block: else-stmt line-break block
  1734. ;
  1735. /* R833 : if-then-stmt */
  1736. if-then-stmt:
  1737. TOK_NAME ':' TOK_LOGICALIF '(' expr ')' TOK_THEN
  1738. | TOK_LOGICALIF '(' expr ')' TOK_THEN
  1739. ;
  1740. /* R834 : else-if-stmt */
  1741. else-if-stmt:
  1742. TOK_ELSEIF '(' expr ')' TOK_THEN
  1743. | TOK_ELSEIF '(' expr ')' TOK_THEN TOK_NAME
  1744. ;
  1745. /* R835 : else-stmt */
  1746. else-stmt:
  1747. TOK_ELSE
  1748. | TOK_ELSE TOK_NAME
  1749. ;
  1750. /* R836 : end-if-stmt */
  1751. end-if-stmt:
  1752. TOK_ENDIF
  1753. | TOK_ENDIF TOK_NAME
  1754. ;
  1755. /* R837 : if-stmt */
  1756. if-stmt: TOK_LOGICALIF '(' expr ')' action-stmt
  1757. ;
  1758. /* R838 : case-construct */
  1759. case-construct: select-case-stmt line-break opt_case-stmt-block end-select-stmt
  1760. ;
  1761. opt_case-stmt-block:
  1762. | case-stmt-block
  1763. | opt_case-stmt-block case-stmt-block
  1764. ;
  1765. case-stmt-block: case-stmt line-break block
  1766. ;
  1767. /* R839 : select-case-stmt */
  1768. select-case-stmt :
  1769. TOK_NAME ':' TOK_SELECTCASE '(' expr ')'
  1770. | TOK_SELECTCASE '(' expr ')'
  1771. ;
  1772. /* R840 : case-stmt */
  1773. case-stmt:
  1774. TOK_CASE case-selector
  1775. | TOK_CASE case-selector TOK_NAME
  1776. ;
  1777. /* R840 : end-select-stmt */
  1778. end-select-stmt:
  1779. TOK_ENDSELECT
  1780. | TOK_ENDSELECT TOK_NAME
  1781. ;
  1782. /* R843 : case-selector */
  1783. case-selector:
  1784. '(' case-value-range-list ')'
  1785. | TOK_DEFAULT
  1786. ;
  1787. case-value-range-list:
  1788. case-value-range
  1789. | case-value-range-list ',' case-value-range
  1790. ;
  1791. /* R844: case-value-range */
  1792. case-value-range :
  1793. case-value
  1794. | case-value ':'
  1795. | ':' case-value
  1796. | case-value ':' case-value
  1797. ;
  1798. /* R845 : case-value */
  1799. case-value: expr
  1800. ;
  1801. /* R854 : continue-stmt */
  1802. continue-stmt: TOK_CONTINUE
  1803. ;
  1804. /* R1001 : format-stmt */
  1805. format-stmt: TOK_FORMAT
  1806. ;
  1807. word_endsubroutine :
  1808. TOK_ENDSUBROUTINE
  1809. {
  1810. strcpy($$,$1);
  1811. pos_endsubroutine = setposcur()-strlen($1);
  1812. functiondeclarationisdone = 0;
  1813. }
  1814. ;
  1815. word_endunit :
  1816. TOK_ENDUNIT
  1817. {
  1818. strcpy($$,$1);
  1819. pos_endsubroutine = setposcur()-strlen($1);
  1820. }
  1821. ;
  1822. word_endprogram :
  1823. TOK_ENDPROGRAM
  1824. {
  1825. strcpy($$,$1);
  1826. pos_endsubroutine = setposcur()-strlen($1);
  1827. }
  1828. ;
  1829. word_endfunction :
  1830. TOK_ENDFUNCTION
  1831. {
  1832. strcpy($$,$1);
  1833. pos_endsubroutine = setposcur()-strlen($1);
  1834. }
  1835. ;
  1836. opt_name : '\n' {strcpy($$,"");}
  1837. | TOK_NAME {strcpy($$,$1);}
  1838. ;
  1839. before_dims : { created_dimensionlist = 0; }
  1840. ;
  1841. ident_dims :
  1842. ident before_dims dims dims
  1843. {
  1844. created_dimensionlist = 1;
  1845. if ( ($3 == NULL) || ($4 == NULL) ) break;
  1846. if ( agrif_parentcall == 1 )
  1847. {
  1848. ModifyTheAgrifFunction_0($3->dim.last);
  1849. agrif_parentcall = 0;
  1850. fprintf(fortran_out," = ");
  1851. }
  1852. }
  1853. | ident_dims '%' declare_after_percent ident before_dims dims dims
  1854. {
  1855. created_dimensionlist = 1;
  1856. }
  1857. ;
  1858. int_list :
  1859. TOK_CSTINT
  1860. | int_list ',' TOK_CSTINT
  1861. ;
  1862. after_ident_dims :
  1863. '=' expr
  1864. | TOK_POINT_TO expr
  1865. ;
  1866. call : keywordcall opt_call
  1867. {
  1868. inagrifcallargument = 0 ;
  1869. incalldeclare=0;
  1870. if ( oldfortran_out && (callagrifinitgrids == 1) && (firstpass == 0) )
  1871. {
  1872. pos_end = setposcur();
  1873. RemoveWordSET_0(fortran_out,pos_curcall,pos_end-pos_curcall);
  1874. strcpy(subofagrifinitgrids,subroutinename);
  1875. }
  1876. Instanciation_0(sameagrifname);
  1877. }
  1878. ;
  1879. opt_call :
  1880. | '(' opt_callarglist ')'
  1881. ;
  1882. opt_callarglist :
  1883. | callarglist
  1884. ;
  1885. keywordcall :
  1886. before_call TOK_FLUSH
  1887. | before_call TOK_NAME
  1888. {
  1889. if (!strcasecmp($2,"MPI_Init") ) callmpiinit = 1;
  1890. else callmpiinit = 0;
  1891. if (!strcasecmp($2,"Agrif_Init_Grids") )
  1892. {
  1893. callagrifinitgrids = 1;
  1894. strcpy(meetagrifinitgrids,subroutinename);
  1895. }
  1896. else
  1897. {
  1898. callagrifinitgrids = 0;
  1899. }
  1900. if ( Vartonumber($2) == 1 )
  1901. {
  1902. incalldeclare = 1;
  1903. inagrifcallargument = 1 ;
  1904. Add_SubroutineWhereAgrifUsed_1(subroutinename, curmodulename);
  1905. }
  1906. }
  1907. ;
  1908. before_call : TOK_CALL { pos_curcall=setposcur()-4; }
  1909. ;
  1910. callarglist :
  1911. callarg
  1912. | callarglist ',' callarg
  1913. ;
  1914. callarg :
  1915. expr
  1916. {
  1917. if ( callmpiinit == 1 )
  1918. {
  1919. strcpy(mpiinitvar,$1);
  1920. if ( firstpass == 1 ) Add_UsedInSubroutine_Var_1 (mpiinitvar);
  1921. }
  1922. }
  1923. | '*' TOK_CSTINT
  1924. ;
  1925. stop : TOK_PAUSE
  1926. | TOK_STOP
  1927. ;
  1928. option_inlist :
  1929. | inlist
  1930. ;
  1931. option_read :
  1932. ioctl option_inlist
  1933. | infmt opt_inlist
  1934. ;
  1935. opt_inlist :
  1936. | ',' inlist
  1937. ;
  1938. ioctl : '(' ctllist ')'
  1939. ;
  1940. after_rewind :
  1941. '(' ident ')'
  1942. | '(' TOK_CSTINT ')'
  1943. | TOK_CSTINT
  1944. | '(' uexpr ')'
  1945. | TOK_NAME
  1946. ;
  1947. ctllist :
  1948. ioclause
  1949. | ctllist ',' ioclause
  1950. ;
  1951. ioclause :
  1952. fexpr
  1953. | '*'
  1954. | TOK_DASTER
  1955. | ident expr dims
  1956. | ident expr '%' declare_after_percent ident_dims
  1957. | ident '(' triplet ')'
  1958. | ident '*'
  1959. | ident TOK_DASTER
  1960. ;
  1961. declare_after_percent: { afterpercent = 1; }
  1962. ;
  1963. iofctl :
  1964. TOK_OPEN
  1965. | TOK_CLOSE
  1966. | TOK_FLUSH
  1967. ;
  1968. infmt : unpar_fexpr
  1969. | '*'
  1970. ;
  1971. read : TOK_READ
  1972. | TOK_INQUIRE
  1973. | TOK_PRINT
  1974. ;
  1975. fexpr : unpar_fexpr
  1976. | '(' fexpr ')'
  1977. ;
  1978. unpar_fexpr :
  1979. lhs
  1980. | simple_const
  1981. | fexpr addop fexpr %prec '+'
  1982. | fexpr '*' fexpr
  1983. | fexpr TOK_SLASH fexpr
  1984. | fexpr TOK_DASTER fexpr
  1985. | addop fexpr %prec '*'
  1986. | fexpr TOK_DSLASH fexpr
  1987. | TOK_FILE expr
  1988. | TOK_UNIT expr
  1989. | TOK_NML expr
  1990. | TOK_FMT expr
  1991. | TOK_EXIST expr
  1992. | TOK_ERR expr
  1993. | TOK_END expr
  1994. | TOK_NAME '=' expr
  1995. | predefinedfunction
  1996. ;
  1997. addop : '+'
  1998. | '-'
  1999. ;
  2000. inlist : inelt
  2001. | inlist ',' inelt
  2002. ;
  2003. // opt_lhs :
  2004. // | lhs
  2005. // ;
  2006. inelt : //opt_lhs opt_operation
  2007. lhs opt_operation
  2008. | '(' inlist ')' opt_operation
  2009. | predefinedfunction opt_operation
  2010. | simple_const opt_operation
  2011. | '(' inlist ',' dospec ')'
  2012. ;
  2013. opt_operation :
  2014. | operation
  2015. | opt_operation operation
  2016. ;
  2017. outlist :
  2018. complex_const { strcpy($$,$1); }
  2019. | predefinedfunction { strcpy($$,$1); }
  2020. | uexpr { strcpy($$,$1); }
  2021. | other { strcpy($$,$1); }
  2022. | uexpr ',' expr { sprintf($$,"%s,%s",$1,$3); }
  2023. | uexpr ',' other { sprintf($$,"%s,%s",$1,$3); }
  2024. | other ',' expr { sprintf($$,"%s,%s",$1,$3); }
  2025. | other ',' other { sprintf($$,"%s,%s",$1,$3); }
  2026. | outlist ',' expr { sprintf($$,"%s,%s",$1,$3); }
  2027. | outlist ',' other { sprintf($$,"%s,%s",$1,$3); }
  2028. ;
  2029. other :
  2030. '(' uexpr ',' dospec ')' { sprintf($$,"(%s,%s)",$2,$4); }
  2031. | '(' outlist ',' dospec ')' { sprintf($$,"(%s,%s)",$2,$4); }
  2032. | '(' other ',' dospec ')' { sprintf($$,"(%s,%s)",$2,$4); }
  2033. dospec :
  2034. TOK_NAME '=' expr ',' expr { sprintf($$,"%s=%s,%s)",$1,$3,$5);}
  2035. | TOK_NAME '=' expr ',' expr ',' expr { sprintf($$,"%s=%s,%s,%s)",$1,$3,$5,$7);}
  2036. ;
  2037. goto : TOK_PLAINGOTO '(' expr ',' expr ')' ',' expr
  2038. | TOK_PLAINGOTO TOK_CSTINT
  2039. ;
  2040. allocation_list :
  2041. allocate_object
  2042. | allocation_list ',' allocate_object
  2043. ;
  2044. allocate_object :
  2045. lhs { Add_Allocate_Var_1($1,curmodulename); }
  2046. ;
  2047. allocate_object_list :
  2048. allocate_object
  2049. | allocate_object_list ',' allocate_object
  2050. ;
  2051. opt_stat_spec :
  2052. | ',' TOK_STAT '=' lhs
  2053. ;
  2054. pointer_name_list :
  2055. ident
  2056. | pointer_name_list ',' ident
  2057. ;
  2058. %%
  2059. void process_fortran(const char *input_file)
  2060. {
  2061. extern FILE *fortran_in;
  2062. extern FILE *fortran_out;
  2063. char output_file[LONG_FNAME];
  2064. char input_fullpath[LONG_FNAME];
  2065. if ( todebug == 1 ) printf("Firstpass == %d \n", firstpass);
  2066. yydebug=0;
  2067. /******************************************************************************/
  2068. /* 1- Open input file */
  2069. /******************************************************************************/
  2070. strcpy(cur_filename, input_file);
  2071. sprintf(input_fullpath, "%s/%s", input_dir, input_file);
  2072. fortran_in = fopen(input_fullpath, "r");
  2073. if (! fortran_in)
  2074. {
  2075. printf("Error : File %s does not exist\n", input_fullpath);
  2076. exit(1);
  2077. }
  2078. /******************************************************************************/
  2079. /* 2- Variables initialization */
  2080. /******************************************************************************/
  2081. line_num_input = 1;
  2082. PublicDeclare = 0;
  2083. PrivateDeclare = 0;
  2084. ExternalDeclare = 0;
  2085. SaveDeclare = 0;
  2086. pointerdeclare = 0;
  2087. optionaldeclare = 0;
  2088. incalldeclare = 0;
  2089. inside_type_declare = 0;
  2090. Allocatabledeclare = 0 ;
  2091. Targetdeclare = 0 ;
  2092. VariableIsParameter = 0 ;
  2093. strcpy(NamePrecision,"");
  2094. c_star = 0 ;
  2095. functiondeclarationisdone = 0;
  2096. insubroutinedeclare = 0 ;
  2097. strcpy(subroutinename," ");
  2098. isrecursive = 0;
  2099. InitialValueGiven = 0 ;
  2100. GlobalDeclarationType = 0;
  2101. inmoduledeclare = 0;
  2102. incontainssubroutine = 0;
  2103. afterpercent = 0;
  2104. aftercontainsdeclare = 1;
  2105. strcpy(nameinttypename,"");
  2106. /******************************************************************************/
  2107. /* 3- Parsing of the input file (1 time) */
  2108. /******************************************************************************/
  2109. sprintf(output_file, "%s/%s", output_dir, input_file);
  2110. if (firstpass == 0) fortran_out = fopen(output_file,"w");
  2111. fortran_parse();
  2112. if (firstpass == 0) NewModule_Creation_0();
  2113. if (firstpass == 0) fclose(fortran_out);
  2114. }