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 | %option warn |
---|
36 | %option noyywrap |
---|
37 | |
---|
38 | %x parameter |
---|
39 | %s character |
---|
40 | %x donottreat |
---|
41 | %s fortran77style |
---|
42 | %s fortran90style |
---|
43 | %{ |
---|
44 | #include <math.h> |
---|
45 | #include <stdlib.h> |
---|
46 | #include <string.h> |
---|
47 | extern FILE * yyin; |
---|
48 | #define MAX_INCLUDE_DEPTH 30 |
---|
49 | YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; |
---|
50 | int line_num_input = 1; |
---|
51 | int newlinef90 = 0; |
---|
52 | char tmpc; |
---|
53 | #define PRINT_LINE_NUM() // { fprintf(stderr,"== Parsing l.%4d...\n", line_num_input); } |
---|
54 | #define INCREMENT_LINE_NUM() { line_num_input++; PRINT_LINE_NUM(); } |
---|
55 | |
---|
56 | /******************************************************************************/ |
---|
57 | /**************PETITS PB NON PREVUS *******************************************/ |
---|
58 | /******************************************************************************/ |
---|
59 | /* NEXTLINF77 un ligne fortran 77 peut commencer par - &a=b or on */ |
---|
60 | /* a prevu seulement & a=b avec l'espace entre le symbole */ |
---|
61 | /* de la 7eme et le debut de la ligne de commande */ |
---|
62 | /* le ! est aussi interdit comme symbole de la 7 eme colonne */ |
---|
63 | /* Normalement NEXTLINEF77 \n+[ ]{5}[^ ] */ |
---|
64 | /******************************************************************************/ |
---|
65 | #define YY_USER_ACTION if (firstpass == 0) ECHO; |
---|
66 | |
---|
67 | void out_of_donottreat(void); |
---|
68 | |
---|
69 | %} |
---|
70 | |
---|
71 | REAL8 "real*8"[ \t]*"(a-h,o-z)" |
---|
72 | |
---|
73 | SLASH "/" |
---|
74 | DSLASH "/"[ \t]*"/" |
---|
75 | HEXA Z\'[0-9a-fA-F]+\' |
---|
76 | NAME [a-zA-Z\_][a-zA-Z0-9\_]* |
---|
77 | INTEGER [0-9]+ |
---|
78 | |
---|
79 | EXPONENT [edq][-+]?{INTEGER} |
---|
80 | |
---|
81 | BEG_DNT ^[C!]"$AGRIF_DO_NOT_TREAT"[ \t]*\n |
---|
82 | END_DNT ^[C!]"$AGRIF_END_DO_NOT_TREAT"[ \t]*\n |
---|
83 | |
---|
84 | BEG_INTERFACE ^[ \t]*interface |
---|
85 | END_INTERFACE ^[ \t]*end[ \t]*interface.*\n |
---|
86 | |
---|
87 | ASSIGNTYPE "assignment"[ \t]*"("[ \t]*[-+=]+[ \t]*")" |
---|
88 | |
---|
89 | COMM_F77 ^([Cc*](([ \t]*\n)|([^AaHhOo\n].*\n))) |
---|
90 | COMM_F90 ^[ \t]*!.*\n |
---|
91 | COMM_F90_2 !.* |
---|
92 | NEXTLINEF90 "&".*\n+ |
---|
93 | NEXTLINEF77 [\n \t]*\n[ \t]{5}("&"|"+"|"$"|"*"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"."|"#") |
---|
94 | |
---|
95 | LABEL ^(((" "|[0-9]){1,5})|([ \t]{1,5}))[ &]+ |
---|
96 | |
---|
97 | %% |
---|
98 | if (infixed) BEGIN(fortran77style) ; |
---|
99 | if (infree) BEGIN(fortran90style) ; |
---|
100 | |
---|
101 | {REAL8} { return TOK_REAL8; } |
---|
102 | subroutine { return TOK_SUBROUTINE; } |
---|
103 | program { return TOK_PROGRAM; } |
---|
104 | allocate { inallocate = 1; return TOK_ALLOCATE; } |
---|
105 | nullify { return TOK_NULLIFY; } |
---|
106 | null[ ]*\([ ]*\) { return TOK_NULL_PTR; } |
---|
107 | deallocate { inallocate = 1; return TOK_DEALLOCATE; } |
---|
108 | result { return TOK_RESULT; } |
---|
109 | function { return TOK_FUNCTION; } |
---|
110 | end[ \t]*program { strcpy(yylval.na,fortran_text); return TOK_ENDPROGRAM;} |
---|
111 | end[ \t]*module { strcpy(yylval.na,fortran_text); return TOK_ENDMODULE; } |
---|
112 | end[ \t]*subroutine { strcpy(yylval.na,fortran_text); return TOK_ENDSUBROUTINE;} |
---|
113 | end[ \t]*function { strcpy(yylval.na,fortran_text); return TOK_ENDFUNCTION;} |
---|
114 | end { strcpy(yylval.na,fortran_text); return TOK_ENDUNIT;} |
---|
115 | include { pos_curinclude = setposcur()-9; return TOK_INCLUDE;} |
---|
116 | ^[ \t]*use[ ]+ { strcpy(yylval.na,fortran_text); |
---|
117 | tmpc = (char) input(); unput(tmpc); |
---|
118 | if ( ( tmpc >= 'a' && tmpc <= 'z' ) || |
---|
119 | ( tmpc >= 'A' && tmpc <= 'Z' ) ) return TOK_USE; |
---|
120 | else return TOK_NAME; |
---|
121 | } |
---|
122 | rewind { return TOK_REWIND; } |
---|
123 | implicit { return TOK_IMPLICIT; } |
---|
124 | none { return TOK_NONE; } |
---|
125 | call { return TOK_CALL; } |
---|
126 | .true. { return TOK_TRUE; } |
---|
127 | .false. { return TOK_FALSE; } |
---|
128 | \=\> { return TOK_POINT_TO; } |
---|
129 | {ASSIGNTYPE} { strcpy(yylval.na,fortran_text); return TOK_ASSIGNTYPE;} |
---|
130 | \*\* { strcpy(yylval.na,fortran_text); return TOK_DASTER; } |
---|
131 | \.[ \t]*eqv\. { strcpy(yylval.na,fortran_text); return TOK_EQV; } |
---|
132 | \.[ \t]*eq\. { strcpy(yylval.na,fortran_text); return TOK_EQ; } |
---|
133 | \.[ \t]*gt\. { strcpy(yylval.na,fortran_text); return TOK_GT; } |
---|
134 | \.[ \t]*ge\. { strcpy(yylval.na,fortran_text); return TOK_GE; } |
---|
135 | \.[ \t]*lt\. { strcpy(yylval.na,fortran_text); return TOK_LT; } |
---|
136 | \.[ \t]*le\. { strcpy(yylval.na,fortran_text); return TOK_LE; } |
---|
137 | \.[ \t]*neqv\. { strcpy(yylval.na,fortran_text); return TOK_NEQV;} |
---|
138 | \.[ \t]*ne\. { strcpy(yylval.na,fortran_text); return TOK_NE; } |
---|
139 | \.[ \t]*not\. { strcpy(yylval.na,fortran_text); return TOK_NOT; } |
---|
140 | \.[ \t]*or\. { strcpy(yylval.na,fortran_text); return TOK_OR; } |
---|
141 | \.[ \t]*xor\. { strcpy(yylval.na,fortran_text); return TOK_XOR; } |
---|
142 | \.[ \t]*and\. { strcpy(yylval.na,fortran_text); return TOK_AND; } |
---|
143 | module { return TOK_MODULE; } |
---|
144 | while { return TOK_WHILE; } |
---|
145 | concurrent { return TOK_CONCURRENT; } |
---|
146 | end[ \t]*do { return TOK_ENDDO; } |
---|
147 | do { return TOK_PLAINDO;} |
---|
148 | real { strcpy(yylval.na,fortran_text); return TOK_REAL; } |
---|
149 | integer { strcpy(yylval.na,fortran_text); return TOK_INTEGER; } |
---|
150 | logical { strcpy(yylval.na,fortran_text); return TOK_LOGICAL; } |
---|
151 | character { strcpy(yylval.na,fortran_text); return TOK_CHARACTER; } |
---|
152 | {HEXA} { strcpy(yylval.na,fortran_text); return TOK_HEXA;} |
---|
153 | double[ \t]*precision { strcpy(yylval.na,fortran_text); return TOK_DOUBLEPRECISION; } |
---|
154 | double[ \t]*complex { strcpy(yylval.na,fortran_text); return TOK_DOUBLECOMPLEX; } |
---|
155 | complex { return TOK_COMPLEX; } |
---|
156 | allocatable { return TOK_ALLOCATABLE; } |
---|
157 | close { return TOK_CLOSE; } |
---|
158 | inquire { return TOK_INQUIRE; } |
---|
159 | dimension { return TOK_DIMENSION; } |
---|
160 | pause { return TOK_PAUSE; } |
---|
161 | equivalence { return TOK_EQUIVALENCE; } |
---|
162 | stop { return TOK_STOP; } |
---|
163 | where { return TOK_WHERE; } |
---|
164 | end[ \t]*where { return TOK_ENDWHERE; } |
---|
165 | else[ \t]*where[ \t]*\( { return TOK_ELSEWHEREPAR; } |
---|
166 | else[ \t]*where { return TOK_ELSEWHERE; } |
---|
167 | ^[ \t]*contains { return TOK_CONTAINS; } |
---|
168 | only { return TOK_ONLY; } |
---|
169 | parameter { return TOK_PARAMETER; } |
---|
170 | recursive { return TOK_RECURSIVE; } |
---|
171 | common { return TOK_COMMON; } |
---|
172 | ^[ \t]*global[ \t]+ { return TOK_GLOBAL; } |
---|
173 | external { return TOK_EXTERNAL; } |
---|
174 | intent { return TOK_INTENT; } |
---|
175 | pointer { return TOK_POINTER; } |
---|
176 | optional { return TOK_OPTIONAL; } |
---|
177 | save { return TOK_SAVE; } |
---|
178 | ^[ \t]*type[ \t]*\( { pos_cur_decl = setposcur()-5; return TOK_TYPEPAR; } |
---|
179 | ^[ \t]*type[ \t\,]+ { return TOK_TYPE; } |
---|
180 | end[ \t]*type { return TOK_ENDTYPE; } |
---|
181 | stat { if (inallocate == 1) return TOK_STAT; else { strcpy(yylval.na,fortran_text); return TOK_NAME; } } |
---|
182 | open { return TOK_OPEN; } |
---|
183 | return { return TOK_RETURN; } |
---|
184 | exit[^(] { return TOK_EXIT; } |
---|
185 | print { return TOK_PRINT; } |
---|
186 | module[ \t]*procedure { return TOK_PROCEDURE; } |
---|
187 | read { return TOK_READ; } |
---|
188 | namelist { return TOK_NAMELIST; } |
---|
189 | write { return TOK_WRITE; } |
---|
190 | flush { return TOK_FLUSH; } |
---|
191 | target { return TOK_TARGET; } |
---|
192 | public { return TOK_PUBLIC; } |
---|
193 | private { return TOK_PRIVATE; } |
---|
194 | in { strcpy(yylval.na,fortran_text); return TOK_IN; } |
---|
195 | ^[ \t]*data[ \t]+ { pos_curdata = setposcur()-strlen(fortran_text); Init_List_Data_Var(); return TOK_DATA; } |
---|
196 | continue { return TOK_CONTINUE; } |
---|
197 | go[ \t]*to { return TOK_PLAINGOTO; } |
---|
198 | out { strcpy(yylval.na,fortran_text); return TOK_OUT; } |
---|
199 | inout { strcpy(yylval.na,fortran_text); return TOK_INOUT; } |
---|
200 | intrinsic { return TOK_INTRINSIC; } |
---|
201 | then { return TOK_THEN; } |
---|
202 | else[ \t]*if { return TOK_ELSEIF; } |
---|
203 | else { return TOK_ELSE; } |
---|
204 | end[ \t]*if { return TOK_ENDIF; } |
---|
205 | if { return TOK_LOGICALIF; } |
---|
206 | sum[ \t]*\( { return TOK_SUM; } |
---|
207 | max[ \t]*\( { return TOK_MAX; } |
---|
208 | tanh { return TOK_TANH; } |
---|
209 | maxval { return TOK_MAXVAL; } |
---|
210 | trim { return TOK_TRIM; } |
---|
211 | sqrt\( { return TOK_SQRT; } |
---|
212 | select[ \t]*case { return TOK_SELECTCASE; } |
---|
213 | ^[ \t]*case[ \t]* { return TOK_CASE; } |
---|
214 | default { return TOK_DEFAULT; } |
---|
215 | end[ \t]*select { return TOK_ENDSELECT; } |
---|
216 | file[ \t]*\= { return TOK_FILE; } |
---|
217 | unit[ \t]*\= { return TOK_UNIT; } |
---|
218 | fmt[ \t]*\= { return TOK_FMT; } |
---|
219 | nml[ \t]*\= { return TOK_NML; } |
---|
220 | end[ \t]*\= { return TOK_END; } |
---|
221 | eor[ \t]*\= { return TOK_EOR; } |
---|
222 | err[ \t]*\= { return TOK_ERR; } |
---|
223 | exist[ \t]*\= { return TOK_EXIST; } |
---|
224 | min[ \t]*\( { return TOK_MIN; } |
---|
225 | nint { return TOK_NINT; } |
---|
226 | float { return TOK_FLOAT; } |
---|
227 | exp { return TOK_EXP; } |
---|
228 | cos { return TOK_COS; } |
---|
229 | cosh { return TOK_COSH; } |
---|
230 | acos { return TOK_ACOS; } |
---|
231 | sin { return TOK_SIN; } |
---|
232 | sinh { return TOK_SINH; } |
---|
233 | asin { return TOK_ASIN; } |
---|
234 | log { return TOK_LOG; } |
---|
235 | tan { return TOK_TAN; } |
---|
236 | atan { return TOK_ATAN; } |
---|
237 | cycle { return TOK_CYCLE; } |
---|
238 | abs[ \t]*\( { return TOK_ABS; } |
---|
239 | mod { return TOK_MOD; } |
---|
240 | sign[ \t]*\( { return TOK_SIGN; } |
---|
241 | minloc { return TOK_MINLOC; } |
---|
242 | maxloc { return TOK_MAXLOC; } |
---|
243 | minval { return TOK_MINVAL; } |
---|
244 | backspace { return TOK_BACKSPACE; } |
---|
245 | :: { return TOK_FOURDOTS; } |
---|
246 | \({SLASH} { return TOK_LEFTAB; } |
---|
247 | {SLASH}\) { return TOK_RIGHTAB; } |
---|
248 | format[ \t]*\((.|{NEXTLINEF90}|{NEXTLINEF77})*\) { |
---|
249 | return TOK_FORMAT; } |
---|
250 | {SLASH} { strcpy(yylval.na,fortran_text); return TOK_SLASH; } |
---|
251 | DSLASH { strcpy(yylval.na,fortran_text); return TOK_DSLASH; } |
---|
252 | (\')[^']*&{0,1}\n[ \t]*&{0,1}[^']*(\') { |
---|
253 | strcpy(yylval.na,fortran_text); return TOK_CHAR_CUT; } |
---|
254 | (\')[^']*(\') { strcpy(yylval.na,fortran_text);return TOK_CHAR_CONSTANT; } |
---|
255 | (\")[^"]*(\") { strcpy(yylval.na,fortran_text);return TOK_CHAR_MESSAGE; } |
---|
256 | {BEG_INTERFACE} { BEGIN(donottreat); } |
---|
257 | <donottreat>{END_INTERFACE} { out_of_donottreat(); return '\n'; } |
---|
258 | {NAME} { strcpy(yylval.na,fortran_text); return TOK_NAME; } |
---|
259 | ({INTEGER}\.[0-9]*)/[^"and."|"false."|"true."|"eq."|"or."|"gt."|"ge."|"lt."|"le."|"not."|"ne."] { // REAL1 |
---|
260 | strcpy(yylval.na,fortran_text); return TOK_CSTREAL; } |
---|
261 | (({INTEGER}\.[0-9]+|[0-9]*\.{INTEGER}){EXPONENT}?)|{INTEGER}(\.)?{EXPONENT} { // REAL2 |
---|
262 | strcpy(yylval.na,fortran_text); return TOK_CSTREAL; } |
---|
263 | {INTEGER} { strcpy(yylval.na,fortran_text); return TOK_CSTINT; } |
---|
264 | \$ {} |
---|
265 | \. {} |
---|
266 | \(|\)|:|\[|\]|\+|\-|\* { strcpy(yylval.na,fortran_text); return (int) *fortran_text; } |
---|
267 | \% { strcpy(yylval.na,fortran_text); return (int) *fortran_text; } |
---|
268 | \; { return TOK_SEMICOLON; } |
---|
269 | \, { return (int) *fortran_text; } |
---|
270 | \= { return (int) *fortran_text; } |
---|
271 | \< { return (int) *fortran_text; } |
---|
272 | \> { return (int) *fortran_text; } |
---|
273 | \n { INCREMENT_LINE_NUM() ; return '\n'; } |
---|
274 | ^[ ]*$ {} |
---|
275 | [ \t]+ {} |
---|
276 | {LABEL} { if (newlinef90 == 0) return TOK_LABEL; else newlinef90 = 0; } |
---|
277 | {NEXTLINEF90} { INCREMENT_LINE_NUM() ; newlinef90=1; } |
---|
278 | {NEXTLINEF77} { INCREMENT_LINE_NUM() ; } |
---|
279 | |
---|
280 | {BEG_DNT} { INCREMENT_LINE_NUM() ; BEGIN(donottreat); } |
---|
281 | <donottreat>{END_DNT} { out_of_donottreat(); return '\n'; } |
---|
282 | <donottreat>.*\n { INCREMENT_LINE_NUM() ; } |
---|
283 | <fortran77style>{COMM_F77} { INCREMENT_LINE_NUM() ; } |
---|
284 | {COMM_F90} { INCREMENT_LINE_NUM() ; } |
---|
285 | {COMM_F90_2} {} |
---|
286 | %% |
---|
287 | |
---|
288 | void out_of_donottreat ( void ) |
---|
289 | { |
---|
290 | BEGIN(INITIAL); |
---|
291 | if (infixed) BEGIN(fortran77style) ; |
---|
292 | if (infree) BEGIN(fortran90style) ; |
---|
293 | INCREMENT_LINE_NUM() ; |
---|
294 | } |
---|