[396] | 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> |
---|
| 23 | extern FILE * yyin; |
---|
| 24 | #define MAX_INCLUDE_DEPTH 30 |
---|
| 25 | #define tabsize 6 |
---|
| 26 | YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; |
---|
| 27 | int line_num_fortran=1; |
---|
| 28 | int line_num_fortran_common=1; |
---|
| 29 | int newlinef90 = 0; |
---|
| 30 | char *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 | %} |
---|
| 55 | AGRIFDEB "Agrif_debut" |
---|
| 56 | AGRIFFIN "Agrif_fin" |
---|
| 57 | NOTTREAT Agrif_do_not_treat |
---|
| 58 | ENDNOTTREAT Agrif_end_do_not_treat |
---|
| 59 | |
---|
| 60 | NIMPORTEQUOI . |
---|
| 61 | SAME_LINE ";" |
---|
| 62 | SLASH "/" |
---|
| 63 | DSLASH "/"[ \t]*"/" |
---|
| 64 | NAME [a-zA-Z\_][a-zA-Z0-9\_]* |
---|
| 65 | DIGIT [0-9]+ |
---|
| 66 | INT {DIGIT} |
---|
| 67 | EXPONENT e[-+]?{DIGIT} |
---|
| 68 | DEXPONENT d[-+]?{DIGIT} |
---|
| 69 | QEXPONENT q[-+]?{DIGIT} |
---|
| 70 | REAL (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){EXPONENT}?)|{DIGIT}\.{EXPONENT} |
---|
| 71 | REALDP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){DEXPONENT}?)|{DIGIT}\.{DEXPONENT} |
---|
| 72 | REALQP (({DIGIT}\.[0-9]+|[0-9]*\.{DIGIT}){QEXPONENT}?)|{DIGIT}\.{QEXPONENT} |
---|
| 73 | ENDFUNCTION end[ \t]*function |
---|
| 74 | DOUBLEPRECISION double[ \t]*precision |
---|
| 75 | DOUBLECOMPLEX double[ \t]*complex |
---|
| 76 | |
---|
| 77 | COMMENTAIRESFORTRAN77 (^[Cc]{NIMPORTEQUOI}*) |
---|
| 78 | COMMENTAIRESFORTRAN90 ^([ \t]*!{NIMPORTEQUOI}*\n) |
---|
| 79 | COMMENTAIRESFORTRAN90_2 (!{NIMPORTEQUOI}*) |
---|
| 80 | NEXTLINEF90 "&"{NIMPORTEQUOI}*[\n]* |
---|
| 81 | NEXTLINEF77 \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 | |
---|
| 100 | subroutine {return TOK_SUBROUTINE;} |
---|
| 101 | program {return TOK_PROGRAM;} |
---|
| 102 | allocate {return TOK_ALLOCATE;} |
---|
| 103 | deallocate {return TOK_DEALLOCATE;} |
---|
| 104 | result {return TOK_RESULT;} |
---|
| 105 | function {return TOK_FUNCTION;} |
---|
| 106 | end[ \t]*subroutine {strcpy(yylval.na,yytext);return TOK_ENDSUBROUTINE;} |
---|
| 107 | end[ \t]*program {strcpy(yylval.na,yytext);return TOK_ENDPROGRAM;} |
---|
| 108 | end[ \t]*function {strcpy(yylval.na,yytext);return TOK_ENDFUNCTION;} |
---|
| 109 | end {strcpy(yylval.na,yytext);return TOK_ENDUNIT;} |
---|
| 110 | include return TOK_INCLUDE; |
---|
| 111 | use {return TOK_USE;} |
---|
| 112 | rewind {return TOK_REWIND;} |
---|
| 113 | implicit return TOK_IMPLICIT; |
---|
| 114 | none return TOK_NONE; |
---|
| 115 | call 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;} |
---|
| 130 | module {return TOK_MODULE;} |
---|
| 131 | do[ \t]*while {return TOK_DOWHILE;} |
---|
| 132 | end[ \t]*module return TOK_ENDMODULE; |
---|
| 133 | end[ \t]*do return TOK_ENDDO; |
---|
| 134 | do {return TOK_PLAINDO;} |
---|
| 135 | real {strcpy(yylval.na,yytext);return TOK_REAL;} |
---|
| 136 | integer {strcpy(yylval.na,yytext);return TOK_INTEGER;} |
---|
| 137 | logical {strcpy(yylval.na,yytext);return TOK_LOGICAL;} |
---|
| 138 | character {strcpy(yylval.na,yytext);return TOK_CHARACTER;} |
---|
| 139 | allocatable {return TOK_ALLOCATABLE;} |
---|
| 140 | close return TOK_CLOSE; |
---|
| 141 | inquire return TOK_INQUIRE; |
---|
| 142 | dimension {return TOK_DIMENSION;} |
---|
| 143 | pause return TOK_PAUSE; |
---|
| 144 | equivalence return TOK_EQUIVALENCE; |
---|
| 145 | stop return TOK_STOP; |
---|
| 146 | where return TOK_WHERE; |
---|
| 147 | end[ \t]*where return TOK_ENDWHERE; |
---|
| 148 | else[ \t]*where return TOK_ELSEWHERE; |
---|
| 149 | complex {return TOK_COMPLEX;} |
---|
| 150 | ^[ \t]*contains {return TOK_CONTAINS;} |
---|
| 151 | only {return TOK_ONLY;} |
---|
| 152 | parameter {return TOK_PARAMETER;} |
---|
| 153 | common {return TOK_COMMON;} |
---|
| 154 | external {return TOK_EXTERNAL;} |
---|
| 155 | intent {return TOK_INTENT;} |
---|
| 156 | kind {return TOK_KIND;} |
---|
| 157 | pointer {return TOK_POINTER;} |
---|
| 158 | optional {return TOK_OPTIONAL;} |
---|
| 159 | save {return TOK_SAVE;} |
---|
| 160 | ^[ \t]*type {return TOK_TYPE;} |
---|
| 161 | end[ \t]*type {return TOK_ENDTYPE;} |
---|
| 162 | open return TOK_OPEN; |
---|
| 163 | return return TOK_RETURN; |
---|
| 164 | exit return TOK_EXIT; |
---|
| 165 | print return TOK_PRINT; |
---|
| 166 | module[ \t]*procedure {return TOK_PROCEDURE;} |
---|
| 167 | read {return TOK_READ;} |
---|
| 168 | namelist {return TOK_NAMELIST;} |
---|
| 169 | write {return TOK_WRITE;} |
---|
| 170 | target {return TOK_TARGET;} |
---|
| 171 | public {return TOK_PUBLIC;} |
---|
| 172 | private {return TOK_PRIVATE;} |
---|
| 173 | in {return TOK_IN;} |
---|
| 174 | data {return TOK_DATA;} |
---|
| 175 | continue return TOK_CONTINUE; |
---|
| 176 | go[ \t]*to {return TOK_PLAINGOTO;} |
---|
| 177 | out {return TOK_OUT;} |
---|
| 178 | inout {return TOK_INOUT;} |
---|
| 179 | intrinsic {return TOK_INTRINSIC;} |
---|
| 180 | then {return TOK_THEN;} |
---|
| 181 | else[ \t]*if {return TOK_ELSEIF;} |
---|
| 182 | else {return TOK_ELSE;} |
---|
| 183 | end[ \t]*if {return TOK_ENDIF;} |
---|
| 184 | if {return TOK_LOGICALIF;} |
---|
| 185 | sum[ \t]*\( {return TOK_SUM;} |
---|
| 186 | max {return TOK_MAX;} |
---|
| 187 | tanh {return TOK_TANH;} |
---|
| 188 | maxval {return TOK_MAXVAL;} |
---|
| 189 | trim {return TOK_TRIM;} |
---|
| 190 | sqrt {return TOK_SQRT;} |
---|
| 191 | select[ \t]*case {return TOK_SELECTCASE;} |
---|
| 192 | case {return TOK_CASE;} |
---|
| 193 | case[ \t]*default {return TOK_CASEDEFAULT;} |
---|
| 194 | end[ \t]*select {return TOK_ENDSELECT;} |
---|
| 195 | file[ \t]*\= {return TOK_FILE;} |
---|
| 196 | exist[ \t]*\= {return TOK_EXIST;} |
---|
| 197 | min[ \t]*\( {return TOK_MIN;} |
---|
| 198 | int {return TOK_INT;} |
---|
| 199 | nint {return TOK_NINT;} |
---|
| 200 | float {return TOK_FLOAT;} |
---|
| 201 | exp {return TOK_EXP;} |
---|
| 202 | cos {return TOK_COS;} |
---|
| 203 | cosh {return TOK_COSH;} |
---|
| 204 | acos {return TOK_ACOS;} |
---|
| 205 | sin {return TOK_SIN;} |
---|
| 206 | sinh {return TOK_SINH;} |
---|
| 207 | asin {return TOK_ASIN;} |
---|
| 208 | log {return TOK_LOG;} |
---|
| 209 | tan {return TOK_TAN;} |
---|
| 210 | atan {return TOK_ATAN;} |
---|
| 211 | abs {return TOK_ABS;} |
---|
| 212 | mod {return TOK_MOD;} |
---|
| 213 | sign {return TOK_SIGN;} |
---|
| 214 | minloc {return TOK_MINLOC;} |
---|
| 215 | maxloc {return TOK_MAXLOC;} |
---|
| 216 | minval {return TOK_MINVAL;} |
---|
| 217 | interface {return TOK_INTERFACE;} |
---|
| 218 | end[ \t]*interface {return TOK_ENDINTERFACE;} |
---|
| 219 | \({SLASH} {return TOK_LEFTAB;} |
---|
| 220 | {SLASH}\) {return TOK_RIGHTAB;} |
---|
| 221 | format {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;} |
---|
| 226 | DSLASH {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 | |
---|
| 283 | fortranerror(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 | |
---|
| 295 | int fortranwrap() |
---|
| 296 | { |
---|
| 297 | } |
---|