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