New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
fortran.lex in vendors/AGRIF/dev_r12970_AGRIF_CMEMS/LEX – NEMO

source: vendors/AGRIF/dev_r12970_AGRIF_CMEMS/LEX/fortran.lex @ 13027

Last change on this file since 13027 was 13027, checked in by rblod, 4 years ago

New AGRIF library, see ticket #2129

  • Property svn:mime-type set to text/x-csrc
File size: 20.5 KB
Line 
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%option warn
36%option noyywrap
37
38%x parameter
39%s character
40%x donottreat
41%x donottreat_interface
42%x includestate
43%s fortran77style
44%s fortran90style
45%{
46#include <math.h>
47#include <stdlib.h>
48#include <string.h>
49extern FILE * yyin;
50#define MAX_INCLUDE_DEPTH 30
51#define YY_BUF_SIZE 64000
52YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
53int line_num_input = 0;
54int newlinef90 = 0;
55int tmpc;
56
57int lastwasendofstmt = 1;
58
59extern char linebuf1[1024];
60extern char linebuf2[1024];
61
62int count_newlines(const char* str_in)
63{
64    int k, i = 0;
65    for( k=0 ; k<strlen(str_in) ; k++)
66        if (str_in[k] == '\n') i++;
67    return i;
68}
69
70#define PRINT_LINE_NUM()   //  { fprintf(stderr,"== Parsing l.%4d...\n", line_num_input); }
71#define INCREMENT_LINE_NUM() { line_num_input+=count_newlines(fortran_text) ; PRINT_LINE_NUM(); }
72#define YY_USER_ACTION       { if (increment_nbtokens !=0) token_since_endofstmt++; increment_nbtokens = 1; if (token_since_endofstmt>=1) lastwasendofstmt=0; /*printf("VALLIJSDFLSD = %d %d %s \n",lastwasendofstmt,token_since_endofstmt,fortran_text); */ if (firstpass) { strcpy(linebuf1, linebuf2); strncpy(linebuf2, fortran_text,80);} \
73                               else {my_position_before=setposcur();/*printf("muposition = %d\n",my_position_before);*/ECHO;} }
74#define YY_BREAK {/*printf("VALL = %d %d\n",lastwasendofstmt,token_since_endofstmt);*/if (token_since_endofstmt>=1) lastwasendofstmt=0; break;}
75
76void out_of_donottreat(void);
77
78%}
79
80SLASH       "/"
81HEXA        Z\'[0-9a-fA-F]+\'
82INTEGER     [0-9]+
83NAME        [a-zA-Z][a-zA-Z0-9\_]*
84EXPONENT    [edq][-+]?{INTEGER}
85
86BEG_DNT         ^[C!]"$AGRIF_DO_NOT_TREAT"[ \t]*([ \t\n]*(!.*\n)*)+\n
87END_DNT         ^[C!]"$AGRIF_END_DO_NOT_TREAT"[ \t]*([ \t\n]*(!.*\n)*)+\n
88
89BEG_INTERFACE   ^[ \t]*interface
90END_INTERFACE   ^[ \t]*end[ \t]*interface.*\n
91
92ASSIGNTYPE      "assignment"[ \t]*"("[ \t]*[-+=]+[ \t]*")"
93
94COMM_F77        ^[c*].*\n
95COMM_F90_1      ^([ \t\n]*(!.*\n)*)+\n
96COMM_F90_2      !.*
97NEXTLINEF90     &([ \t\n]|(!.*\n))*
98NEXTLINEF77     \n(([c*].*\n)|(([ \t]{0,4}|[ \t]{6,})!.*\n)|[\n])*[ ]{5}([a-z0-9&+$*.#/!;])
99LABEL           ^[ 0-9]{1,5}[ \t]+
100
101%%
102  if (infixed) BEGIN(fortran77style) ;
103  if (infree)  BEGIN(fortran90style) ;
104
105subroutine                  { return TOK_SUBROUTINE; }
106program                     { return TOK_PROGRAM; }
107allocate                    { inallocate = 1; return TOK_ALLOCATE; }
108continue                    { return TOK_CONTINUE; }
109nullify                    { return TOK_NULLIFY; }
110deallocate                  { inallocate = 1; return TOK_DEALLOCATE; }
111result                      { return TOK_RESULT; }
112function                    { return TOK_FUNCTION; }
113end                         { strcpy(yylval.na,fortran_text); return TOK_ENDUNIT;}
114include                     { pos_curinclude = setposcur()-9; BEGIN(includestate); }
115use                         { return TOK_USE;}
116rewind                      { return TOK_REWIND; }
117implicit                    { return TOK_IMPLICIT; }
118none                        { return TOK_NONE; }
119call                        { return TOK_CALL; }
120.true.                      { strcpy(yylval.na,fortran_text); return TOK_TRUE; }
121.false.                     { strcpy(yylval.na,fortran_text); return TOK_FALSE; }
122\=\>                        { return TOK_POINT_TO; }
123{ASSIGNTYPE}                { strcpy(yylval.na,fortran_text); return TOK_ASSIGNTYPE;}
124\*\*                        { strcpy(yylval.na,fortran_text); return TOK_DASTER; }
125\.eqv\.               { strcpy(yylval.na,fortran_text); return TOK_EQV; }
126\.[ \t]*eq[ \t]*\.                { strcpy(yylval.na,fortran_text); return TOK_EQ;  }
127\.gt\.                { strcpy(yylval.na,fortran_text); return TOK_GT;  }
128\.ge\.                { strcpy(yylval.na,fortran_text); return TOK_GE;  }
129\.lt\.                { strcpy(yylval.na,fortran_text); return TOK_LT;  }
130\.le\.                { strcpy(yylval.na,fortran_text); return TOK_LE;  }
131\.neqv\.              { strcpy(yylval.na,fortran_text); return TOK_NEQV;}
132\.[ \t]*ne[ \t]*\.                { strcpy(yylval.na,fortran_text); return TOK_NE;  }
133\.not\.               { strcpy(yylval.na,fortran_text); return TOK_NOT; }
134\.or\.                { strcpy(yylval.na,fortran_text); return TOK_OR;  }
135\.[ \t]*xor\.               { strcpy(yylval.na,fortran_text); return TOK_XOR; }
136\.and\.               { strcpy(yylval.na,fortran_text); return TOK_AND; }
137\=\=                  { strcpy(yylval.na,fortran_text); return TOK_EQUALEQUAL; }
138\/\=                  { strcpy(yylval.na,fortran_text); return TOK_SLASHEQUAL; }
139\<\=                  { strcpy(yylval.na,fortran_text); return TOK_INFEQUAL; }
140\>\=                  { strcpy(yylval.na,fortran_text); return TOK_SUPEQUAL; }
141module                      { return TOK_MODULE; }
142while                       { return TOK_WHILE; }
143concurrent                  { return TOK_CONCURRENT; }
144end[ \t]*do                 { return TOK_ENDDO; }
145do[\ t]+{INTEGER}           { strcpy(yylval.na,&fortran_text[2]);
146                              if (testandextractfromlist(&List_Do_labels,&fortran_text[2]) == 1)
147                              {
148                              return TOK_PLAINDO_LABEL_DJVIEW;
149                              }
150                              else
151                              {
152                              List_Do_labels=Insertname(List_Do_labels,yylval.na,1);
153                              return TOK_PLAINDO_LABEL;
154                             }
155                             }
156do                          { increment_nbtokens = 0; return TOK_PLAINDO;}
157real                        { strcpy(yylval.na,fortran_text); return TOK_REAL; }
158integer                     { strcpy(yylval.na,fortran_text); return TOK_INTEGER; }
159logical                     { strcpy(yylval.na,fortran_text); return TOK_LOGICAL; }
160character                   { strcpy(yylval.na,fortran_text); return TOK_CHARACTER; }
161{HEXA}                      { strcpy(yylval.na,fortran_text); return TOK_HEXA;}
162double[ \t]*precision       { strcpy(yylval.na,fortran_text); return TOK_DOUBLEPRECISION; }
163double[ \t]*complex         { strcpy(yylval.na,fortran_text); return TOK_DOUBLECOMPLEX; }
164complex                     { strcpy(yylval.na,fortran_text); return TOK_COMPLEX; }
165allocatable                 { return TOK_ALLOCATABLE; }
166close                       { return TOK_CLOSE; }
167inquire                     { return TOK_INQUIRE; }
168dimension                   { return TOK_DIMENSION; }
169pause                       { return TOK_PAUSE; }
170equivalence                 { return TOK_EQUIVALENCE; }
171stop                        { return TOK_STOP; }
172where                       { return TOK_WHERE; }
173end[ \t]*where              { return TOK_ENDWHERE; }
174else[ \t]*where[ \t]*\(     { return TOK_ELSEWHEREPAR; }
175else[ \t]*where             { return TOK_ELSEWHERE; }
176^[ \t]*contains             { return TOK_CONTAINS; }
177only                        { return TOK_ONLY; }
178parameter                   { return TOK_PARAMETER; }
179recursive                   { return TOK_RECURSIVE; }
180common                      { return TOK_COMMON; }
181^[ \t]*global[ \t]+         { return TOK_GLOBAL; }
182external                    { return TOK_EXTERNAL; }
183intent                      { intent_spec = 1; return TOK_INTENT; }
184pointer                     { return TOK_POINTER; }
185optional                    { return TOK_OPTIONAL; }
186save                        { return TOK_SAVE; }
187^[ \t]*type[ \t]*\(         { pos_cur_decl = setposcur()-strlen(fortran_text); return TOK_TYPEPAR; }
188^[ \t]*type/[ \t\,:]+       { return TOK_TYPE; }
189end[ \t]*type               { return TOK_ENDTYPE; }
190stat                        { if (inallocate == 1) return TOK_STAT; else { strcpy(yylval.na,fortran_text); return TOK_NAME; } }
191open                        { return TOK_OPEN; }
192return                      { return TOK_RETURN; }
193exit                        { return TOK_EXIT; }
194print                       { return TOK_PRINT; }
195module[ \t]*procedure       { return TOK_PROCEDURE; }
196read[ \t]*\(                { in_io_control_spec = 1; return TOK_READ_PAR; }
197read                        { return TOK_READ; }
198namelist                    { return TOK_NAMELIST; }
199write[ \t]*\(               { in_io_control_spec = 1; return TOK_WRITE_PAR; }
200write                       { return TOK_WRITE; }
201flush                       { strcpy(yylval.na,fortran_text); return TOK_FLUSH; }
202target                      { return TOK_TARGET; }
203public                      { return TOK_PUBLIC; }
204private                     { return TOK_PRIVATE; }
205in                          { strcpy(yylval.na,fortran_text);
206                               if (intent_spec==1)
207                                {return TOK_IN; }
208                              else
209                              {
210                              return TOK_NAME;
211                              }
212                            }
213^[ \t]*data[ \t]+           { pos_curdata = setposcur()-strlen(fortran_text); /*Init_List_Data_Var();*/ return TOK_DATA; }
214go[ \t]*to                  { return TOK_PLAINGOTO; }
215out                         { strcpy(yylval.na,fortran_text);
216                               if (intent_spec==1)
217                                {return TOK_OUT; }
218                              else
219                              {
220                              return TOK_NAME;
221                              }
222                            }
223inout                       { strcpy(yylval.na,fortran_text);
224                               if (intent_spec==1)
225                                {return TOK_IN; }
226                              else
227                              {
228                              return TOK_INOUT;
229                              }
230                            }
231intrinsic                   { return TOK_INTRINSIC; }
232then                        { return TOK_THEN; }
233else[ \t]*if                { return TOK_ELSEIF; }
234else                        { return TOK_ELSE; }
235end[ \t]*if                 { return TOK_ENDIF; }
236if[ \t]*\(/(.*\)[ \t]*[\=|\+|\-]+.*\))   {strcpy(yylval.na,fortran_text);
237                            return TOK_LOGICALIF_PAR;
238                            }
239if/([ \t]*\([^(]*\)[ \t]*[\=|\+|\-]+)   {strcpy(yylval.na,fortran_text);
240                            return TOK_NAME;
241                            }
242if[ \t]*\(                 {strcpy(yylval.na,fortran_text);
243                            return TOK_LOGICALIF_PAR;
244                            }
245select[ \t]*case            { return TOK_SELECTCASE; }
246^[ \t]*case[ \t]*           { if (in_select_case_stmt > 0) return TOK_CASE ; else return TOK_NAME;}
247default                     { return TOK_DEFAULT; }
248end[ \t]*select             { return TOK_ENDSELECT; }
249file[ \t]*\=                { return TOK_FILE; }
250access[ \t]*\=                { return TOK_ACCESS; }
251action[ \t]*\=                { return TOK_ACTION; }
252iolength[ \t]*\=                { return TOK_IOLENGTH; }
253unit[ \t]*\=                { return TOK_UNIT; }
254opened[ \t]*\=                { return TOK_OPENED; }
255fmt[ \t]*\=                 { return TOK_FMT; }
256nml[ \t]*\=                 { return TOK_NML; }
257end[ \t]*\=                 { return TOK_END; }
258eor[ \t]*\=                 { return TOK_EOR; }
259len/([ \t]*\=)                 {
260                            if (in_char_selector ==1)
261                               return TOK_LEN;
262                            else
263                            {
264                            strcpy(yylval.na,fortran_text); return TOK_NAME;
265                            }
266                            }
267kind/([ \t]*\=)            {
268                            if ((in_char_selector==1) || (in_kind_selector == 1))
269                               return TOK_KIND;
270                            else
271                            {
272                            strcpy(yylval.na,fortran_text); return TOK_NAME;
273                            }
274                            }
275errmsg[ \t]*\=              { return TOK_ERRMSG; }
276mold[ \t]*\=              { return TOK_MOLD; }
277source[ \t]*\=              { return TOK_SOURCE; }
278position[ \t]*\=            { return TOK_POSITION; }
279iomsg[ \t]*\=               { return TOK_IOMSG; }
280iostat[ \t]*\=              { return TOK_IOSTAT; }
281err[ \t]*\=                 { return TOK_ERR; }
282form[ \t]*\=                { return TOK_FORM; }
283name/([ \t]*\=)             {
284                            if (in_inquire==1)
285                               return TOK_NAME_EQ;
286                            else
287                            {
288                            strcpy(yylval.na,fortran_text); return TOK_NAME;
289                            }
290                            }
291recl[ \t]*\=                { return TOK_RECL; }
292rec/([ \t]*\=)              { if (in_io_control_spec == 1)
293                              return TOK_REC;
294                             else
295                             {
296                             strcpy(yylval.na,fortran_text); return TOK_NAME;
297                             }
298                             }
299status/([ \t]*\=)           { if (close_or_connect == 1)
300                              return TOK_STATUS;
301                             else
302                             {
303                             strcpy(yylval.na,fortran_text); return TOK_NAME;
304                             }
305                             }
306status                      { strcpy(yylval.na,fortran_text); return TOK_NAME;}
307exist[ \t]*\=               { return TOK_EXIST; }
308cycle                       { return TOK_CYCLE; }
309backspace                   { return TOK_BACKSPACE; }
310::                          { return TOK_FOURDOTS;  }
311\/[ \t]*({NEXTLINEF90}|{NEXTLINEF77})*[ \t]*\/  { strcpy(yylval.na,fortran_text); return TOK_DSLASH; }
312\({SLASH}                   { return TOK_LEFTAB; }
313{SLASH}\)                   { return TOK_RIGHTAB; }
314{SLASH}                     { strcpy(yylval.na,fortran_text); return TOK_SLASH; }
315((\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\'))+ {
316                              INCREMENT_LINE_NUM() ; strcpy(yylval.na,fortran_text); return TOK_CHAR_CUT; }
317<includestate>((\')[^']*(\'))+ {Add_Include_1(fortran_text);}
318<includestate>[ \t]* {}
319<includestate>\n {
320                  if (inmoduledeclare == 0 )
321                  {
322                  pos_end=setposcur();
323                  RemoveWordSET_0(fortran_out,pos_curinclude,pos_end-pos_curinclude);
324                  }
325                  out_of_donottreat();
326                  }
327((\')[^']*(\'))+               { strcpy(yylval.na,fortran_text);return TOK_CHAR_CONSTANT; }
328((\")[^"]*(\"))+               { strcpy(yylval.na,fortran_text);return TOK_CHAR_MESSAGE; }
329{BEG_INTERFACE}             { BEGIN(donottreat_interface); }
330<donottreat_interface>{END_INTERFACE} { out_of_donottreat(); return '\n'; }
331<donottreat_interface>.*\n            {INCREMENT_LINE_NUM() ; }
332<fortran77style>{NAME}{NEXTLINEF77}[a-zA-Z0-9\_]+ {strcpy(yylval.na,fortran_text); removenewline(yylval.na);
333                            return TOK_NAME; }
334{NAME}                      { strcpy(yylval.na,fortran_text); return TOK_NAME; }
335{INTEGER}\.[0-9]+           {strcpy(yylval.na,fortran_text); return TOK_CSTREAL; }
336({INTEGER}\.[0-9]*)/[^"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {  // REAL1
337                              strcpy(yylval.na,fortran_text); return TOK_CSTREAL; }
338(({INTEGER}\.[0-9]+|[0-9]*\.{INTEGER}){EXPONENT}?)|{INTEGER}(\.)?{EXPONENT}                     {  // REAL2
339                              strcpy(yylval.na,fortran_text); return TOK_CSTREAL; }
340{INTEGER}                   { strcpy(yylval.na,fortran_text);
341                             if (lastwasendofstmt == 0)
342                              return TOK_CSTINT;
343                             else
344                              if (testandextractfromlist(&List_Do_labels,fortran_text) == 1)
345                              {
346                              removefromlist(&List_Do_labels,yylval.na);
347                              return TOK_LABEL_DJVIEW;
348                              }
349                              else
350                              {
351                              return TOK_LABEL;
352                              }
353                             }
354\$                          {}
355\.                          {}
356\(/([ \t]*[\+\-]?[a-zA-Z0-9]+[\.]*[0-9]*(\_({INTEGER}|{NAME}))?[ \t]*\,[ \t]*[\+\-]?[a-zA-Z0-9]+[\.]*[0-9]*(\_({INTEGER}|{NAME}))?[ \t]*\)) {
357                            in_complex_literal = -1;
358                            return (int) *fortran_text;
359                            }
360\(|\)|:|\[|\]|\+|\-|\*|\_   { strcpy(yylval.na,fortran_text); return (int) *fortran_text; }
361\%                          { strcpy(yylval.na,fortran_text); return (int) *fortran_text; }
362\;                          { lastwasendofstmt=1; token_since_endofstmt = 0; return TOK_SEMICOLON; }
363\,                          { if (in_complex_literal==-1) {return TOK_COMMACOMPLEX; in_complex_literal=0;} else; return (int) *fortran_text; }
364\=                          { return (int) *fortran_text; }
365\<                          { return (int) *fortran_text; }
366\>                          { return (int) *fortran_text; }
367\n                          { INCREMENT_LINE_NUM() ; lastwasendofstmt=1; token_since_endofstmt = 0; increment_nbtokens = 0; return '\n'; }
368[ \t]+                      {increment_nbtokens = 0;}
369<fortran77style>{LABEL}[ \t]*format[ \t]*\((.|{NEXTLINEF90}|{NEXTLINEF77})*\)  {
370                              return TOK_LABEL_FORMAT; }
371<fortran90style>^[ \t]*{INTEGER}[ \t]*format[ \t]*\((.|{NEXTLINEF90})*\) {return TOK_LABEL_FORMAT; }
372{NEXTLINEF90}               { INCREMENT_LINE_NUM() ; newlinef90=1; }
373<fortran77style>{NEXTLINEF77}               { INCREMENT_LINE_NUM() ;}
374
375{BEG_DNT}                   {INCREMENT_LINE_NUM() ; BEGIN(donottreat); }
376<donottreat>{END_DNT}       {out_of_donottreat(); return '\n'; }
377<donottreat>.*\n            {INCREMENT_LINE_NUM() ; }
378<fortran77style>{COMM_F77}  {INCREMENT_LINE_NUM() ; increment_nbtokens = 0;}
379{COMM_F90_1}                {INCREMENT_LINE_NUM() ; increment_nbtokens = 0;}
380{COMM_F90_2}                {increment_nbtokens = 0;}
381<<EOF>>                     {endoffile = 1; yyterminate();}
382%%
383
384void out_of_donottreat ( void )
385{
386    BEGIN(INITIAL);
387    if (infixed) BEGIN(fortran77style) ;
388    if (infree)  BEGIN(fortran90style) ;
389    INCREMENT_LINE_NUM() ;
390}
Note: See TracBrowser for help on using the repository browser.