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 branches/UKMO/dev_r5518_v3.6_asm_nemovar_community_ersem_hem08/NEMOGCM/EXTERNAL/AGRIF/LIB – NEMO

source: branches/UKMO/dev_r5518_v3.6_asm_nemovar_community_ersem_hem08/NEMOGCM/EXTERNAL/AGRIF/LIB/fortran.lex @ 9319

Last change on this file since 9319 was 7730, checked in by dford, 7 years ago

Clear svn keywords.

File size: 17.8 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%x parameter
36%s character
37%x donottreat
38%s fortran77style
39%s fortran90style
40%{
41#include <math.h>
42#include <stdlib.h>
43#include <string.h>
44extern FILE * yyin;
45#define MAX_INCLUDE_DEPTH 30
46#define tabsize 6
47YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
48int line_num_fortran=1;
49int line_num_fortran_common=1;
50int newlinef90 = 0;
51char *tmp;
52char tmpc;
53/******************************************************************************/
54/**************PETITS PB NON PREVUS *******************************************/
55/******************************************************************************/
56/* NEXTLINF77 un ligne fortran 77 peut commencer par -      &a=b or on        */
57/*            a prevu seulement       & a=b avec l'espace entre le symbole    */
58/*            de la 7eme et le debut de la ligne de commande                  */
59/*            le ! est aussi interdit comme symbole de la 7 eme colonne       */
60/*            Normalement NEXTLINEF77 \n+[ ]{5}[^ ]                           */
61/******************************************************************************/
62#define YY_USER_ACTION \
63        {\
64           if (firstpass == 0) \
65           {\
66              strcat(curbuf,yytext); \
67              Save_Length(curbuf,38); \
68              strcpy(motparse,yytext);\
69              Save_Length(motparse,32); \
70              colnum = colnum + strlen(motparse);\
71              ECHO; \
72           }\
73           strcpy(motparse1,yytext);\
74/*           printf("yytext = %s\n",yytext);*/\
75        /*if ( firstpass == 1 )
76                      printf("yytext = %s %d\n",yytext,strlen(yytext));*/\
77        }
78%}
79AGRIFDEB "Agrif_debut"
80AGRIFFIN "Agrif_fin"
81REAL8 "real*8"[ \t]*"(a-h,o-z)"
82NOTTREAT Agrif_do_not_treat
83ENDNOTTREAT Agrif_end_do_not_treat
84
85NIMPORTEQUOI .
86SLASH "/"
87DSLASH "/"[ \t]*"/"
88NAME [a-zA-Z\_][a-zA-Z0-9\_]*
89DIGIT [0-9]+
90INT {DIGIT}
91EXPONENT e[-+]?{DIGIT}
92DEXPONENT d[-+]?{DIGIT}
93QEXPONENT q[-+]?{DIGIT}
94REAL (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){EXPONENT}?)|{DIGIT}\.{EXPONENT}
95REALDP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){DEXPONENT}?)|{DIGIT}\.{DEXPONENT}
96REALQP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){QEXPONENT}?)|{DIGIT}\.{QEXPONENT}
97ENDFUNCTION end[ \t]*function
98DOUBLEPRECISION double[ \t]*precision
99DOUBLECOMPLEX double[ \t]*complex
100
101COMMENTAIRESFORTRAN77 ^([Cc*](([ \t]*\n)|([^AaHhOo\n]{NIMPORTEQUOI}*\n)))
102COMMENTAIRESFORTRAN77_2 \n([Cc*](([ \t]*\n)|([^AaHhOo\n]{NIMPORTEQUOI}*\n)))
103COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n)
104COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*)
105NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]*
106NEXTLINEF77 [\n \t]*\n[ \t]{5}("&"|"+"|"$"|"*"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"."|"#")
107%%
108  if (infixed) BEGIN(fortran77style) ;
109  if (infree) BEGIN(fortran90style)  ;
110
111^C${AGRIFDEB}            return TOK_DEBUT;
112^C${AGRIFFIN}            return TOK_FIN;
113^C$OMP[ \t]*{NIMPORTEQUOI}* return TOK_OMP;
114^C$[ \t]*{NIMPORTEQUOI}* return TOK_DOLLAR;
115
116{REAL8}                 {return TOK_REAL8;}
117subroutine              {return TOK_SUBROUTINE;}
118program                 {return TOK_PROGRAM;}
119allocate                {inallocate = 1; return TOK_ALLOCATE;}
120nullify        {return TOK_NULLIFY;}
121deallocate              {inallocate = 1; return TOK_DEALLOCATE;}
122result                  {return TOK_RESULT;}
123function                {return TOK_FUNCTION;}
124end[ \t]*subroutine     {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
125end[ \t]*program        {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
126end[ \t]*function       {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
127end                     {strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
128include                  return TOK_INCLUDE;
129^[ \t]*use[ ]+           {
130                            strcpy(yylval.na,yytext);
131                            tmpc = input();
132                            unput(tmpc);
133                            if ( (
134                               tmpc >= 'a' && tmpc <= 'z'
135                                  ) || (
136                               tmpc >= 'A' && tmpc <= 'Z'
137                               )  )
138                               {
139                                  return TOK_USE;
140                               }
141                               else
142                               {
143                                  return TOK_NAME;
144                               }
145                         }
146rewind                  {return TOK_REWIND;}
147implicit                 return TOK_IMPLICIT;
148none                     return TOK_NONE;
149call                     return TOK_CALL;
150.true.                   return TOK_TRUE;
151.false.                  return TOK_FALSE;
152\=\>                    {return TOK_POINT_TO;}
153\*\*                    {strcpy(yylval.na,yytext);return TOK_DASTER;}
154\.[ \t]*eqv\.            {strcpy(yylval.na,yytext);return TOK_EQV;}
155\.[ \t]*eq\.            {strcpy(yylval.na,yytext);return TOK_EQ;}
156\.[ \t]*gt\.            {strcpy(yylval.na,yytext);return TOK_GT;}
157\.[ \t]*ge\.            {strcpy(yylval.na,yytext);return TOK_GE;}
158\.[ \t]*lt\.            {strcpy(yylval.na,yytext);return TOK_LT;}
159\.[ \t]*le\.            {strcpy(yylval.na,yytext);return TOK_LE;}
160\.[ \t]*neqv\.          {strcpy(yylval.na,yytext);return TOK_NEQV;}
161\.[ \t]*ne\.            {strcpy(yylval.na,yytext);return TOK_NE;}
162\.[ \t]*not\.           {strcpy(yylval.na,yytext);return TOK_NOT;}
163\.[ \t]*or\.            {strcpy(yylval.na,yytext);return TOK_OR;}
164\.[ \t]*xor\.           {strcpy(yylval.na,yytext);return TOK_XOR;}
165\.[ \t]*and\.           {strcpy(yylval.na,yytext);return TOK_AND;}
166module                  {return TOK_MODULE;}
167do[ 0-9\t]*while           {return TOK_DOWHILE;}
168end[ \t]*module          return TOK_ENDMODULE;
169end[ \t]*do              return TOK_ENDDO;
170do                      {return TOK_PLAINDO;}
171real                    {strcpy(yylval.na,yytext);return TOK_REAL;}
172integer                 {strcpy(yylval.na,yytext);return TOK_INTEGER;}
173logical                 {strcpy(yylval.na,yytext);return TOK_LOGICAL;}
174character               {strcpy(yylval.na,yytext);return TOK_CHARACTER;}
175allocatable             {return TOK_ALLOCATABLE;}
176close                    return TOK_CLOSE;
177inquire                  return TOK_INQUIRE;
178dimension               {return TOK_DIMENSION;}
179pause                    return TOK_PAUSE;
180equivalence              return TOK_EQUIVALENCE;
181stop                     return TOK_STOP;
182where                    return TOK_WHERE;
183end[ \t]*where           return TOK_ENDWHERE;
184else[ \t]*where          return TOK_ELSEWHERE;
185complex                 {return TOK_COMPLEX;}
186^[ \t]*contains         {return TOK_CONTAINS;}
187only                    {return TOK_ONLY;}
188parameter               {return TOK_PARAMETER;}
189recursive               {return TOK_RECURSIVE;}
190common                  {return TOK_COMMON;}
191^[ \t]*global[ \t]+     {return TOK_GLOBAL;}
192external                {return TOK_EXTERNAL;}
193intent                  {return TOK_INTENT;}
194pointer                 {return TOK_POINTER;}
195optional                {return TOK_OPTIONAL;}
196save                    {return TOK_SAVE;}
197^[ \t]*type[ \t\,]+       {return TOK_TYPE;}
198^[ \t]*type[ \t]*\(     {return TOK_TYPEPAR;}
199stat                    {if (inallocate == 1) return TOK_STAT; else {strcpy(yylval.na,yytext);return TOK_NAME;}}
200end[ \t]*type           {return TOK_ENDTYPE;}
201open                     return TOK_OPEN;
202return                   return TOK_RETURN;
203exit[^(]                 return TOK_EXIT;
204print                    return TOK_PRINT;
205module[ \t]*procedure   {return TOK_PROCEDURE;}
206read                    {return TOK_READ;}
207namelist                {return TOK_NAMELIST;}
208write                   {return TOK_WRITE;}
209target                  {return TOK_TARGET;}
210public                  {return TOK_PUBLIC;}
211private                 {return TOK_PRIVATE;}
212in                      {strcpy(yylval.nac,yytext);return TOK_IN;}
213^[ \t]*data[ \t]+       {strcpy(yylval.na,yytext);return TOK_DATA;}
214continue                 return TOK_CONTINUE;
215go[ \t]*to              {return TOK_PLAINGOTO;}
216out                     {strcpy(yylval.nac,yytext);return TOK_OUT;}
217inout                   {strcpy(yylval.nac,yytext);return TOK_INOUT;}
218intrinsic               {return TOK_INTRINSIC;}
219then                    {return TOK_THEN;}
220else[ \t]*if            {return TOK_ELSEIF;}
221else                    {return TOK_ELSE;}
222end[ \t]*if             {return TOK_ENDIF;}
223if[ \t]*\(              {return TOK_LOGICALIF;}
224sum[ \t]*\(             {return TOK_SUM;}
225max[ \t]*\(             {return TOK_MAX;}
226tanh                    {return TOK_TANH;}
227maxval                  {return TOK_MAXVAL;}
228trim                    {return TOK_TRIM;}
229sqrt\(                  {return TOK_SQRT;}
230select[ \t]*case        {return TOK_SELECTCASE;}
231^[ \t]*case[ \t]*\(     {return TOK_CASE;}
232^[ \t]*case[ \t]*default       {return TOK_CASEDEFAULT;}
233end[ \t]*select         {return TOK_ENDSELECT;}
234file[ \t]*\=            {return TOK_FILE;}
235end[ \t]*\=             {return TOK_END;}
236err[ \t]*\=             {return TOK_ERR;}
237exist[ \t]*\=           {return TOK_EXIST;}
238min[ \t]*\(             {return TOK_MIN;}
239nint                    {return TOK_NINT;}
240float                   {return TOK_FLOAT;}
241exp                     {return TOK_EXP;}
242cos                     {return TOK_COS;}
243cosh                    {return TOK_COSH;}
244acos                    {return TOK_ACOS;}
245sin                     {return TOK_SIN;}
246sinh                    {return TOK_SINH;}
247asin                    {return TOK_ASIN;}
248log                     {return TOK_LOG;}
249tan                     {return TOK_TAN;}
250atan                    {return TOK_ATAN;}
251cycle                   {return TOK_CYCLE;}
252abs\(                   {return TOK_ABS;}
253mod                     {return TOK_MOD;}
254sign                    {return TOK_SIGN;}
255minloc                  {return TOK_MINLOC;}
256maxloc                  {return TOK_MAXLOC;}
257minval                  {return TOK_MINVAL;}
258backspace               {return TOK_BACKSPACE;}
259\({SLASH}               {return TOK_LEFTAB;}
260{SLASH}\)               {return TOK_RIGHTAB;}
261format[ \t]*\(({NIMPORTEQUOI}|{NEXTLINEF90}|{NEXTLINEF77})*\)  {return TOK_FORMAT;}
262{DOUBLEPRECISION}       {strcpy(yylval.na,yytext);return TOK_DOUBLEPRECISION;}
263{DOUBLECOMPLEX}         {strcpy(yylval.na,yytext);return TOK_DOUBLECOMPLEX;}
264{SLASH}                 {strcpy(yylval.na,yytext);return TOK_SLASH;}
265DSLASH                  {strcpy(yylval.na,yytext);return TOK_DSLASH;}
266(\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CUT;}
267(\')[^\n']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CONSTANT;}
268(\")[^\n"]*(\")         {strcpy(yylval.na,yytext);return TOK_CHAR_MESSAGE;}
269({NAME}{REAL})          {strcpy(yylval.na,yytext);return TOK_CHAR_INT;}
270^[ \t]*interface        {printf("debug interfacer\n");BEGIN(donottreat);}
271<donottreat>^[ \t]*end[ \t]*interface[ \t]*\n {
272                  BEGIN(INITIAL);
273                        if (infixed) BEGIN(fortran77style) ;
274                        if (infree) BEGIN(fortran90style)  ;
275                        line_num_fortran++;line_num_fortran_common++;
276                        return '\n';
277                  }
278{NAME}                  {strcpy(yylval.na,yytext);return TOK_NAME;}
279{REAL}                  {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
280{REALDP}                {strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
281{REALQP}                {strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
282({DIGIT}\.)/[^{NAME}|"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
283{INT}                   {strcpy(yylval.na,yytext);return TOK_CSTINT;}
284\$ {}
285\'|\"                   {return TOK_QUOTE;}
286\.                      {}
287\(|\)|:|\[|\]|\+|\-|\* {strcpy(yylval.na,yytext);return (int) *yytext;}
288\%                     {afterpercent = 1; strcpy(yylval.na,yytext);return (int) *yytext;}
289\;                      {return TOK_SEMICOLON;}
290\,                      {return (int) *yytext;}
291\=                      {return (int) *yytext;}
292\<                      {return (int) *yytext;}
293\>                      {return (int) *yytext;}
294\n                      {colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
295^[ ]*$
296^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ {if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
297[ ]+
298[\t]+                   {colnum=colnum-1+tabsize;}
299[ \t]+ ;
300{NEXTLINEF90}           {line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
301{NEXTLINEF77}           {line_num_fortran++;line_num_fortran_common++;colnum=0;}
302<fortran77style>{COMMENTAIRESFORTRAN77} {
303                           convert2lower(motparse1);
304                           if ( strncasecmp(motparse1,"contains",8) == 0 )
305                           {
306                              return TOK_CONTAINS;
307                           }
308                           else
309                           {
310                            /*  colnum=0;line_num_fortran++;line_num_fortran_common++;*/
311                             if ( !strcasecmp(motparse1,"C$AGRIF_DO_NOT_TREAT\n"))
312                             return TOK_DONOTTREAT;
313                             if ( !strcasecmp(motparse1,"C$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
314                             unput('\n');
315                           }
316                         }
317<fortran77style>{COMMENTAIRESFORTRAN77_2} {
318                           convert2lower(&motparse1[1]);
319                           if ( strncasecmp(&motparse1[1],"contains",8) == 0 )
320                           {
321                              return TOK_CONTAINS;
322                           }
323                           else
324                           {
325                             /* colnum=0;line_num_fortran++;line_num_fortran_common++;*/
326                             if ( !strcasecmp(&motparse1[1],"C$AGRIF_DO_NOT_TREAT\n"))
327                             return TOK_DONOTTREAT;
328                             if ( !strcasecmp(&motparse1[1],"C$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
329                             unput('\n');
330                           }
331                         }                           
332^"!$AGRIF_DO_NOT_TREAT"[ \t]*\n {
333                  BEGIN(donottreat);
334                  }
335<donottreat>^"!$AGRIF_END_DO_NOT_TREAT"[ \t]*\n {
336                  BEGIN(INITIAL);
337                        if (infixed) BEGIN(fortran77style) ;
338                        if (infree) BEGIN(fortran90style)  ;
339                        line_num_fortran++;line_num_fortran_common++;
340                        return '\n';
341                  }
342<donottreat>.*\n        {line_num_fortran++;line_num_fortran_common++;}
343{COMMENTAIRESFORTRAN90}   {
344                             colnum = 0;
345                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
346                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
347                          }
348{COMMENTAIRESFORTRAN90_2} {
349                             colnum = 0;
350                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
351                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
352                          }
353%%
354
355fortranerror(char *s)
356{
357   if (!strcasecmp(curfile,mainfile))
358   {
359      printf("%s line %d, file %s motclef = %s\n",s,line_num_fortran,curfile,yytext);
360   }
361   else
362   {
363      printf("%s line %d, file %s motclef = %s curbuf = %s\n",s,line_num_fortran_common,curfile,yytext,curbuf);
364   }
365/*   exit(0);*/
366}
367
368int fortranwrap()
369{
370}
Note: See TracBrowser for help on using the repository browser.