]> matita.cs.unibo.it Git - helm.git/blob - helm/metadata/create_V7_mowgli/METADATA/meta_lex_ind.l
bumped version to 0.0.3
[helm.git] / helm / metadata / create_V7_mowgli / METADATA / meta_lex_ind.l
1  /******************************************************************/
2  /*  Copyright (C) 2000, HELM Team                                 */ 
3  /*                                                                */
4  /* This file is part of HELM, an Hypertextual, Electronic         */
5  /* Library of Mathematics, developed at the Computer Science      */
6  /* Department, University of Bologna, Italy.                      */
7  /*                                                                */
8  /* HELM is free software; you can redistribute it and/or          */
9  /* modify it under the terms of the GNU General Public License    */
10  /* as published by the Free Software Foundation; either version   */
11  /* 2 of the License, or (at your option) any later version.       */
12  /*                                                                */
13  /* HELM is distributed in the hope that it will be useful,        */
14  /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15  /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the   */
16  /* GNU General Public License for more details.                   */
17  /*                                                                */
18  /* You should have received a copy of the GNU General Public      */
19  /* License along with HELM; if not, write to the Free Software    */
20  /* Foundation, Inc., 59 Temple Place - Suite 330, Boston,         */
21  /* MA  02111-1307, USA.                                           */
22  /*                                                                */
23  /* For details, see the HELM World-Wide-Web page,                 */
24  /* http://cs.unibo.it/helm/.                                      */
25  /******************************************************************/
26
27  /***************************************************************/
28  /*                        META_LEXAN                           */
29  /*                 Automatic Metadata Extractor                */
30  /*           First draft 11/12/2001, by Andrea Asperti         */
31  /*      more bugs added by domenico lordi on mon 12/17/2001    */
32  /***************************************************************/
33
34  /***************************************************************/
35  /* 1. Inclusion of header files.                               */
36  /***************************************************************/
37
38 %{
39 #include                <string.h>
40 #include                <stdlib.h>
41 #include                "sthandler_ind.h"
42 %}
43
44  /***************************************************************/
45  /* 2. Constants and Variables Definitions                      */
46  /***************************************************************/
47
48 %{
49 #define                 NOWHERE   0
50 #define                 CONST     1
51 #define                 MUTIND    2
52 #define                 MUTCONSTRUCT  3
53
54 #define                 INBODY    0
55 #define                 MAINHYP   1
56 #define                 INHYP     2
57 #define                 INCONCL   3
58 #define                 MAINCONCL 4
59 #define                 INTYPE    5
60 #define                 NOTFOUND  6
61
62 #define                 HERE      0     
63 #define                 AFTER     1
64
65
66 int                     where = NOWHERE;
67 int                     found = NOTFOUND;
68 int                     position = INTYPE;
69 int                     first_child = HERE;
70 int                     skip = 0;     // boolean to skip the insertion of a URI
71 int                     no_open_source =0;
72 int                     tmp_n;
73 int                     inductive_type =0;
74 int                     constructor = 0;
75 int                     deep_type = 0;
76 char                    sep = '"';
77 char                    *xpointer = "#xpointer(1/";
78 char                    *uri;
79 char                    *tmp;
80 char                    *filename;
81 char                    *file_uri; 
82 char                    *inductive_uri;
83 char                    *filename_prefix;
84 char                    *file_uri_prefix;
85
86 %}
87
88 /*%x deeptype*/
89
90
91  /***************************************************************/
92  /* 3. Regular definitions.                                     */
93  /***************************************************************/
94
95 uri                     [^"]+
96 digits                  [0-9]+                   
97
98  /***************************************************************/
99  /* 4. Rules.                                                   */
100  /***************************************************************/
101
102 /*
103 "<type>"           {
104                      BEGIN(deeptype);
105                      deep_type++;
106                    }
107
108 <deeptype>"<type>" {
109                      deep_type++;
110                    }
111
112 <deeptype>"</type>" {
113                      deep_type--;
114                      if (deeptype == 0) BEGIN(0);
115                     }
116
117 <deeptype>.|\n     {
118                    }
119 */
120
121 %%
122
123 "<InductiveType"   { 
124                      fprintf(stderr,"uno");
125                      init_symbol_table();
126                      fprintf(stderr,"due");
127                      inductive_type++;
128                      constructor=0;
129                      position = INTYPE;
130                      first_child = HERE;
131                    }
132
133 "</arity>"         { tmp = (char *)malloc(sizeof('a')*128);
134                      strcpy(filename,filename_prefix);
135                      fprintf(stderr,"tre");
136                      strcpy(file_uri,file_uri_prefix);
137                      sprintf(tmp,",%d.xml", inductive_type);
138                      fprintf(stderr,"quattro");
139                      strcat(filename,tmp);
140                      sprintf(tmp,"#xpointer(1/%d)", inductive_type);
141                      strcat(file_uri,tmp);
142                      fprintf(stderr,"cinque");
143                      free(tmp);
144                      print_file();
145                    }
146
147 "<Constructor"     { init_symbol_table();
148                      constructor++;
149                      strcpy(inductive_uri,file_uri_prefix);
150                      position = INTYPE;
151                      first_child = HERE;
152                    }
153
154 "</Constructor>"   { tmp = (char *)malloc(sizeof('a')*128);
155                      strcpy(filename,filename_prefix);
156                      strcpy(file_uri,file_uri_prefix);
157                      strcpy(inductive_uri,file_uri_prefix);
158                      sprintf(tmp,",%d,%d.xml", inductive_type,constructor);
159                      strcat(filename,tmp);
160                      sprintf(tmp,"#xpointer(1/%d/%d)",inductive_type,constructor);
161                      strcat(file_uri,tmp);
162                      free(tmp);
163                      print_file();
164                    }
165
166 "<decl"            |
167 "<def"             {
168                     if ((position == INTYPE) ||
169                         (position == INHYP))
170                         { position = INHYP;
171                           no_open_source++;};
172                    }
173
174 "</decl>"          |
175 "</def"            {
176                     if (position == INHYP)
177                      {
178                       no_open_source--;
179                       if (no_open_source == 0) 
180                        { position = INTYPE;
181                          first_child = HERE; };
182                      };
183                    }
184
185 .|\n               {
186                    }
187
188 "<LAMBDA"          |
189 "<REL"             |
190 "<MUTCASE"         |
191 "<FIX"             |
192 "<COFIX"           { 
193                           first_child = AFTER;
194                    }
195
196 "<VAR"             {
197                      skip = 1;
198                      first_child = AFTER;
199                    }
200
201 "<CONST"           { 
202                      if (position == INTYPE) /* CONST on the spine */
203                         position = INCONCL;
204                      where = CONST;
205                    }
206
207 "<MUTIND"          { 
208                      if (position == INTYPE) /* MUTIND on the spine */
209                         position = INCONCL;
210                      where = MUTIND;
211                    }
212
213 "<MUTCONSTRUCT"    { 
214                      if (position == INTYPE) /* MUTCONSTRUCT on the spine */
215                         position = INCONCL;
216                      where = MUTCONSTRUCT;
217                    }
218
219 "uri=\""{uri}      {     
220                          if (!skip) {
221                             uri=(char *)malloc((sizeof('a')*200)); 
222                             strcpy(uri,yytext);
223                             strsep(&uri,&sep);
224                             if (where == CONST)
225                                 {
226                                    search(uri,first_child,position); 
227                                    where = NOWHERE;
228                                    first_child = AFTER;
229                                    free(uri); 
230                                  };
231                          } else skip = 0;
232                    } 
233
234 "noType=\""{digits} {
235                          if ((where == MUTIND) || (where == MUTCONSTRUCT))
236                           { strsep(&yytext,&sep);
237                             tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
238                             strcpy(tmp,yytext);
239                             tmp_n = atoi(tmp)+1;
240                             sprintf(tmp,"%d",tmp_n);
241                             strcat(uri,"#xpointer(1/"); 
242                             strcat(uri,tmp); 
243                           };
244                          if (where == MUTIND) 
245                              { 
246                                strcat(uri,")");
247                                search(uri,first_child,position); 
248                                free(uri);
249                                free(tmp);
250                                where = NOWHERE; 
251                                first_child = AFTER;};
252                    } 
253
254 "noConstr=\""{digits} {
255                          if (where == MUTCONSTRUCT)
256                           { strsep(&yytext,&sep);
257                             tmp=(char *)malloc((sizeof(sep)*(strlen(yytext)+1)));
258                             strcpy(tmp,yytext);
259                             strcat(uri,"/");
260                             strcat(uri,tmp);
261                             strcat(uri,")");
262                             search(uri,first_child,position);
263                             free(uri);
264                             free(tmp);
265                             where = NOWHERE; 
266                             first_child = AFTER;};
267                    } 
268
269
270 %%
271
272  /***************************************************************/
273  /* 6. Auxiliary functions.                                     */
274  /***************************************************************/
275
276 main(int argc, char *argv[])
277 {                  
278                    filename = malloc((sizeof('a')*2000));
279                    file_uri = malloc((sizeof('a')*2000));
280                    inductive_uri = malloc((sizeof('a')*2000));
281                    filename_prefix=argv[1];
282                    file_uri_prefix=argv[2];
283                    fprintf(stderr,"qua");
284                    yyin = fopen("tmp/inductive_type.xml", "r");
285                    yylex();
286                    } 
287
288 print_file()
289 {
290                    FILE *out;
291                    if (!(out = fopen(filename,"w"))) 
292                      {
293                       fprintf(stderr, "error in openinf file %s\n", filename);
294                       exit(-1);
295                      }
296                    else
297                      {
298                       fprintf(out,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n\n");
299                       fprintf(out,"<rdf:RDF xml:lang=\"en\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\">\n");
300                       fprintf(out,"\t<h:Object rdf:about=\"");
301                       fprintf(out,"%s",file_uri);
302                       fprintf(out,"\">\n");
303                       print_all(out);
304                       fprintf(out,"\t</h:Object>\n");
305                       fprintf(out,"</rdf:RDF>\n");
306                       fclose(out);
307                      }
308 }
309
310 search(uri,first_child,position)
311 char               *uri;
312 int                first_child;
313 int                position; 
314 {                  
315                    if (first_child == HERE)
316                       {
317                        if (position == INHYP)
318                           found = search_bucket(uri,MAINHYP);
319                        else if (position == INCONCL)
320                           found = search_bucket(uri,MAINCONCL);
321                        /* if (found == NOTFOUND)
322                           printf( "pos = %d, uri = %s\n", MAINCONCL, uri); */
323                        }
324                     else found = search_bucket(uri,position);
325                     /* if (found == NOTFOUND)
326                           printf( "pos = %d, uri = %s\n", position, uri); */
327                     }
328
329 int yywrap() {
330                return 1;
331              }