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

Last change on this file since 959 was 774, checked in by rblod, 17 years ago

Update Agrif, see ticket:#39

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