[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> |
---|
| 42 | extern FILE * yyin; |
---|
| 43 | #define MAX_INCLUDE_DEPTH 30 |
---|
| 44 | #define tabsize 6 |
---|
| 45 | YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; |
---|
| 46 | int line_num_fortran=1; |
---|
| 47 | int line_num_fortran_common=1; |
---|
| 48 | int newlinef90 = 0; |
---|
| 49 | char *tmp; |
---|
[530] | 50 | char 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 | %} |
---|
| 76 | AGRIFDEB "Agrif_debut" |
---|
| 77 | AGRIFFIN "Agrif_fin" |
---|
[530] | 78 | REAL8 "real*8"[ \t]*"(a-h,o-z)" |
---|
[396] | 79 | NOTTREAT Agrif_do_not_treat |
---|
| 80 | ENDNOTTREAT Agrif_end_do_not_treat |
---|
| 81 | |
---|
| 82 | NIMPORTEQUOI . |
---|
| 83 | SLASH "/" |
---|
| 84 | DSLASH "/"[ \t]*"/" |
---|
| 85 | NAME [a-zA-Z\_][a-zA-Z0-9\_]* |
---|
| 86 | DIGIT [0-9]+ |
---|
| 87 | INT {DIGIT} |
---|
| 88 | EXPONENT e[-+]?{DIGIT} |
---|
| 89 | DEXPONENT d[-+]?{DIGIT} |
---|
| 90 | QEXPONENT q[-+]?{DIGIT} |
---|
| 91 | REAL (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){EXPONENT}?)|{DIGIT}\.{EXPONENT} |
---|
| 92 | REALDP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){DEXPONENT}?)|{DIGIT}\.{DEXPONENT} |
---|
| 93 | REALQP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){QEXPONENT}?)|{DIGIT}\.{QEXPONENT} |
---|
| 94 | ENDFUNCTION end[ \t]*function |
---|
| 95 | DOUBLEPRECISION double[ \t]*precision |
---|
| 96 | DOUBLECOMPLEX double[ \t]*complex |
---|
| 97 | |
---|
[530] | 98 | COMMENTAIRESFORTRAN77 ^([Cc*](([ \t]*\n)|([^AaHhOo\n]{NIMPORTEQUOI}*\n))) |
---|
[396] | 99 | COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n) |
---|
| 100 | COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*) |
---|
| 101 | NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]* |
---|
[663] | 102 | NEXTLINEF77 \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] | 111 | subroutine {return TOK_SUBROUTINE;} |
---|
| 112 | program {return TOK_PROGRAM;} |
---|
| 113 | allocate {return TOK_ALLOCATE;} |
---|
| 114 | deallocate {return TOK_DEALLOCATE;} |
---|
| 115 | result {return TOK_RESULT;} |
---|
| 116 | function {return TOK_FUNCTION;} |
---|
| 117 | end[ \t]*subroutine {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;} |
---|
| 118 | end[ \t]*program {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;} |
---|
| 119 | end[ \t]*function {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;} |
---|
| 120 | end {strcpy(yylval.na,yytext);return TOK_ENDUNIT;} |
---|
| 121 | include 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] | 139 | rewind {return TOK_REWIND;} |
---|
| 140 | implicit return TOK_IMPLICIT; |
---|
| 141 | none return TOK_NONE; |
---|
| 142 | call 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;} |
---|
| 157 | module {return TOK_MODULE;} |
---|
[663] | 158 | do[ 0-9\t]*while {return TOK_DOWHILE;} |
---|
[396] | 159 | end[ \t]*module return TOK_ENDMODULE; |
---|
| 160 | end[ \t]*do return TOK_ENDDO; |
---|
| 161 | do {return TOK_PLAINDO;} |
---|
| 162 | real {strcpy(yylval.na,yytext);return TOK_REAL;} |
---|
| 163 | integer {strcpy(yylval.na,yytext);return TOK_INTEGER;} |
---|
| 164 | logical {strcpy(yylval.na,yytext);return TOK_LOGICAL;} |
---|
| 165 | character {strcpy(yylval.na,yytext);return TOK_CHARACTER;} |
---|
| 166 | allocatable {return TOK_ALLOCATABLE;} |
---|
| 167 | close return TOK_CLOSE; |
---|
| 168 | inquire return TOK_INQUIRE; |
---|
| 169 | dimension {return TOK_DIMENSION;} |
---|
| 170 | pause return TOK_PAUSE; |
---|
| 171 | equivalence return TOK_EQUIVALENCE; |
---|
| 172 | stop return TOK_STOP; |
---|
| 173 | where return TOK_WHERE; |
---|
| 174 | end[ \t]*where return TOK_ENDWHERE; |
---|
| 175 | else[ \t]*where return TOK_ELSEWHERE; |
---|
| 176 | complex {return TOK_COMPLEX;} |
---|
| 177 | ^[ \t]*contains {return TOK_CONTAINS;} |
---|
| 178 | only {return TOK_ONLY;} |
---|
| 179 | parameter {return TOK_PARAMETER;} |
---|
[663] | 180 | recursive {return TOK_RECURSIVE;} |
---|
[396] | 181 | common {return TOK_COMMON;} |
---|
[663] | 182 | ^[ \t]*global[ \t]+ {return TOK_GLOBAL;} |
---|
[396] | 183 | external {return TOK_EXTERNAL;} |
---|
| 184 | intent {return TOK_INTENT;} |
---|
| 185 | pointer {return TOK_POINTER;} |
---|
| 186 | optional {return TOK_OPTIONAL;} |
---|
| 187 | save {return TOK_SAVE;} |
---|
[663] | 188 | ^[ \t]*type[ \t\,]+ {return TOK_TYPE;} |
---|
| 189 | ^[ \t]*type[ \t]*\( {return TOK_TYPEPAR;} |
---|
| 190 | stat {return TOK_STAT;} |
---|
[396] | 191 | end[ \t]*type {return TOK_ENDTYPE;} |
---|
| 192 | open return TOK_OPEN; |
---|
| 193 | return return TOK_RETURN; |
---|
[530] | 194 | exit[^(] return TOK_EXIT; |
---|
[396] | 195 | print return TOK_PRINT; |
---|
| 196 | module[ \t]*procedure {return TOK_PROCEDURE;} |
---|
| 197 | read {return TOK_READ;} |
---|
| 198 | namelist {return TOK_NAMELIST;} |
---|
| 199 | write {return TOK_WRITE;} |
---|
| 200 | target {return TOK_TARGET;} |
---|
| 201 | public {return TOK_PUBLIC;} |
---|
| 202 | private {return TOK_PRIVATE;} |
---|
[774] | 203 | in {strcpy(yylval.nac,yytext);return TOK_IN;} |
---|
[663] | 204 | ^[ \t]*data[ \t]+ {strcpy(yylval.na,yytext);return TOK_DATA;} |
---|
[396] | 205 | continue return TOK_CONTINUE; |
---|
| 206 | go[ \t]*to {return TOK_PLAINGOTO;} |
---|
[774] | 207 | out {strcpy(yylval.nac,yytext);return TOK_OUT;} |
---|
| 208 | inout {strcpy(yylval.nac,yytext);return TOK_INOUT;} |
---|
[396] | 209 | intrinsic {return TOK_INTRINSIC;} |
---|
| 210 | then {return TOK_THEN;} |
---|
| 211 | else[ \t]*if {return TOK_ELSEIF;} |
---|
| 212 | else {return TOK_ELSE;} |
---|
| 213 | end[ \t]*if {return TOK_ENDIF;} |
---|
[530] | 214 | if[ \t]*\( {return TOK_LOGICALIF;} |
---|
| 215 | sum[ \t]*\( {return TOK_SUM;} |
---|
| 216 | max[ \t]*\( {return TOK_MAX;} |
---|
[396] | 217 | tanh {return TOK_TANH;} |
---|
| 218 | maxval {return TOK_MAXVAL;} |
---|
| 219 | trim {return TOK_TRIM;} |
---|
[530] | 220 | sqrt\( {return TOK_SQRT;} |
---|
[396] | 221 | select[ \t]*case {return TOK_SELECTCASE;} |
---|
[663] | 222 | ^[ \t]*case[ \t]*\( {return TOK_CASE;} |
---|
| 223 | ^[ \t]*case[ \t]*default {return TOK_CASEDEFAULT;} |
---|
[396] | 224 | end[ \t]*select {return TOK_ENDSELECT;} |
---|
| 225 | file[ \t]*\= {return TOK_FILE;} |
---|
[663] | 226 | end[ \t]*\= {return TOK_END;} |
---|
| 227 | err[ \t]*\= {return TOK_ERR;} |
---|
[396] | 228 | exist[ \t]*\= {return TOK_EXIST;} |
---|
| 229 | min[ \t]*\( {return TOK_MIN;} |
---|
| 230 | int {return TOK_INT;} |
---|
| 231 | nint {return TOK_NINT;} |
---|
| 232 | float {return TOK_FLOAT;} |
---|
| 233 | exp {return TOK_EXP;} |
---|
| 234 | cos {return TOK_COS;} |
---|
| 235 | cosh {return TOK_COSH;} |
---|
| 236 | acos {return TOK_ACOS;} |
---|
| 237 | sin {return TOK_SIN;} |
---|
| 238 | sinh {return TOK_SINH;} |
---|
| 239 | asin {return TOK_ASIN;} |
---|
| 240 | log {return TOK_LOG;} |
---|
| 241 | tan {return TOK_TAN;} |
---|
| 242 | atan {return TOK_ATAN;} |
---|
[530] | 243 | cycle {return TOK_CYCLE;} |
---|
[663] | 244 | abs\( {return TOK_ABS;} |
---|
[396] | 245 | mod {return TOK_MOD;} |
---|
| 246 | sign {return TOK_SIGN;} |
---|
| 247 | minloc {return TOK_MINLOC;} |
---|
| 248 | maxloc {return TOK_MAXLOC;} |
---|
| 249 | minval {return TOK_MINVAL;} |
---|
| 250 | interface {return TOK_INTERFACE;} |
---|
[530] | 251 | backspace {return TOK_BACKSPACE;} |
---|
[396] | 252 | end[ \t]*interface {return TOK_ENDINTERFACE;} |
---|
| 253 | \({SLASH} {return TOK_LEFTAB;} |
---|
| 254 | {SLASH}\) {return TOK_RIGHTAB;} |
---|
[663] | 255 | format[ \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;} |
---|
| 259 | DSLASH {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 | |
---|
| 315 | fortranerror(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 | |
---|
| 327 | int fortranwrap() |
---|
| 328 | { |
---|
| 329 | } |
---|