/[MITgcm]/mitgcm.org/devel/buildweb/code-browser/F90Mapper/F90sym.lex
ViewVC logotype

Contents of /mitgcm.org/devel/buildweb/code-browser/F90Mapper/F90sym.lex

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Fri Sep 20 19:47:31 2002 UTC (22 years, 9 months ago) by adcroft
Branch: Import, MAIN
CVS Tags: baseline, HEAD
Changes since 1.1: +0 -0 lines
Importing web-site building process.

1 /* $Id: F90sym.lex,v 1.1 1997/03/23 05:52:43 cnh Exp cnh $ */
2 /* Lex analyser to produce a list of names */
3 /* from a fixed form Fortran 90 program. */
4 /* Rules assume that *NO* Fortran 90 */
5 /* keywords that the rules identify are */
6 /* used as variable names. */
7 %p 100000
8 %a 100000
9 %o 100000
10 %n 100000
11 %k 100000
12 %e 100000
13 %s LOADLINE
14 %option noyywrap
15
16 /* Line and character no. counter */
17 int Lno=1;int Cno=1;
18 NAME [_a-zA-Z]+[_a-zA-Z0-9]*
19 INT [0-9]*
20 EXPO ([EeDd][+-]?{INT})
21 FLOAT ([0-9]+\.|\.[0-9]+|[0-9]+\.[0-9]+){EXPO}?
22 CONT ^[ ][ ][ ][ ][ ][^ \n].*
23 LAB ^[1-9]....*
24 /* Those wretched case insensitive keywords */
25 A [aA]
26 B [bB]
27 C [cC]
28 D [dD]
29 E [eE]
30 F [fF]
31 G [gG]
32 H [hH]
33 I [iI]
34 J [jJ]
35 K [kK]
36 L [lL]
37 M [mM]
38 N [nN]
39 O [oO]
40 P [pP]
41 Q [qQ]
42 R [rR]
43 S [sS]
44 T [tT]
45 U [uU]
46 V [vV]
47 W [wW]
48 X [xX]
49 Y [yY]
50 Z [zZ]
51
52 %{
53 #include "string.h"
54 #include "stdio.h"
55 #include "F90sym.tab.h" /* Tokens for yacc return values */
56 #include "GLOBALS.h"
57 int call1yylex = 0;
58 %}
59
60 %%
61 if ( call1yylex == 0 ) {
62 BEGIN(LOADLINE);
63 call1yylex = 1;
64 }
65
66 ^[CcDd].* {Cno=Cno+F90symleng; /* 'C' or 'D' in column 1 F77 style comment */
67 strcat(currentLineHtml,"<I>"); /* echo italicised to HTML buffer */
68 strcat(currentLineHtml,F90symtext);
69 strcat(currentLineHtml,"</I>");
70 return(OTHER);}
71
72 ^[\*].* {Cno=Cno+F90symleng; /* '*' in column 1 */
73 strcat(currentLineHtml,F90symtext);
74 return(OTHER);}
75
76 '[^']*' {Cno=Cno+F90symleng; /* String in ' quotes */
77 strcat(currentLineHtml,F90symtext);
78 return(OTHER);}
79
80 \"[^\"]*\" {Cno=Cno+F90symleng; /* String in " quotes */
81 strcat(currentLineHtml,F90symtext);
82 return(OTHER);}
83
84 !.* {Cno=Cno+F90symleng; /* Inline quote */
85 strcat(currentLineHtml,F90symtext);
86 return(OTHER);}
87
88 \/\*.* {Cno=Cno+F90symleng; /* Inline quote ( C-style ) */
89 strcat(currentLineHtml,F90symtext);
90 return(OTHER);}
91
92 ^[ \t]* {Cno=Cno+F90symleng; /* Blank line */
93 strcat(currentLineHtml,F90symtext);
94 return(OTHER);}
95
96 {LAB} {Cno=Cno+F90symleng; /* Col 1-5 label */
97 currentLineText[0]=(char)NULL; /* Note the trick here: */
98 sprintf(currentLineHtml,"<A NAME=%d_L></A>",Lno);
99 strncat(currentLineHtml,F90symtext,5); /* We have to match a whole line because otherwise */
100 strncat(currentLineText,F90symtext,5); /* we loose our left context ^ to LOADLINE. We then */
101 yyless(5);return(OTHER);} /* put back all but the first n chars after setting */
102 /* currentLineText. */
103 /* I think the proper way to do this is via */
104 /* a left context of <INITIAL>. This is working for */
105 /* #ifdef. Haven't tried it for LAB and CONT yet. */
106
107 {CONT} {Cno=Cno+F90symleng; /* Col 6 non-blank continuation */
108 currentLineText[0]=(char)NULL; /* Need to use same trick as col 1-5 label */
109 sprintf(currentLineHtml,"<A NAME=%d_L></A>",Lno);
110 strncat(currentLineText,F90symtext,6);
111 strncat(currentLineHtml,F90symtext,6);
112 yyless(6);}
113
114 <INITIAL>#ifdef | /* ifdef CPP statement */
115 <INITIAL>#[ ]*ifdef {Cno=Cno+F90symleng;
116 F90symlval.LineNo=Lno;
117 strcat(currentLineHtml,F90symtext);
118 return(CPP_IFDEF);}
119 <INITIAL>#undef | /* undef CPP statement */
120 <INITIAL>#[ ]*undef {Cno=Cno+F90symleng;
121 F90symlval.LineNo=Lno;
122 strcat(currentLineHtml,F90symtext);
123 return(CPP_UNDEF);}
124 <INITIAL>#define | /* define CPP statement */
125 <INITIAL>#[ ]*define {Cno=Cno+F90symleng;
126 F90symlval.LineNo=Lno;
127 strcat(currentLineHtml,F90symtext);
128 return(CPP_DEFINE);}
129 <INITIAL>#elif | /* elif CPP statement */
130 <INITIAL>#[ ]*elif {Cno=Cno+F90symleng;
131 F90symlval.LineNo=Lno;
132 strcat(currentLineHtml,F90symtext);
133 return(CPP_ELIF);}
134 <INITIAL>#if | /* if CPP statement */
135 <INITIAL>#[ ]*if {Cno=Cno+F90symleng;
136 F90symlval.LineNo=Lno;
137 strcat(currentLineHtml,F90symtext);
138 return(CPP_IF );}
139 <INITIAL>#ifndef | /* ifndef CPP statement */
140 <INITIAL>#[ ]*ifndef {Cno=Cno+F90symleng;
141 F90symlval.LineNo=Lno;
142 strcat(currentLineHtml,F90symtext);
143 return(CPP_IFNDEF);}
144
145 {INT} {Cno=Cno+F90symleng; /* Integer */
146 strcat(currentLineHtml,F90symtext);
147 return(OTHER);}
148
149 {FLOAT} {Cno=Cno+F90symleng; /* Floating point number */
150 strcat(currentLineHtml,F90symtext);
151 return(OTHER);}
152
153 ^#ifndef.* | /* C preprocessor controls */
154 ^#[ ]*endif.* |
155 ^#undef.* |
156 ^#define.* |
157 ^#elif |
158 ^#if |
159 ^#[ ]*include.* |
160 ^#else.* {Cno=Cno+F90symleng;
161 strcat(currentLineHtml,F90symtext);
162 return(OTHER);}
163
164 [ \t\r] {Cno=Cno+F90symleng; /* Blank space */
165 strcat(currentLineHtml,F90symtext);}
166
167 \( {Cno=Cno+F90symleng; /* ( bracket */
168 strcat(currentLineHtml,"<FONT SIZE=5><B>"); /* echo bold to HTML buffer */
169 strcat(currentLineHtml,F90symtext);
170 strcat(currentLineHtml,"</FONT></B>");
171 return(OTHER);}
172
173 \) {Cno=Cno+F90symleng; /* ) bracket */
174 strcat(currentLineHtml,"<FONT SIZE=5><B>"); /* echo bold to HTML buffer */
175 strcat(currentLineHtml,F90symtext);
176 strcat(currentLineHtml,"</FONT></B>");
177 return(OTHER);}
178
179 \, | /* Various punctutation symbols or operators */
180 \. | /* which are just echoed to the HTML buffer. */
181 \: |
182 \= |
183 \+ |
184 \- |
185 \* {Cno=Cno+F90symleng;
186 strcat(currentLineHtml,F90symtext);
187 return(OTHER);}
188 \/ {Cno=Cno+F90symleng;
189 strcat(currentLineHtml,F90symtext);
190 return(FSLASH);}
191
192 {A}{B}{S} | /* Language keywords which are just echoed to */
193 {A}{L}{L} | /* HTML buffer. ( Alphabetical order ) */
194 {A}{N}{D} |
195 {A}{N}{Y} |
196 {C}{H}{A}{R}{A}{C}{T}{E}{R} |
197 {C}{L}{O}{S}{E} |
198 {C}{O}{N}{T}{I}{N}{U}{E} |
199 {C}{O}{S} |
200 {C}{O}{U}{N}{T} |
201 {C}{S}{H}{I}{F}{T} |
202 {D}{A}{T}{A} |
203 {D}{I}{M} |
204 {E}{N}{D}{W}{H}{E}{R}{E} |
205 {E}{Q} |
206 {F}{A}{L}{S}{E} |
207 {F}{I}{L}{E} |
208 {F}{L}{O}{A}{T} |
209 {F}{M}{T} |
210 {F}{O}{R}{A}{L}{L} |
211 {F}{O}{R}{M}{A}{T}.* |
212 {F}{U}{N}{C}{T}{I}{O}{N} |
213 {G}{E} |
214 {G}{O}{T}{O} |
215 [ ]*\.{G}{T}[ ]*\. | /* Unfortunately we chose to call a variable gT! */
216 {I}{M}{P}{L}{I}{C}{I}{T} |
217 {I}{N}{C}{L}{U}{D}{E} |
218 {I}{N}{D}{E}{X} |
219 {I}{N}{T} |
220 {I}{N}{T}{E}{G}{E}{R} |
221 {I}{O}{S}{T}{A}{T} |
222 {L}{E} |
223 {L}{E}{N} |
224 {L}{O}{G}{I}{C}{A}{L} |
225 {L}{T} |
226 {M}{A}{S}{K} |
227 {M}{A}{X} |
228 {M}{A}{X}{V}{A}{L} |
229 {M}{I}{N} |
230 {M}{I}{N}{V}{A}{L} |
231 {M}{O}{D} |
232 {N}{E} |
233 {N}{I}{N}{T} |
234 {N}{O}{N}{E} |
235 {N}{O}{T} |
236 {O}{P}{E}{N} |
237 {O}{R} |
238 {P}{A}{R}{A}{M}{E}{T}{E}{R} |
239 {P}{R}{I}{N}{T} |
240 {P}{R}{O}{G}{R}{A}{M} |
241 {R}{E}{A}{D} |
242 {R}{E}{A}{L} |
243 {R}{E}{T}{U}{R}{N} |
244 {R}{E}{W}{I}{N}{D} |
245 {S}{A}{V}{E} |
246 {S}{H}{I}{F}{T} |
247 {S}{I}{N} |
248 {S}{Q}{R}{T} |
249 {S}{T}{A}{T}{U}{S} |
250 {S}{T}{O}{P} |
251 {S}{U}{M} |
252 {T}{A}{N} |
253 {T}{H}{E}{N} |
254 {T}{R}{U}{E} |
255 {U}{N}{I}{T} |
256 {W}{R}{I}{T}{E} {Cno=Cno+F90symleng;
257 strcat(currentLineHtml,F90symtext);
258 return(OTHER);}
259
260 {D}{O} | /* Language keywords which are just echoed BOLD */
261 {E}{L}{S}{E} | /* to HTML buffer. ( Alphabetical order ) */
262 {E}{L}{S}{E}{I}{F} |
263 {E}{L}{S}{E}{W}{H}{E}{R}{E} |
264 {E}{N}{D}{D}{O} |
265 {E}{N}{D}{I}{F} |
266 {I}{F} |
267 {W}{H}{E}{R}{E} {Cno=Cno+F90symleng;
268 strcat(currentLineHtml,"<B>");
269 strcat(currentLineHtml,F90symtext);
270 strcat(currentLineHtml,"</B>");
271 return(OTHER);}
272
273 {E}{N}{D}= {Cno=Cno+F90symleng; /* END= in I/O statement */
274 strcat(currentLineHtml,"<B>");
275 strcat(currentLineHtml,F90symtext);
276 strcat(currentLineHtml,"</B>");
277 return(OTHER);}
278 {C}{A}{L}{L} {Cno=Cno+F90symleng; /* CALL returns "CALL" token to parser */
279 F90symlval.LineNo=Lno;
280 strcat(currentLineHtml,"<U><B>");
281 strcat(currentLineHtml,F90symtext);
282 strcat(currentLineHtml,"</B></U>");
283 return(CALL);}
284 {E}{N}{D} {Cno=Cno+F90symleng; /* END causes horizontal line to be */
285 strcat(currentLineHtml,F90symtext); /* to HTML buffer. */
286 strcat(currentLineHtml,"<HR>"); /* Exclude END= because we don't want */
287 strcat(currentLineHtml,"<HR>"); /* to match END= clauses in I/O statements */
288 strcat(currentLineHtml,"<HR>");
289 return(OTHER);}
290 {E}{X}{T}{E}{R}{N}{A}{L} {Cno=Cno+F90symleng; /* EXTERNAL returns "EXTERNAL" token to*/
291 F90symlval.LineNo=Lno; /* parser. */
292 strcat(currentLineHtml,F90symtext);
293 return(EXTERNAL);}
294 {S}{U}{B}{R}{O}{U}{T}{I}{N}{E} {Cno=Cno+F90symleng; /* Write SUBROUTINE to HTML buffer bold*/
295 F90symlval.LineNo=Lno; /* and with large font */
296 strcat(currentLineHtml,"<FONT SIZE=8><B>");
297 strcat(currentLineHtml,F90symtext);
298 strcat(currentLineHtml,"</FONT></B>");
299 return(SUBROUTINE);} /* Return "SUBROUTINE" token to parser */
300 {N}{A}{M}{E}{L}{I}{S}{T} {Cno=Cno+F90symleng;
301 strcat(currentLineHtml,F90symtext);
302 return(NAMELIST);}
303
304 {NAME} {Cno=Cno+F90symleng; /* At last! A variable name. This is */
305 F90symlval.symbolName=strdup(F90symtext); /* written to HTML buffer by the parser */
306 return(NAME);} /* code cos we need to know the HREF */
307
308 <LOADLINE>.* { if ( currentLineText[0] == (char)NULL ||
309 currentLineText[0] == '#' ) /* Special trick to create a */
310 { /* Not a continuation or label */ /* string containing the current */
311 strncpy(currentLineText,F90symtext,currentLineBufSize-1); /* line. */
312 sprintf(currentLineHtml,"<A NAME=%d_L></A>",Lno);
313 newLineNotify();
314 newStatementNotify(); /* Call function to clear context */
315 } /* related to previous statement */
316 else
317 { /* Continuation or label */
318 newLineNotify();
319 strncat(currentLineText,F90symtext,currentLineBufSize-7);
320 }
321 yyless(0);
322 BEGIN(INITIAL);
323 }
324
325 \n\r |
326 \n { /* Newline */
327 F90db_Newline(); /* Write out HTML buffer */
328 BEGIN(LOADLINE);
329 ++Lno;Cno=0;
330 currentLineText[0]=(char)NULL; /* Clear current line buffer */
331 currentLineHtml[0]=(char)NULL;} /* Clear HTML buffer */
332
333 . {printf(" Unclassified symbol \"%s\" @ line %d\n",F90symtext,Lno); /* Something unrecognised */
334 Cno=Cno+F90symleng;} /* This should not happen for */
335 /* legitimate programs. */

  ViewVC Help
Powered by ViewVC 1.1.22