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

source: vendors/AGRIF/current/LIB/fortran.lex @ 1901

Last change on this file since 1901 was 1901, checked in by flavoni, 14 years ago

importing AGRIF vendor

File size: 16.1 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)))
102COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n)
103COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*)
104NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]*
105NEXTLINEF77 \n[ \t]{5}("&"|"+"|"$"|"*"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"."|"#")
106%%
107  if (infixed) BEGIN(fortran77style) ;
108  if (infree) BEGIN(fortran90style)  ;
109
110^C${AGRIFDEB}            return TOK_DEBUT;
111^C${AGRIFFIN}            return TOK_FIN;
112^C$OMP[ \t]*{NIMPORTEQUOI}* return TOK_OMP;
113^C$[ \t]*{NIMPORTEQUOI}* return TOK_DOLLAR;
114
115{REAL8}                 {return TOK_REAL8;}
116subroutine              {return TOK_SUBROUTINE;}
117program                 {return TOK_PROGRAM;}
118allocate                {inallocate = 1; return TOK_ALLOCATE;}
119deallocate              {inallocate = 1; return TOK_DEALLOCATE;}
120result                  {return TOK_RESULT;}
121function                {return TOK_FUNCTION;}
122end[ \t]*subroutine     {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
123end[ \t]*program        {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
124end[ \t]*function       {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
125end                     {strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
126include                  return TOK_INCLUDE;
127^[ \t]*use[ ]+           {
128                            strcpy(yylval.na,yytext);
129                            tmpc = input();
130                            unput(tmpc);
131                            if ( (
132                               tmpc >= 'a' && tmpc <= 'z'
133                                  ) || (
134                               tmpc >= 'A' && tmpc <= 'Z'
135                               )  )
136                               {
137                                  return TOK_USE;
138                               }
139                               else
140                               {
141                                  return TOK_NAME;
142                               }
143                         }
144rewind                  {return TOK_REWIND;}
145implicit                 return TOK_IMPLICIT;
146none                     return TOK_NONE;
147call                     return TOK_CALL;
148.true.                   return TOK_TRUE;
149.false.                  return TOK_FALSE;
150\=\>                    {return TOK_POINT_TO;}
151\*\*                    {strcpy(yylval.na,yytext);return TOK_DASTER;}
152\.[ \t]*eqv\.            {strcpy(yylval.na,yytext);return TOK_EQV;}
153\.[ \t]*eq\.            {strcpy(yylval.na,yytext);return TOK_EQ;}
154\.[ \t]*gt\.            {strcpy(yylval.na,yytext);return TOK_GT;}
155\.[ \t]*ge\.            {strcpy(yylval.na,yytext);return TOK_GE;}
156\.[ \t]*lt\.            {strcpy(yylval.na,yytext);return TOK_LT;}
157\.[ \t]*le\.            {strcpy(yylval.na,yytext);return TOK_LE;}
158\.[ \t]*neqv\.          {strcpy(yylval.na,yytext);return TOK_NEQV;}
159\.[ \t]*ne\.            {strcpy(yylval.na,yytext);return TOK_NE;}
160\.[ \t]*not\.           {strcpy(yylval.na,yytext);return TOK_NOT;}
161\.[ \t]*or\.            {strcpy(yylval.na,yytext);return TOK_OR;}
162\.[ \t]*xor\.           {strcpy(yylval.na,yytext);return TOK_XOR;}
163\.[ \t]*and\.           {strcpy(yylval.na,yytext);return TOK_AND;}
164module                  {return TOK_MODULE;}
165do[ 0-9\t]*while           {return TOK_DOWHILE;}
166end[ \t]*module          return TOK_ENDMODULE;
167end[ \t]*do              return TOK_ENDDO;
168do                      {return TOK_PLAINDO;}
169real                    {strcpy(yylval.na,yytext);return TOK_REAL;}
170integer                 {strcpy(yylval.na,yytext);return TOK_INTEGER;}
171logical                 {strcpy(yylval.na,yytext);return TOK_LOGICAL;}
172character               {strcpy(yylval.na,yytext);return TOK_CHARACTER;}
173allocatable             {return TOK_ALLOCATABLE;}
174close                    return TOK_CLOSE;
175inquire                  return TOK_INQUIRE;
176dimension               {return TOK_DIMENSION;}
177pause                    return TOK_PAUSE;
178equivalence              return TOK_EQUIVALENCE;
179stop                     return TOK_STOP;
180where                    return TOK_WHERE;
181end[ \t]*where           return TOK_ENDWHERE;
182else[ \t]*where          return TOK_ELSEWHERE;
183complex                 {return TOK_COMPLEX;}
184^[ \t]*contains         {return TOK_CONTAINS;}
185only                    {return TOK_ONLY;}
186parameter               {return TOK_PARAMETER;}
187recursive               {return TOK_RECURSIVE;}
188common                  {return TOK_COMMON;}
189^[ \t]*global[ \t]+     {return TOK_GLOBAL;}
190external                {return TOK_EXTERNAL;}
191intent                  {return TOK_INTENT;}
192pointer                 {return TOK_POINTER;}
193optional                {return TOK_OPTIONAL;}
194save                    {return TOK_SAVE;}
195^[ \t]*type[ \t\,]+       {return TOK_TYPE;}
196^[ \t]*type[ \t]*\(     {return TOK_TYPEPAR;}
197stat                    {if (inallocate == 1) return TOK_STAT; else {strcpy(yylval.na,yytext);return TOK_NAME;}}
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;}
210in                      {strcpy(yylval.nac,yytext);return TOK_IN;}
211^[ \t]*data[ \t]+       {strcpy(yylval.na,yytext);return TOK_DATA;}
212continue                 return TOK_CONTINUE;
213go[ \t]*to              {return TOK_PLAINGOTO;}
214out                     {strcpy(yylval.nac,yytext);return TOK_OUT;}
215inout                   {strcpy(yylval.nac,yytext);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;}
229^[ \t]*case[ \t]*\(     {return TOK_CASE;}
230^[ \t]*case[ \t]*default       {return TOK_CASEDEFAULT;}
231end[ \t]*select         {return TOK_ENDSELECT;}
232file[ \t]*\=            {return TOK_FILE;}
233end[ \t]*\=             {return TOK_END;}
234err[ \t]*\=             {return TOK_ERR;}
235exist[ \t]*\=           {return TOK_EXIST;}
236min[ \t]*\(             {return TOK_MIN;}
237nint                    {return TOK_NINT;}
238float                   {return TOK_FLOAT;}
239exp                     {return TOK_EXP;}
240cos                     {return TOK_COS;}
241cosh                    {return TOK_COSH;}
242acos                    {return TOK_ACOS;}
243sin                     {return TOK_SIN;}
244sinh                    {return TOK_SINH;}
245asin                    {return TOK_ASIN;}
246log                     {return TOK_LOG;}
247tan                     {return TOK_TAN;}
248atan                    {return TOK_ATAN;}
249cycle                   {return TOK_CYCLE;}
250abs\(                   {return TOK_ABS;}
251mod                     {return TOK_MOD;}
252sign                    {return TOK_SIGN;}
253minloc                  {return TOK_MINLOC;}
254maxloc                  {return TOK_MAXLOC;}
255minval                  {return TOK_MINVAL;}
256interface               {return TOK_INTERFACE;}
257backspace               {return TOK_BACKSPACE;}
258end[ \t]*interface      {return TOK_ENDINTERFACE;}
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{NAME}                  {strcpy(yylval.na,yytext);return TOK_NAME;}
271{REAL}                  {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
272{REALDP}                {strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
273{REALQP}                {strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
274({DIGIT}\.)/[^{NAME}|"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
275{INT}                   {strcpy(yylval.na,yytext);return TOK_CSTINT;}
276\$ {}
277\'|\"                   {return TOK_QUOTE;}
278\.                      {}
279\(|\)|:|\[|\]|\+|\-|\*|\% {strcpy(yylval.na,yytext);return (int) *yytext;}
280\;                      {return TOK_SEMICOLON;}
281\,                      {return (int) *yytext;}
282\=                      {return (int) *yytext;}
283\<                      {return (int) *yytext;}
284\>                      {return (int) *yytext;}
285\n                      {colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
286^[ ]*$
287^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ {if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
288[ ]+
289[\t]+                   {colnum=colnum-1+tabsize;}
290[ \t]+ ;
291{NEXTLINEF90}           {line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
292{NEXTLINEF77}           {line_num_fortran++;line_num_fortran_common++;colnum=0;}
293<fortran77style>{COMMENTAIRESFORTRAN77} {
294                           convert2lower(motparse1);
295                           if ( strncasecmp(motparse1,"contains",8) == 0 )
296                           {
297                              return TOK_CONTAINS;
298                           }
299                           else
300                           {
301                              colnum=0;line_num_fortran++;line_num_fortran_common++;
302                             if ( !strcasecmp(motparse1,"C$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
303                             if ( !strcasecmp(motparse1,"C$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
304                           }
305                         }
306^"!$AGRIF_DO_NOT_TREAT\n" BEGIN(donottreat);
307<donottreat>^"!$AGRIF_END_DO_NOT_TREAT\n" BEGIN(INITIAL);
308<donottreat>.*\n
309{COMMENTAIRESFORTRAN90}   {
310                             colnum = 0;
311                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
312                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
313                          }
314{COMMENTAIRESFORTRAN90_2} {
315                             colnum = 0;
316                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
317                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
318                          }
319%%
320
321fortranerror(char *s)
322{
323   if (!strcasecmp(curfile,mainfile))
324   {
325      printf("%s line %d, file %s\n",s,line_num_fortran,curfile);
326   }
327   else
328   {
329      printf("%s line %d, file %s\n",s,line_num_fortran_common,curfile);
330   }
331   /*exit(0);*/
332}
333
334int fortranwrap()
335{
336}
Note: See TracBrowser for help on using the repository browser.