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

source: branches/dev_001_GM/AGRIF/LIB/fortran.lex @ 4310

Last change on this file since 4310 was 663, checked in by opalod, 17 years ago

RB: update CONV

  • 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@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.6                                                                */
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]{5}("&"|"+"|"$"|"*"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"."|"#")
101%%
102
103^C${AGRIFDEB}            return TOK_DEBUT;
104^C${AGRIFFIN}            return TOK_FIN;
105^C$OMP[ \t]*{NIMPORTEQUOI}* return TOK_OMP;
106^C$[ \t]*{NIMPORTEQUOI}* return TOK_DOLLAR;
107
108{REAL8}                 {return TOK_REAL8;}
109subroutine              {return TOK_SUBROUTINE;}
110program                 {return TOK_PROGRAM;}
111allocate                {return TOK_ALLOCATE;}
112deallocate              {return TOK_DEALLOCATE;}
113result                  {return TOK_RESULT;}
114function                {return TOK_FUNCTION;}
115end[ \t]*subroutine     {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
116end[ \t]*program        {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
117end[ \t]*function       {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
118end                     {strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
119include                  return TOK_INCLUDE;
120^[ \t]*use[ ]+           {
121                            strcpy(yylval.na,yytext);
122                            tmpc = input();
123                            unput(tmpc);
124                            if ( (
125                               tmpc >= 'a' && tmpc <= 'z'
126                                  ) || (
127                               tmpc >= 'A' && tmpc <= 'Z'
128                               )  )
129                               {
130                                  return TOK_USE;
131                               }
132                               else
133                               {
134                                  return TOK_NAME;
135                               }
136                         }
137rewind                  {return TOK_REWIND;}
138implicit                 return TOK_IMPLICIT;
139none                     return TOK_NONE;
140call                     return TOK_CALL;
141.true.                   return TOK_TRUE;
142.false.                  return TOK_FALSE;
143\=\>                    {return TOK_POINT_TO;}
144\*\*                    {strcpy(yylval.na,yytext);return TOK_DASTER;}
145\.[ \t]*eq\.            {strcpy(yylval.na,yytext);return TOK_EQ;}
146\.[ \t]*gt\.            {strcpy(yylval.na,yytext);return TOK_GT;}
147\.[ \t]*ge\.            {strcpy(yylval.na,yytext);return TOK_GE;}
148\.[ \t]*lt\.            {strcpy(yylval.na,yytext);return TOK_LT;}
149\.[ \t]*le\.            {strcpy(yylval.na,yytext);return TOK_LE;}
150\.[ \t]*ne\.            {strcpy(yylval.na,yytext);return TOK_NE;}
151\.[ \t]*not\.           {strcpy(yylval.na,yytext);return TOK_NOT;}
152\.[ \t]*or\.            {strcpy(yylval.na,yytext);return TOK_OR;}
153\.[ \t]*xor\.           {strcpy(yylval.na,yytext);return TOK_XOR;}
154\.[ \t]*and\.           {strcpy(yylval.na,yytext);return TOK_AND;}
155module                  {return TOK_MODULE;}
156do[ 0-9\t]*while           {return TOK_DOWHILE;}
157end[ \t]*module          return TOK_ENDMODULE;
158end[ \t]*do              return TOK_ENDDO;
159do                      {return TOK_PLAINDO;}
160real                    {strcpy(yylval.na,yytext);return TOK_REAL;}
161integer                 {strcpy(yylval.na,yytext);return TOK_INTEGER;}
162logical                 {strcpy(yylval.na,yytext);return TOK_LOGICAL;}
163character               {strcpy(yylval.na,yytext);return TOK_CHARACTER;}
164allocatable             {return TOK_ALLOCATABLE;}
165close                    return TOK_CLOSE;
166inquire                  return TOK_INQUIRE;
167dimension               {return TOK_DIMENSION;}
168pause                    return TOK_PAUSE;
169equivalence              return TOK_EQUIVALENCE;
170stop                     return TOK_STOP;
171where                    return TOK_WHERE;
172end[ \t]*where           return TOK_ENDWHERE;
173else[ \t]*where          return TOK_ELSEWHERE;
174complex                 {return TOK_COMPLEX;}
175^[ \t]*contains         {return TOK_CONTAINS;}
176only                    {return TOK_ONLY;}
177parameter               {return TOK_PARAMETER;}
178recursive               {return TOK_RECURSIVE;}
179common                  {return TOK_COMMON;}
180^[ \t]*global[ \t]+     {return TOK_GLOBAL;}
181external                {return TOK_EXTERNAL;}
182intent                  {return TOK_INTENT;}
183pointer                 {return TOK_POINTER;}
184optional                {return TOK_OPTIONAL;}
185save                    {return TOK_SAVE;}
186^[ \t]*type[ \t\,]+       {return TOK_TYPE;}
187^[ \t]*type[ \t]*\(     {return TOK_TYPEPAR;}
188stat                    {return TOK_STAT;}
189end[ \t]*type           {return TOK_ENDTYPE;}
190open                     return TOK_OPEN;
191return                   return TOK_RETURN;
192exit[^(]                 return TOK_EXIT;
193print                    return TOK_PRINT;
194module[ \t]*procedure   {return TOK_PROCEDURE;}
195read                    {return TOK_READ;}
196namelist                {return TOK_NAMELIST;}
197write                   {return TOK_WRITE;}
198target                  {return TOK_TARGET;}
199public                  {return TOK_PUBLIC;}
200private                 {return TOK_PRIVATE;}
201\([ \t]*in[ \t]*\)      {return TOK_IN;}
202^[ \t]*data[ \t]+       {strcpy(yylval.na,yytext);return TOK_DATA;}
203continue                 return TOK_CONTINUE;
204go[ \t]*to              {return TOK_PLAINGOTO;}
205\([ \t]*out[ \t]*\)     {return TOK_OUT;}
206\([ \t]*inout[ \t]*\)   {return TOK_INOUT;}
207intrinsic               {return TOK_INTRINSIC;}
208then                    {return TOK_THEN;}
209else[ \t]*if            {return TOK_ELSEIF;}
210else                    {return TOK_ELSE;}
211end[ \t]*if             {return TOK_ENDIF;}
212if[ \t]*\(              {return TOK_LOGICALIF;}
213sum[ \t]*\(             {return TOK_SUM;}
214max[ \t]*\(             {return TOK_MAX;}
215tanh                    {return TOK_TANH;}
216maxval                  {return TOK_MAXVAL;}
217trim                    {return TOK_TRIM;}
218sqrt\(                  {return TOK_SQRT;}
219select[ \t]*case        {return TOK_SELECTCASE;}
220^[ \t]*case[ \t]*\(     {return TOK_CASE;}
221^[ \t]*case[ \t]*default       {return TOK_CASEDEFAULT;}
222end[ \t]*select         {return TOK_ENDSELECT;}
223file[ \t]*\=            {return TOK_FILE;}
224end[ \t]*\=             {return TOK_END;}
225err[ \t]*\=             {return TOK_ERR;}
226exist[ \t]*\=           {return TOK_EXIST;}
227min[ \t]*\(             {return TOK_MIN;}
228int                     {return TOK_INT;}
229nint                    {return TOK_NINT;}
230float                   {return TOK_FLOAT;}
231exp                     {return TOK_EXP;}
232cos                     {return TOK_COS;}
233cosh                    {return TOK_COSH;}
234acos                    {return TOK_ACOS;}
235sin                     {return TOK_SIN;}
236sinh                    {return TOK_SINH;}
237asin                    {return TOK_ASIN;}
238log                     {return TOK_LOG;}
239tan                     {return TOK_TAN;}
240atan                    {return TOK_ATAN;}
241cycle                   {return TOK_CYCLE;}
242abs\(                   {return TOK_ABS;}
243mod                     {return TOK_MOD;}
244sign                    {return TOK_SIGN;}
245minloc                  {return TOK_MINLOC;}
246maxloc                  {return TOK_MAXLOC;}
247minval                  {return TOK_MINVAL;}
248interface               {return TOK_INTERFACE;}
249backspace               {return TOK_BACKSPACE;}
250end[ \t]*interface      {return TOK_ENDINTERFACE;}
251\({SLASH}               {return TOK_LEFTAB;}
252{SLASH}\)               {return TOK_RIGHTAB;}
253format[ \t]*\(({NIMPORTEQUOI}|{NEXTLINEF90}|{NEXTLINEF77})*\)  {return TOK_FORMAT;}
254{DOUBLEPRECISION}       {strcpy(yylval.na,yytext);return TOK_DOUBLEPRECISION;}
255{DOUBLECOMPLEX}         {strcpy(yylval.na,yytext);return TOK_DOUBLECOMPLEX;}
256{SLASH}                 {strcpy(yylval.na,yytext);return TOK_SLASH;}
257DSLASH                  {strcpy(yylval.na,yytext);return TOK_DSLASH;}
258(\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CUT;}
259(\')[^\n']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CONSTANT;}
260(\")[^\n]*(\")          {strcpy(yylval.na,yytext);return TOK_CHAR_MESSAGE;}
261({NAME}{REAL})          {strcpy(yylval.na,yytext);return TOK_CHAR_INT;}
262{NAME}                  {strcpy(yylval.na,yytext);return TOK_NAME;}
263{REAL}                  {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
264{REALDP}                {strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
265{REALQP}                {strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
266({DIGIT}\.)/[^{NAME}|"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
267{INT}                   {strcpy(yylval.na,yytext);return TOK_CSTINT;}
268\$ {}
269\'|\"                   {return TOK_QUOTE;}
270\.                      {}
271;|\(|\)|:|\[|\]|\+|\-|\*|\% {strcpy(yylval.na,yytext);return (int) *yytext;}
272\,                      {return (int) *yytext;}
273\;                      {return (int) *yytext;}
274\=                      {return (int) *yytext;}
275\<                      {return (int) *yytext;}
276\>                      {return (int) *yytext;}
277\n                      {colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
278^[ ]*$
279^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ {if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
280[ ]+
281[\t]+                   {colnum=colnum-1+tabsize;}
282[ \t]+ ;
283{NEXTLINEF90}           {line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
284{NEXTLINEF77}           {line_num_fortran++;line_num_fortran_common++;colnum=0;}
285{COMMENTAIRESFORTRAN77} {
286                           convert2lower(motparse1);
287                           if ( strncasecmp(motparse1,"contains",8) == 0 )
288                           {
289                              return TOK_CONTAINS;
290                           }
291                           else
292                           {
293                              colnum=0;line_num_fortran++;line_num_fortran_common++;
294                             if ( !strcasecmp(motparse1,"C$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
295                             if ( !strcasecmp(motparse1,"C$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
296                           }
297                         }
298{COMMENTAIRESFORTRAN90}   {
299                             colnum = 0;
300                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
301                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
302                          }
303{COMMENTAIRESFORTRAN90_2} {
304                             colnum = 0;
305                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
306                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
307                          }
308%%
309
310fortranerror(char *s)
311{
312   if (!strcasecmp(curfile,mainfile))
313   {
314      printf("%s line %d, fichier %s\n",s,line_num_fortran,curfile);
315   }
316   else
317   {
318      printf("%s line %d, fichier %s\n",s,line_num_fortran_common,curfile);
319   }
320}
321
322int fortranwrap()
323{
324}
Note: See TracBrowser for help on using the repository browser.