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 trunk/AGRIF/LIB – NEMO

source: trunk/AGRIF/LIB/fortran.lex @ 530

Last change on this file since 530 was 530, checked in by opalod, 18 years ago

RB: update of the conv for IOM and NEC MPI library

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.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@imag.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.0                                                                */
34/******************************************************************************/
35%x parameter
36%s character
37%{
38#include <math.h>
39#include <stdlib.h>
40#include <string.h>
41extern FILE * yyin;
42#define MAX_INCLUDE_DEPTH 30
43#define tabsize 6
44YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
45int line_num_fortran=1;
46int line_num_fortran_common=1;
47int newlinef90 = 0;
48char *tmp;
49char tmpc;
50/******************************************************************************/
51/**************PETITS PB NON PREVUS *******************************************/
52/******************************************************************************/
53/* NEXTLINF77 un ligne fortran 77 peut commencer par -      &a=b or on        */
54/*            a prevu seulement       & a=b avec l'espace entre le symbole    */
55/*            de la 7eme et le debut de la ligne de commande                  */
56/*            le ! est aussi interdit comme symbole de la 7 eme colonne       */
57/*            Normalement NEXTLINEF77 \n+[ ]{5}[^ ]                           */
58/******************************************************************************/
59#define YY_USER_ACTION \
60   {\
61      if (firstpass == 0) \
62           {\
63              strcat(curbuf,yytext); \
64         strcpy(motparse,yytext);\
65              colnum = colnum + strlen(motparse);\
66         /*printf("motparse = %s %d\n",motparse,strlen(motparse));*/\
67              ECHO; \
68           }\
69           strcpy(motparse1,yytext);\
70   /*if ( firstpass == 1 )
71                      printf("yytext = %s %d\n",yytext,strlen(yytext));*/\
72   }
73%}
74AGRIFDEB "Agrif_debut"
75AGRIFFIN "Agrif_fin"
76REAL8 "real*8"[ \t]*"(a-h,o-z)"
77NOTTREAT Agrif_do_not_treat
78ENDNOTTREAT Agrif_end_do_not_treat
79
80NIMPORTEQUOI .
81SLASH "/"
82DSLASH "/"[ \t]*"/"
83NAME [a-zA-Z\_][a-zA-Z0-9\_]*
84DIGIT [0-9]+
85INT {DIGIT}
86EXPONENT e[-+]?{DIGIT}
87DEXPONENT d[-+]?{DIGIT}
88QEXPONENT q[-+]?{DIGIT}
89REAL (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){EXPONENT}?)|{DIGIT}\.{EXPONENT}
90REALDP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){DEXPONENT}?)|{DIGIT}\.{DEXPONENT}
91REALQP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){QEXPONENT}?)|{DIGIT}\.{QEXPONENT}
92ENDFUNCTION end[ \t]*function
93DOUBLEPRECISION double[ \t]*precision
94DOUBLECOMPLEX double[ \t]*complex
95
96COMMENTAIRESFORTRAN77 ^([Cc*](([ \t]*\n)|([^AaHhOo\n]{NIMPORTEQUOI}*\n)))
97COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n)
98COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*)
99NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]*
100NEXTLINEF77 \n[ \t]*("&"|"+"|"$"|"*")
101%%
102{NAME}\= {
103      if (firstpass == 0)
104      {
105      fseek(fortranout,-1,1);
106      strcpy(&curbuf[strlen(curbuf)-1],"\0");
107      }
108      yyless(yyleng-1);
109      strcpy(yylval.na,yytext);
110      return TOK_NAME;
111      }
112^C${NOTTREAT}           {return TOK_DONOTTREAT;}
113^C${ENDNOTTREAT}        {return TOK_ENDDONOTTREAT;}
114^C${AGRIFDEB}            return TOK_DEBUT;
115^C${AGRIFFIN}            return TOK_FIN;
116^C$OMP[ \t]*{NIMPORTEQUOI}* return TOK_OMP;
117^C$[ \t]*{NIMPORTEQUOI}* return TOK_DOLLAR;
118
119{REAL8}                 {return TOK_REAL8;}
120subroutine              {return TOK_SUBROUTINE;}
121program                 {return TOK_PROGRAM;}
122allocate                {return TOK_ALLOCATE;}
123deallocate              {return TOK_DEALLOCATE;}
124result                  {return TOK_RESULT;}
125function                {return TOK_FUNCTION;}
126end[ \t]*subroutine     {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
127end[ \t]*program        {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
128end[ \t]*function       {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
129end                     {strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
130include                  return TOK_INCLUDE;
131^[ \t]*use[ ]+           {
132                            strcpy(yylval.na,yytext);
133                            tmpc = input();
134                            unput(tmpc);
135                            if ( (
136                               tmpc >= 'a' && tmpc <= 'z'
137                                  ) || (
138                               tmpc >= 'A' && tmpc <= 'Z'
139                               )  )
140                               {
141                                  return TOK_USE;
142                               }
143                               else
144                               {
145                                  return TOK_NAME;
146                               }
147                         }
148rewind                  {return TOK_REWIND;}
149implicit                 return TOK_IMPLICIT;
150none                     return TOK_NONE;
151call                     return TOK_CALL;
152.true.                   return TOK_TRUE;
153.false.                  return TOK_FALSE;
154\=\>                    {return TOK_POINT_TO;}
155\*\*                    {strcpy(yylval.na,yytext);return TOK_DASTER;}
156\.[ \t]*eq\.            {strcpy(yylval.na,yytext);return TOK_EQ;}
157\.[ \t]*gt\.            {strcpy(yylval.na,yytext);return TOK_GT;}
158\.[ \t]*ge\.            {strcpy(yylval.na,yytext);return TOK_GE;}
159\.[ \t]*lt\.            {strcpy(yylval.na,yytext);return TOK_LT;}
160\.[ \t]*le\.            {strcpy(yylval.na,yytext);return TOK_LE;}
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[ \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;}
189common                  {return TOK_COMMON;}
190global                  {return TOK_GLOBAL;}
191external                {return TOK_EXTERNAL;}
192intent                  {return TOK_INTENT;}
193kind                    {return TOK_KIND;}
194pointer                 {return TOK_POINTER;}
195optional                {return TOK_OPTIONAL;}
196save                    {return TOK_SAVE;}
197^[ \t]*type              {return TOK_TYPE;}
198end[ \t]*type           {return TOK_ENDTYPE;}
199open                     return TOK_OPEN;
200return                   return TOK_RETURN;
201exit[^(]                 return TOK_EXIT;
202print                    return TOK_PRINT;
203module[ \t]*procedure   {return TOK_PROCEDURE;}
204read                    {return TOK_READ;}
205namelist                {return TOK_NAMELIST;}
206write                   {return TOK_WRITE;}
207target                  {return TOK_TARGET;}
208public                  {return TOK_PUBLIC;}
209private                 {return TOK_PRIVATE;}
210\([ \t]*in[ \t]*\)      {return TOK_IN;}
211data                    {return TOK_DATA;}
212continue                 return TOK_CONTINUE;
213go[ \t]*to              {return TOK_PLAINGOTO;}
214\([ \t]*out[ \t]*\)     {return TOK_OUT;}
215\([ \t]*inout[ \t]*\)   {return TOK_INOUT;}
216intrinsic               {return TOK_INTRINSIC;}
217then                    {return TOK_THEN;}
218else[ \t]*if            {return TOK_ELSEIF;}
219else                    {return TOK_ELSE;}
220end[ \t]*if             {return TOK_ENDIF;}
221if[ \t]*\(              {return TOK_LOGICALIF;}
222sum[ \t]*\(             {return TOK_SUM;}
223max[ \t]*\(             {return TOK_MAX;}
224tanh                    {return TOK_TANH;}
225maxval                  {return TOK_MAXVAL;}
226trim                    {return TOK_TRIM;}
227sqrt\(                  {return TOK_SQRT;}
228select[ \t]*case        {return TOK_SELECTCASE;}
229case                    {return TOK_CASE;}
230case[ \t]*default       {return TOK_CASEDEFAULT;}
231end[ \t]*select         {return TOK_ENDSELECT;}
232file[ \t]*\=            {return TOK_FILE;}
233exist[ \t]*\=           {return TOK_EXIST;}
234min[ \t]*\(             {return TOK_MIN;}
235int                     {return TOK_INT;}
236nint                    {return TOK_NINT;}
237float                   {return TOK_FLOAT;}
238exp                     {return TOK_EXP;}
239cos                     {return TOK_COS;}
240cosh                    {return TOK_COSH;}
241acos                    {return TOK_ACOS;}
242sin                     {return TOK_SIN;}
243sinh                    {return TOK_SINH;}
244asin                    {return TOK_ASIN;}
245log                     {return TOK_LOG;}
246tan                     {return TOK_TAN;}
247atan                    {return TOK_ATAN;}
248cycle                   {return TOK_CYCLE;}
249abs\(                     {return TOK_ABS;}
250mod                     {return TOK_MOD;}
251sign                    {return TOK_SIGN;}
252minloc                  {return TOK_MINLOC;}
253maxloc                  {return TOK_MAXLOC;}
254minval                  {return TOK_MINVAL;}
255interface               {return TOK_INTERFACE;}
256backspace               {return TOK_BACKSPACE;}
257end[ \t]*interface      {return TOK_ENDINTERFACE;}
258\({SLASH}               {return TOK_LEFTAB;}
259{SLASH}\)               {return TOK_RIGHTAB;}
260format                  {return TOK_FORMAT;}
261{DOUBLEPRECISION}       {strcpy(yylval.na,yytext);return TOK_DOUBLEPRECISION;}
262{DOUBLECOMPLEX}         {strcpy(yylval.na,yytext);return TOK_DOUBLECOMPLEX;}
263{SLASH}                 {strcpy(yylval.na,yytext);return TOK_SLASH;}
264DSLASH                  {strcpy(yylval.na,yytext);return TOK_DSLASH;}
265(\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CUT;}
266(\')[^\n']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CONSTANT;}
267(\")[^\n]*(\")          {strcpy(yylval.na,yytext);return TOK_CHAR_MESSAGE;}
268({NAME}{REAL})          {strcpy(yylval.na,yytext);return TOK_CHAR_INT;}
269{NAME}                  {strcpy(yylval.na,yytext);return TOK_NAME;}
270{REAL}                  {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
271{REALDP}                {strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
272{REALQP}                {strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
273({DIGIT}\.)/[^{NAME}|"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
274\.                      {return TOK_POINT;}
275{INT}                   {strcpy(yylval.na,yytext);return TOK_CSTINT;}
276\$ {}
277\'|\"                   {return TOK_QUOTE;}
278;|\(|\)|:|\[|\]|\+|\-|\*|\% {strcpy(yylval.na,yytext);return (int) *yytext;}
279\,                      {return (int) *yytext;}
280\;                      {return (int) *yytext;}
281\=                      {return (int) *yytext;}
282\<                      {return (int) *yytext;}
283\>                      {return (int) *yytext;}
284\n                      {colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
285^[ ]*$
286^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ {if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
287[ ]+
288[\t]+                   {colnum=colnum-1+tabsize;}
289[ \t]+ ;
290{NEXTLINEF90}           {line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
291{NEXTLINEF77}           {line_num_fortran++;line_num_fortran_common++;colnum=0;}
292{COMMENTAIRESFORTRAN77} {
293/* fonction non standard     if (  strcasestr(motparse1,"contains") )         */
294                           if (  strstr(motparse1,"contains")  ||
295                                 strstr(motparse1,"Contains")  ||
296                                 strstr(motparse1,"CONTAINS")  )
297                           {
298                              return TOK_CONTAINS;
299                           }
300                           else
301                           {
302                              colnum=0;line_num_fortran++;line_num_fortran_common++;                           
303                           }
304                         }
305{COMMENTAIRESFORTRAN90}   {
306                             colnum = 0;
307                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
308                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
309                          }
310{COMMENTAIRESFORTRAN90_2} {
311                             colnum = 0;
312                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
313                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
314                          }
315%%
316
317fortranerror(char *s)
318{
319   if (!strcasecmp(curfile,mainfile))
320   {
321      printf("%s line %d, fichier %s\n",s,line_num_fortran,curfile);
322   }
323   else
324   {
325      printf("%s line %d, fichier %s\n",s,line_num_fortran_common,curfile);
326   }
327}
328
329int fortranwrap()
330{
331}
Note: See TracBrowser for help on using the repository browser.