2005-04-09 19:16:09 +00:00
|
|
|
|
/* Eliot */
|
|
|
|
|
/* Copyright (C) 1999 antoine.fraboulet */
|
|
|
|
|
/* antoine.fraboulet@free.fr */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is free software; you can redistribute it and/or modify */
|
|
|
|
|
/* it under the terms of the GNU General Public License as published by */
|
|
|
|
|
/* the Free Software Foundation; either version 2 of the License, or */
|
|
|
|
|
/* (at your option) any later version. */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is distributed in the hope that it will be useful, */
|
|
|
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
|
|
|
/* GNU General Public License for more details. */
|
|
|
|
|
/* */
|
|
|
|
|
/* You should have received a copy of the GNU General Public License */
|
|
|
|
|
/* along with this program; if not, write to the Free Software */
|
|
|
|
|
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
/*
|
2005-04-18 17:40:36 +00:00
|
|
|
|
* $Id: regexpmain.c,v 1.3 2005/04/18 17:40:36 afrab Exp $
|
2005-04-09 19:16:09 +00:00
|
|
|
|
*/
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "regexp.h"
|
2005-04-18 17:40:36 +00:00
|
|
|
|
#include "regexp-er.h" /* generated by bison */
|
|
|
|
|
#include "scanner.h" /* generated by flex */
|
2005-04-09 19:16:09 +00:00
|
|
|
|
#include "automaton.h"
|
|
|
|
|
|
|
|
|
|
#ifndef PDBG
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define PDBG(x) { x ; }
|
|
|
|
|
#else
|
|
|
|
|
#define PDBG(x) { }
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-04-16 20:55:51 +00:00
|
|
|
|
extern int yyparse(yyscan_t scanner, NODE ** root);
|
2005-04-09 19:16:09 +00:00
|
|
|
|
|
2005-04-16 20:55:51 +00:00
|
|
|
|
|
|
|
|
|
int buildauto(char* er)
|
2005-04-09 19:16:09 +00:00
|
|
|
|
{
|
2005-04-16 20:55:51 +00:00
|
|
|
|
int i,p,n,value;
|
|
|
|
|
|
|
|
|
|
int ptl[REGEXP_MAX+1];
|
|
|
|
|
int PS [REGEXP_MAX+1];
|
|
|
|
|
|
|
|
|
|
NODE* root;
|
|
|
|
|
yyscan_t scanner;
|
|
|
|
|
YY_BUFFER_STATE buf;
|
|
|
|
|
|
2005-04-09 19:16:09 +00:00
|
|
|
|
automaton a;
|
|
|
|
|
|
2005-04-16 20:55:51 +00:00
|
|
|
|
char stringbuf[250];
|
|
|
|
|
|
2005-04-18 17:40:36 +00:00
|
|
|
|
/* (expr)# */
|
|
|
|
|
sprintf(stringbuf,"(%s)#",er);
|
2005-04-16 20:55:51 +00:00
|
|
|
|
|
2005-04-09 19:16:09 +00:00
|
|
|
|
for(i=0; i < REGEXP_MAX; i++)
|
|
|
|
|
{
|
|
|
|
|
PS[i] = 0;
|
|
|
|
|
ptl[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-16 20:55:51 +00:00
|
|
|
|
yylex_init( &scanner );
|
|
|
|
|
buf = yy_scan_string( stringbuf, scanner );
|
|
|
|
|
root = NULL;
|
|
|
|
|
value = yyparse( scanner , &root);
|
|
|
|
|
yy_delete_buffer(buf,scanner);
|
|
|
|
|
yylex_destroy( scanner );
|
|
|
|
|
|
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
regexp_delete_tree(root);
|
2005-04-18 17:40:36 +00:00
|
|
|
|
return 1;
|
2005-04-16 20:55:51 +00:00
|
|
|
|
}
|
2005-04-09 19:16:09 +00:00
|
|
|
|
|
|
|
|
|
n = 1;
|
|
|
|
|
p = 1;
|
2005-04-16 20:55:51 +00:00
|
|
|
|
regexp_parcours(root, &p, &n, ptl);
|
2005-04-09 19:16:09 +00:00
|
|
|
|
PS [0] = p - 1;
|
|
|
|
|
ptl[0] = p - 1;
|
2005-04-16 20:55:51 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
printf("** regexp: nombre de terminaux: %d\n",PS[0]);
|
|
|
|
|
printf("** regexp: nombre de noeuds dans l'arbre: %d\n",n);
|
|
|
|
|
printf("** position des lettres : \n");
|
|
|
|
|
regexp_print_ptl(ptl);
|
|
|
|
|
*/
|
2005-04-09 19:16:09 +00:00
|
|
|
|
|
|
|
|
|
regexp_possuivante(root,PS);
|
2005-04-16 20:55:51 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
regexp_print_tree(root,"tree",1);
|
|
|
|
|
regexp_print_PS(PS);
|
|
|
|
|
*/
|
2005-04-09 19:16:09 +00:00
|
|
|
|
|
|
|
|
|
a = automaton_build(root->PP,ptl,PS);
|
2005-04-16 20:55:51 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
printf("** auto: nombre d'<27>tats: %d\n",a->nstate);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
automaton_dump(a,"auto");
|
2005-04-09 19:16:09 +00:00
|
|
|
|
automaton_delete(a);
|
2005-04-16 20:55:51 +00:00
|
|
|
|
regexp_delete_tree(root);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-18 17:40:36 +00:00
|
|
|
|
void yyerror (yyscan_t yyscanner, NODE** root, char const *msg)
|
|
|
|
|
{
|
|
|
|
|
printf("\n erreur ! (%s)\n",msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-04-16 20:55:51 +00:00
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
char stringbuf[200];
|
|
|
|
|
strcpy(stringbuf,".");
|
|
|
|
|
|
|
|
|
|
while (strcmp(stringbuf,""))
|
|
|
|
|
{
|
|
|
|
|
fprintf(stdout,"entrer une ER:\n");
|
|
|
|
|
fgets(stringbuf,sizeof(stringbuf),stdin);
|
|
|
|
|
/* strip \n */
|
|
|
|
|
stringbuf[strlen(stringbuf) - 1] = '\0';
|
2005-04-18 17:40:36 +00:00
|
|
|
|
/* automaton */
|
2005-04-16 20:55:51 +00:00
|
|
|
|
buildauto(stringbuf);
|
|
|
|
|
}
|
2005-04-09 19:16:09 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|