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 @ 396

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

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.4 KB
Line 
1/******************************************************************************/
2/*                                                                            */
3/*     CONV (converter) for Agrif (Adaptive Grid Refinement In Fortran)       */
4/*                                                                            */
5/*     Copyright (C) 2005 Laurent Debreu (Laurent.Debreu@imag.fr)             */
6/*                        Cyril Mazauric (Cyril.Mazauric@imag.fr)             */
7/*                                                                            */
8/*     This program is free software; you can redistribute it and/or modify   */
9/*    it                                                                      */
10/*                                                                            */
11/*    This program is distributed in the hope that it will be useful,         */
12/*     but WITHOUT ANY WARRANTY; without even the implied warranty of         */
13/*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
14/*    GNU General Public License for more details.                            */
15/*                                                                            */
16/******************************************************************************/
17%x parameter
18%s character
19%{
20#include <math.h>
21#include <stdlib.h>
22#include <string.h>
23extern FILE * yyin;
24#define MAX_INCLUDE_DEPTH 30
25#define tabsize 6
26YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
27int line_num_fortran=1;
28int line_num_fortran_common=1;
29int newlinef90 = 0;
30char *tmp;
31/******************************************************************************/
32/**************PETITS PB NON PREVUS *******************************************/
33/******************************************************************************/
34/* NEXTLINF77 un ligne fortran 77 peut commencer par -      &a=b or on        */
35/*            a prevu seulement       & a=b avec l'espace entre le symbole    */
36/*            de la 7eme et le debut de la ligne de commande                  */
37/*            le ! est aussi interdit comme symbole de la 7 eme colonne       */
38/*            Normalement NEXTLINEF77 \n+[ ]{5}[^ ]                           */
39/******************************************************************************/
40#define YY_USER_ACTION \
41   {\
42      if (firstpass == 0) \
43           {\
44              strcat(curbuf,yytext); \
45         strcpy(motparse,yytext);\
46              colnum = colnum + strlen(motparse);\
47         /*printf("motparse = %s %d\n",motparse,strlen(motparse));*/\
48              ECHO; \
49           }\
50           strcpy(motparse1,yytext);\
51   /*if ( firstpass == 1 )
52                      printf("yytext = %s %d\n",yytext,strlen(yytext));*/\
53   }
54%}
55AGRIFDEB "Agrif_debut"
56AGRIFFIN "Agrif_fin"
57NOTTREAT Agrif_do_not_treat
58ENDNOTTREAT Agrif_end_do_not_treat
59
60NIMPORTEQUOI .
61SAME_LINE ";"
62SLASH "/"
63DSLASH "/"[ \t]*"/"
64NAME [a-zA-Z\_][a-zA-Z0-9\_]*
65DIGIT [0-9]+
66INT {DIGIT}
67EXPONENT e[-+]?{DIGIT}
68DEXPONENT d[-+]?{DIGIT}
69QEXPONENT q[-+]?{DIGIT}
70REAL (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){EXPONENT}?)|{DIGIT}\.{EXPONENT}
71REALDP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){DEXPONENT}?)|{DIGIT}\.{DEXPONENT}
72REALQP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){QEXPONENT}?)|{DIGIT}\.{QEXPONENT}
73ENDFUNCTION end[ \t]*function
74DOUBLEPRECISION double[ \t]*precision
75DOUBLECOMPLEX double[ \t]*complex
76
77COMMENTAIRESFORTRAN77 (^[Cc]{NIMPORTEQUOI}*)
78COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n)
79COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*)
80NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]*
81NEXTLINEF77 \n[ \t]*"&"
82%%
83{NAME}\= {
84      if (firstpass == 0)
85      {
86      fseek(fortranout,-1,1);
87      strcpy(&curbuf[strlen(curbuf)-1],"\0");
88      }
89      yyless(yyleng-1);
90      strcpy(yylval.na,yytext);
91      return TOK_NAME;
92      }
93^C${NOTTREAT}           {return TOK_DONOTTREAT;}
94^C${ENDNOTTREAT}        {return TOK_ENDDONOTTREAT;}
95^C${AGRIFDEB}            return TOK_DEBUT;
96^C${AGRIFFIN}            return TOK_FIN;
97^C$OMP[ \t]*{NIMPORTEQUOI}* return TOK_OMP;
98^C$[ \t]*{NIMPORTEQUOI}* return TOK_DOLLAR;
99
100subroutine              {return TOK_SUBROUTINE;}
101program                 {return TOK_PROGRAM;}
102allocate                {return TOK_ALLOCATE;}
103deallocate              {return TOK_DEALLOCATE;}
104result                  {return TOK_RESULT;}
105function                {return TOK_FUNCTION;}
106end[ \t]*subroutine     {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;}
107end[ \t]*program        {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;}
108end[ \t]*function       {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;}
109end                     {strcpy(yylval.na,yytext);return TOK_ENDUNIT;}
110include                  return TOK_INCLUDE;
111use                     {return TOK_USE;}
112rewind                  {return TOK_REWIND;}
113implicit                 return TOK_IMPLICIT;
114none                     return TOK_NONE;
115call                     return TOK_CALL;
116.true.                   return TOK_TRUE;
117.false.                  return TOK_FALSE;
118\=\>                    {return TOK_POINT_TO;}
119\*\*                    {strcpy(yylval.na,yytext);return TOK_DASTER;}
120\.[ \t]*eq\.            {strcpy(yylval.na,yytext);return TOK_EQ;}
121\.[ \t]*gt\.            {strcpy(yylval.na,yytext);return TOK_GT;}
122\.[ \t]*ge\.            {strcpy(yylval.na,yytext);return TOK_GE;}
123\.[ \t]*lt\.            {strcpy(yylval.na,yytext);return TOK_LT;}
124\.[ \t]*le\.            {strcpy(yylval.na,yytext);return TOK_LE;}
125\.[ \t]*ne\.            {strcpy(yylval.na,yytext);return TOK_NE;}
126\.[ \t]*not\.           {strcpy(yylval.na,yytext);return TOK_NOT;}
127\.[ \t]*or\.            {strcpy(yylval.na,yytext);return TOK_OR;}
128\.[ \t]*xor\.           {strcpy(yylval.na,yytext);return TOK_XOR;}
129\.[ \t]*and\.           {strcpy(yylval.na,yytext);return TOK_AND;}
130module                  {return TOK_MODULE;}
131do[ \t]*while           {return TOK_DOWHILE;}
132end[ \t]*module          return TOK_ENDMODULE;
133end[ \t]*do              return TOK_ENDDO;
134do                      {return TOK_PLAINDO;}
135real                    {strcpy(yylval.na,yytext);return TOK_REAL;}
136integer                 {strcpy(yylval.na,yytext);return TOK_INTEGER;}
137logical                 {strcpy(yylval.na,yytext);return TOK_LOGICAL;}
138character               {strcpy(yylval.na,yytext);return TOK_CHARACTER;}
139allocatable             {return TOK_ALLOCATABLE;}
140close                    return TOK_CLOSE;
141inquire                  return TOK_INQUIRE;
142dimension               {return TOK_DIMENSION;}
143pause                    return TOK_PAUSE;
144equivalence              return TOK_EQUIVALENCE;
145stop                     return TOK_STOP;
146where                    return TOK_WHERE;
147end[ \t]*where           return TOK_ENDWHERE;
148else[ \t]*where          return TOK_ELSEWHERE;
149complex                 {return TOK_COMPLEX;}
150^[ \t]*contains         {return TOK_CONTAINS;}
151only                    {return TOK_ONLY;}
152parameter               {return TOK_PARAMETER;}
153common                  {return TOK_COMMON;}
154external                {return TOK_EXTERNAL;}
155intent                  {return TOK_INTENT;}
156kind                    {return TOK_KIND;}
157pointer                 {return TOK_POINTER;}
158optional                {return TOK_OPTIONAL;}
159save                    {return TOK_SAVE;}
160^[ \t]*type              {return TOK_TYPE;}
161end[ \t]*type           {return TOK_ENDTYPE;}
162open                     return TOK_OPEN;
163return                   return TOK_RETURN;
164exit                     return TOK_EXIT;
165print                    return TOK_PRINT;
166module[ \t]*procedure   {return TOK_PROCEDURE;}
167read                    {return TOK_READ;}
168namelist                {return TOK_NAMELIST;}
169write                   {return TOK_WRITE;}
170target                  {return TOK_TARGET;}
171public                  {return TOK_PUBLIC;}
172private                 {return TOK_PRIVATE;}
173in                      {return TOK_IN;}
174data                    {return TOK_DATA;}
175continue                 return TOK_CONTINUE;
176go[ \t]*to              {return TOK_PLAINGOTO;}
177out                     {return TOK_OUT;}
178inout                   {return TOK_INOUT;}
179intrinsic               {return TOK_INTRINSIC;}
180then                    {return TOK_THEN;}
181else[ \t]*if            {return TOK_ELSEIF;}
182else                    {return TOK_ELSE;}
183end[ \t]*if             {return TOK_ENDIF;}
184if                      {return TOK_LOGICALIF;}
185sum[ \t]*\(              {return TOK_SUM;}
186max                     {return TOK_MAX;}
187tanh                    {return TOK_TANH;}
188maxval                  {return TOK_MAXVAL;}
189trim                    {return TOK_TRIM;}
190sqrt                    {return TOK_SQRT;}
191select[ \t]*case        {return TOK_SELECTCASE;}
192case                    {return TOK_CASE;}
193case[ \t]*default       {return TOK_CASEDEFAULT;}
194end[ \t]*select         {return TOK_ENDSELECT;}
195file[ \t]*\=            {return TOK_FILE;}
196exist[ \t]*\=           {return TOK_EXIST;}
197min[ \t]*\(             {return TOK_MIN;}
198int                     {return TOK_INT;}
199nint                    {return TOK_NINT;}
200float                   {return TOK_FLOAT;}
201exp                     {return TOK_EXP;}
202cos                     {return TOK_COS;}
203cosh                    {return TOK_COSH;}
204acos                    {return TOK_ACOS;}
205sin                     {return TOK_SIN;}
206sinh                    {return TOK_SINH;}
207asin                    {return TOK_ASIN;}
208log                     {return TOK_LOG;}
209tan                     {return TOK_TAN;}
210atan                    {return TOK_ATAN;}
211abs                     {return TOK_ABS;}
212mod                     {return TOK_MOD;}
213sign                    {return TOK_SIGN;}
214minloc                  {return TOK_MINLOC;}
215maxloc                  {return TOK_MAXLOC;}
216minval                  {return TOK_MINVAL;}
217interface               {return TOK_INTERFACE;}
218end[ \t]*interface      {return TOK_ENDINTERFACE;}
219\({SLASH}               {return TOK_LEFTAB;}
220{SLASH}\)               {return TOK_RIGHTAB;}
221format                  {return TOK_FORMAT;}
222{DOUBLEPRECISION}       {strcpy(yylval.na,yytext);return TOK_DOUBLEPRECISION;}
223{DOUBLECOMPLEX}         {strcpy(yylval.na,yytext);return TOK_DOUBLECOMPLEX;}
224{SAME_LINE}             {return '\n';}
225{SLASH}                 {strcpy(yylval.na,yytext);return TOK_SLASH;}
226DSLASH                  {strcpy(yylval.na,yytext);return TOK_DSLASH;}
227(\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CUT;}
228(\')[^\n']*(\')         {strcpy(yylval.na,yytext);return TOK_CHAR_CONSTANT;}
229(\")[^\n]*(\")          {strcpy(yylval.na,yytext);return TOK_CHAR_MESSAGE;}
230({NAME}{REAL})          {strcpy(yylval.na,yytext);return TOK_CHAR_INT;}
231{NAME}                  {strcpy(yylval.na,yytext);return TOK_NAME;}
232{REAL}                  {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
233{REALDP}                {strcpy(yylval.na,yytext);return TOK_CSTREALDP;}
234{REALQP}                {strcpy(yylval.na,yytext);return TOK_CSTREALQP;}
235({DIGIT}\.)/[^{NAME}|"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] {strcpy(yylval.na,yytext);return TOK_CSTREAL;}
236\.                      {return TOK_POINT;}
237{INT}                   {strcpy(yylval.na,yytext);return TOK_CSTINT;}
238\$ {}
239\'|\"                   {return TOK_QUOTE;}
240;|\(|\)|:|\[|\]|\+|\-|\*|\% {strcpy(yylval.na,yytext);return (int) *yytext;}
241\,                      {return (int) *yytext;}
242\=                      {return (int) *yytext;}
243\<                      {return (int) *yytext;}
244\>                      {return (int) *yytext;}
245\n                      {colnum=0;line_num_fortran++;line_num_fortran_common++; return (int) *yytext;}
246^[ ]*$
247^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ {if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0;}
248[ ]+
249[\t]+                   {colnum=colnum-1+tabsize;}
250[ \t]+ ;
251{NEXTLINEF90}           {line_num_fortran++;line_num_fortran_common++;newlinef90=1;colnum=0;}
252{NEXTLINEF77}           {line_num_fortran++;line_num_fortran_common++;colnum=0;}
253{COMMENTAIRESFORTRAN77} {
254                                       tmp =  strstr(motparse1,"contains");
255                           if ( !tmp ) tmp =  strstr(motparse1,"CONTAINS");
256                           if ( !tmp ) tmp =  strstr(motparse1,"Contains");
257                           if (  tmp )
258                           {
259                              if ( strlen(motparse1) == strlen(tmp)+1 )
260                              {
261                                 return TOK_CONTAINS;
262                              }
263                              else
264                              {
265                                 colnum=0;line_num_fortran++;line_num_fortran_common++;
266                              }
267                           }
268                           else
269                           {
270                              colnum=0;line_num_fortran++;line_num_fortran_common++;                           
271                           }
272                         }
273{COMMENTAIRESFORTRAN90}   {
274                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
275                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
276                          }
277{COMMENTAIRESFORTRAN90_2} {
278                             if ( !strcasecmp(motparse1,"!$AGRIF_DO_NOT_TREAT\n")) return TOK_DONOTTREAT;
279                             if ( !strcasecmp(motparse1,"!$AGRIF_END_DO_NOT_TREAT\n")) return TOK_ENDDONOTTREAT;
280                          }
281%%
282
283fortranerror(char *s)
284{
285   if (!strcasecmp(curfile,mainfile))
286   {
287      printf("%s line %d, fichier %s\n",s,line_num_fortran,curfile);
288   }
289   else
290   {
291      printf("%s line %d, fichier %s\n",s,line_num_fortran_common,curfile);
292   }
293}
294
295int fortranwrap()
296{
297}
Note: See TracBrowser for help on using the repository browser.