mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-28 19:58:35 +01:00
- minor dictionary .h changes
- starting integrating regexp into eliot
This commit is contained in:
parent
5b11146a36
commit
4f1420ed31
11 changed files with 337 additions and 134 deletions
|
@ -16,12 +16,12 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
# $Id: Makefile.am,v 1.4 2005/04/03 21:12:03 ipkiss Exp $
|
||||
|
||||
bin_PROGRAMS = compdic listdic
|
||||
# $Id: Makefile.am,v 1.5 2005/04/09 19:16:09 afrab Exp $
|
||||
|
||||
noinst_LIBRARIES = libdic.a
|
||||
|
||||
INCLUDES = -I$(top_srcdir)
|
||||
|
||||
libdic_a_SOURCES = \
|
||||
dic_internals.h \
|
||||
dic_search.c dic_search.h \
|
||||
|
@ -29,6 +29,15 @@ libdic_a_SOURCES = \
|
|||
automaton.c automaton.h \
|
||||
regexp.c regexp.h
|
||||
|
||||
#####################################
|
||||
# if BUILD_DICTOOLS
|
||||
# automake does not support regexp_YFLAGS being defined conditionally
|
||||
|
||||
bin_PROGRAMS = \
|
||||
compdic \
|
||||
listdic \
|
||||
regexp
|
||||
|
||||
compdic_SOURCES= \
|
||||
dic_internals.h \
|
||||
hashtable.c hashtble.h \
|
||||
|
@ -39,3 +48,14 @@ listdic_SOURCES= \
|
|||
dic.c dic.h \
|
||||
listdic.c
|
||||
|
||||
regexp_YFLAGS=-d
|
||||
regexp_CFLAGS=${REGEXP_FLAGS}
|
||||
|
||||
regexp_SOURCES= \
|
||||
regexpmain.c \
|
||||
regexp.c regexp.h \
|
||||
automaton.h automaton.c \
|
||||
er.y \
|
||||
er.l
|
||||
|
||||
# endif
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*
|
||||
* $Id: automaton.c,v 1.3 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: automaton.c,v 1.4 2005/04/09 19:16:09 afrab Exp $
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -30,15 +31,19 @@
|
|||
|
||||
#ifndef PDBG
|
||||
#ifdef DEBUG
|
||||
# define PDBG(x) { x ; }
|
||||
# define PDBG(s...) { printf(s); }
|
||||
#else
|
||||
# define PDBG(x) { }
|
||||
# define PDBG(s...) { }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int
|
||||
automaton_build(automaton* aa, int init_state, int *ptl, int *PS)
|
||||
automaton
|
||||
automaton_build(int init_state, int *ptl, int *PS)
|
||||
{
|
||||
/* int init_state; */
|
||||
/* int *ptl; // mapping postition -> lettre */
|
||||
/* int *PS; // Position Suivante [ 1 << (position-1)] = \cup { 1 << (p-1) | p \in position acceptée } */
|
||||
|
||||
int i,l,pos,letter,ens;
|
||||
int state,plist;
|
||||
int *state_list;
|
||||
|
@ -46,7 +51,6 @@ automaton_build(automaton* aa, int init_state, int *ptl, int *PS)
|
|||
automaton a;
|
||||
|
||||
a = (automaton)malloc(sizeof(struct _automaton));
|
||||
*aa = a;
|
||||
|
||||
a->nterm = PS[0];
|
||||
a->nstate = 1;
|
||||
|
@ -68,7 +72,7 @@ automaton_build(automaton* aa, int init_state, int *ptl, int *PS)
|
|||
while (plist)
|
||||
{
|
||||
state = state_list[--plist];
|
||||
PDBG(printf("** traitement état 0x%08x\n",state));
|
||||
PDBG("** traitement état 0x%08x\n",state);
|
||||
memset(used_letter,0,sizeof(used_letter));
|
||||
/* 3: \foreach l in \sigma | l \neq # */
|
||||
for(l=1; l < PS[0]; l++)
|
||||
|
@ -88,7 +92,7 @@ automaton_build(automaton* aa, int init_state, int *ptl, int *PS)
|
|||
{
|
||||
state_list[plist++] = ens;
|
||||
a->Dtrans[state][letter] = ens;
|
||||
PDBG(printf(" adding %x -%c> %x (queue %x)\n",state,letter,ens,ens));
|
||||
PDBG(" adding %x -%c> %x (queue %x)\n",state,letter,ens,ens);
|
||||
if (ens != state)
|
||||
{
|
||||
a->nstate = a->nstate + 1;
|
||||
|
@ -98,7 +102,7 @@ automaton_build(automaton* aa, int init_state, int *ptl, int *PS)
|
|||
if (ens && a->marque[ens] == 1)
|
||||
{
|
||||
a->Dtrans[state][letter] = ens;
|
||||
PDBG(printf(" adding %x -%c> %x\n",state,letter,ens));
|
||||
PDBG(" adding %x -%c> %x\n",state,letter,ens);
|
||||
}
|
||||
a->marque[state] = 1;
|
||||
used_letter[letter] = 1;
|
||||
|
@ -106,19 +110,19 @@ automaton_build(automaton* aa, int init_state, int *ptl, int *PS)
|
|||
}
|
||||
}
|
||||
|
||||
PDBG(printf("** accept : "));
|
||||
PDBG("** accept : ");
|
||||
for(i=0; i < (1 << PS[0]); i++)
|
||||
{
|
||||
if (a->marque[i] && (i & (1 << (PS[0] - 1))))
|
||||
{
|
||||
a->accept[i] = 1;
|
||||
PDBG(printf("%x ",i));
|
||||
PDBG("%x ",i);
|
||||
}
|
||||
}
|
||||
PDBG(printf("\n"));
|
||||
PDBG("\n");
|
||||
|
||||
free(state_list);
|
||||
return 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*
|
||||
* $Id: automaton.h,v 1.2 2005/03/29 08:22:55 afrab Exp $
|
||||
* $Id: automaton.h,v 1.3 2005/04/09 19:16:09 afrab Exp $
|
||||
*/
|
||||
|
||||
#ifndef _DIC_AUTOMATON_H_
|
||||
|
@ -26,15 +26,15 @@ struct _automaton {
|
|||
int nterm;
|
||||
int nstate;
|
||||
int init;
|
||||
int **Dtrans;
|
||||
int *accept;
|
||||
int **Dtrans;
|
||||
int *accept;
|
||||
int *marque;
|
||||
};
|
||||
|
||||
typedef struct _automaton* automaton;
|
||||
|
||||
int automaton_build (automaton *a, int init_state, int *ptl, int *PS);
|
||||
void automaton_delete(automaton a);
|
||||
void automaton_dump (automaton a, char* filename);
|
||||
automaton automaton_build (int init_state, int *ptl, int *PS);
|
||||
void automaton_delete(automaton a);
|
||||
void automaton_dump (automaton a, char* filename);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
/* $Id: dic.h,v 1.2 2004/08/07 18:10:42 ipkiss Exp $ */
|
||||
/* $Id: dic.h,v 1.3 2005/04/09 19:16:09 afrab Exp $ */
|
||||
|
||||
/*!
|
||||
* \file dic.h
|
||||
|
@ -35,8 +35,6 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
#define LETTERS 27
|
||||
|
||||
typedef struct _Dictionary* Dictionary;
|
||||
typedef unsigned int uint_t;
|
||||
|
||||
|
|
113
dic/dic_search.c
113
dic/dic_search.c
|
@ -16,7 +16,7 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*
|
||||
* $Id: dic_search.c,v 1.4 2005/02/05 11:14:56 ipkiss Exp $
|
||||
* $Id: dic_search.c,v 1.5 2005/04/09 19:16:09 afrab Exp $
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -26,6 +26,8 @@
|
|||
#include "dic_internals.h"
|
||||
#include "dic.h"
|
||||
#include "dic_search.h"
|
||||
|
||||
#include "regexp.h"
|
||||
#include "automaton.h"
|
||||
|
||||
/****************************************/
|
||||
|
@ -77,7 +79,7 @@ struct params_7plus1_t {
|
|||
int search_wordlistlen;
|
||||
int search_wordlistlenmax;
|
||||
char search_wordtst[DIC_WORD_MAX];
|
||||
char search_letters[LETTERS];
|
||||
char search_letters[DIC_LETTERS];
|
||||
char (*search_wordlist)[RES_7PL1_MAX][DIC_WORD_MAX];
|
||||
};
|
||||
|
||||
|
@ -138,7 +140,7 @@ Dic_search_word_by_len(struct params_7plus1_t *params, int i, Dawg_edge *edgeptr
|
|||
|
||||
void
|
||||
Dic_search_7pl1(const Dictionary dic, const char* rack,
|
||||
char buff[LETTERS][RES_7PL1_MAX][DIC_WORD_MAX],
|
||||
char buff[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX],
|
||||
int joker)
|
||||
{
|
||||
int i,j,wordlen;
|
||||
|
@ -146,11 +148,11 @@ Dic_search_7pl1(const Dictionary dic, const char* rack,
|
|||
struct params_7plus1_t params;
|
||||
Dawg_edge *root_edge;
|
||||
|
||||
for(i=0; i < LETTERS; i++)
|
||||
for(i=0; i < DIC_LETTERS; i++)
|
||||
for(j=0; j < RES_7PL1_MAX; j++)
|
||||
buff[i][j][0] = '\0';
|
||||
|
||||
for(i=0; i<LETTERS; i++)
|
||||
for(i=0; i<DIC_LETTERS; i++)
|
||||
params.search_letters[i] = 0;
|
||||
|
||||
if (dic == NULL || rack == NULL)
|
||||
|
@ -397,51 +399,59 @@ struct params_regexp_t {
|
|||
};
|
||||
|
||||
void
|
||||
Dic_search_regexp_rec(struct params_regexp_t *params, char wordlist[RES_CROS_MAX][DIC_WORD_MAX], Dawg_edge *edgeptr, int state)
|
||||
Dic_search_regexp_rec(struct params_regexp_t *params,
|
||||
char wordlist[RES_CROS_MAX][DIC_WORD_MAX],
|
||||
Dawg_edge *edgeptr, int state)
|
||||
{
|
||||
/*
|
||||
// Dawg_edge *current = params->dic->dawg + edgeptr->ptr;
|
||||
/* // fin du motif et fin de mot */
|
||||
/* if (params->mask[params->wordlen] == '\0' && edgeptr->term) */
|
||||
/* { */
|
||||
/* if (params->wordlistlen < params->wordlistlenmax) */
|
||||
/* strcpy(wordlist[params->wordlistlen++],params->mask); */
|
||||
/* } */
|
||||
/* // n'importe quel char */
|
||||
/* else if (params->mask[params->wordlen] == '.') */
|
||||
/* { */
|
||||
/* do */
|
||||
/* { */
|
||||
/* params->mask[params->wordlen] = current->chr + 'a' - 1; */
|
||||
/* params->wordlen ++; */
|
||||
/* Dic_search_regexp_rec(params,wordlist,current, ??); */
|
||||
/* params->wordlen --; */
|
||||
/* params->mask[params->wordlen] = '.'; */
|
||||
/* } */
|
||||
/* while (!(*current++).last); */
|
||||
/* } */
|
||||
/* // une lettre dans le motif */
|
||||
/* else */
|
||||
/* { */
|
||||
/* do */
|
||||
/* { */
|
||||
/* if (current->chr == (params->mask[params->wordlen] & CHAR)) */
|
||||
/* { */
|
||||
/* params->wordlen ++; */
|
||||
/* Dic_search_cross_rec(params,wordlist,current); */
|
||||
/* params->wordlen --; */
|
||||
/* break; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* while (!(*current++).last); */
|
||||
/* } */
|
||||
// fin du motif et fin de mot
|
||||
if (params->mask[params->wordlen] == '\0' && edgeptr->term)
|
||||
{
|
||||
if (params->wordlistlen < params->wordlistlenmax)
|
||||
strcpy(wordlist[params->wordlistlen++],params->mask);
|
||||
}
|
||||
// n'importe quel char
|
||||
else if (params->mask[params->wordlen] == '.')
|
||||
{
|
||||
do
|
||||
{
|
||||
params->mask[params->wordlen] = current->chr + 'a' - 1;
|
||||
params->wordlen ++;
|
||||
Dic_search_regexp_rec(params,wordlist,current, ??);
|
||||
params->wordlen --;
|
||||
params->mask[params->wordlen] = '.';
|
||||
}
|
||||
while (!(*current++).last);
|
||||
}
|
||||
// une lettre dans le motif
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
if (current->chr == (params->mask[params->wordlen] & CHAR))
|
||||
{
|
||||
params->wordlen ++;
|
||||
Dic_search_cross_rec(params,wordlist,current);
|
||||
params->wordlen --;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (!(*current++).last);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void
|
||||
Dic_search_RegE(const Dictionary dic, const char* mask,
|
||||
char wordlist[RES_REGE_MAX][DIC_WORD_MAX])
|
||||
{
|
||||
int i;
|
||||
int i,p,n;
|
||||
struct params_regexp_t params;
|
||||
|
||||
int ptl[REGEXP_MAX+1]; // mapping postition -> lettre
|
||||
int PS [REGEXP_MAX+1]; // Position Suivante [ 1 << (position-1)] = \cup { 1 << (p-1) | p \in position acceptée }
|
||||
|
||||
automaton a = NULL;
|
||||
|
||||
for(i=0; i < RES_REGE_MAX; i++)
|
||||
|
@ -450,8 +460,22 @@ Dic_search_RegE(const Dictionary dic, const char* mask,
|
|||
if (dic == NULL || mask == NULL)
|
||||
return;
|
||||
|
||||
/* if (automaton_build(&a,"")) */
|
||||
/* return; */
|
||||
/*
|
||||
* we stop here right now
|
||||
|
||||
if ((root = regexp_parse(mask)) == NULL)
|
||||
return;
|
||||
|
||||
n = 1;
|
||||
p = 1;
|
||||
regexp_parcours(root,&p,&n,ptl);
|
||||
PS [0] = p - 1;
|
||||
ptl[0] = p - 1;
|
||||
|
||||
regexp_possuivante(root,PS);
|
||||
|
||||
if ((a = automaton_build()) == NULL)
|
||||
return;
|
||||
|
||||
params.dic = dic;
|
||||
params.wordlen = 0;
|
||||
|
@ -459,6 +483,9 @@ Dic_search_RegE(const Dictionary dic, const char* mask,
|
|||
params.wordlistlenmax = RES_REGE_MAX;
|
||||
params.er_automaton = a;
|
||||
Dic_search_regexp_rec(¶ms, wordlist, dic->dawg + dic->root, 0);
|
||||
|
||||
automaton_delete(a);
|
||||
*/
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
/* $Id: dic_search.h,v 1.3 2005/02/05 11:14:56 ipkiss Exp $ */
|
||||
/* $Id: dic_search.h,v 1.4 2005/04/09 19:16:09 afrab Exp $ */
|
||||
|
||||
#ifndef _DIC_SEARCH_H_
|
||||
#define _DIC_SEARCH_H_
|
||||
|
@ -26,7 +26,9 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
#define DIC_WORD_MAX 16
|
||||
#define DIC_LETTERS 27 // different letters in the dictionary
|
||||
#define DIC_WORD_MAX 16 // max length of words (including last \0)
|
||||
|
||||
#define RES_7PL1_MAX 200
|
||||
#define RES_RACC_MAX 100
|
||||
#define RES_BENJ_MAX 100
|
||||
|
@ -34,11 +36,11 @@ extern "C"
|
|||
#define RES_REGE_MAX 200
|
||||
|
||||
int Dic_search_word(Dictionary, const char*);
|
||||
void Dic_search_7pl1(Dictionary, const char* rack, char wordlist[LETTERS][RES_7PL1_MAX][DIC_WORD_MAX], int joker);
|
||||
void Dic_search_7pl1(Dictionary, const char* rack, char wordlist[DIC_LETTERS][RES_7PL1_MAX][DIC_WORD_MAX], int joker);
|
||||
void Dic_search_Racc(Dictionary, const char* word, char wordlist[RES_RACC_MAX][DIC_WORD_MAX]);
|
||||
void Dic_search_Benj(Dictionary, const char* word, char wordlist[RES_BENJ_MAX][DIC_WORD_MAX]);
|
||||
void Dic_search_Cros(Dictionary, const char* mask, char wordlist[RES_CROS_MAX][DIC_WORD_MAX]);
|
||||
void Dic_search_RegE(Dictionary, const char* mask, char wordlist[RES_CROS_MAX][DIC_WORD_MAX]);
|
||||
void Dic_search_RegE(Dictionary, const char* mask, char wordlist[RES_REGE_MAX][DIC_WORD_MAX]);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
24
dic/er.l
Normal file
24
dic/er.l
Normal file
|
@ -0,0 +1,24 @@
|
|||
%{
|
||||
|
||||
#include "regexp.h"
|
||||
#include "regexp-er.h"
|
||||
|
||||
#define YY_NO_UNPUT
|
||||
|
||||
%}
|
||||
%option noyywrap
|
||||
|
||||
alphabet [a-zA-Z]
|
||||
%%
|
||||
|
||||
{alphabet} {yylval.variable = yytext[0]; return VARIABLE;}
|
||||
"(" {return PAR_G;}
|
||||
")" {return PAR_D;}
|
||||
"#" {return DIESE;}
|
||||
"*" {return STAR;}
|
||||
"+" {return OR;}
|
||||
"." {return AND;}
|
||||
|
||||
"\n" {return FIN;}
|
||||
%%
|
||||
|
81
dic/er.y
Normal file
81
dic/er.y
Normal file
|
@ -0,0 +1,81 @@
|
|||
%{
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include "regexp.h"
|
||||
|
||||
int yylex();
|
||||
void yyerror(char*);
|
||||
|
||||
NODE *createNODE(int type, char v, NODE *fg, NODE *fd);
|
||||
|
||||
%}
|
||||
%union {
|
||||
char variable;
|
||||
NODE *NODE_TYPE;
|
||||
};
|
||||
|
||||
%token DIESE PAR_G PAR_D FIN
|
||||
%token <variable> VARIABLE
|
||||
%left OR
|
||||
%left AND
|
||||
%left STAR
|
||||
%type <NODE_TYPE> var
|
||||
%type <NODE_TYPE> expr
|
||||
%start start
|
||||
%%
|
||||
|
||||
/* start : ex ex */
|
||||
/* { root=createNODE(NODE_TOP,'\0',$1,$2); YYACCEPT; } */
|
||||
/* ; */
|
||||
|
||||
start: expr FIN
|
||||
{ root = createNODE(NODE_AND,'\0',$1,createNODE(NODE_VAR,'#',NULL,NULL)); YYACCEPT; }
|
||||
;
|
||||
|
||||
expr : var {$$=$1;}
|
||||
| expr expr {$$=createNODE(NODE_AND,'\0',$1,$2);}
|
||||
| expr AND expr {$$=createNODE(NODE_AND,'\0',$1,$3);}
|
||||
| PAR_G expr PAR_D {$$=$2;}
|
||||
| expr OR expr {$$=createNODE(NODE_OR,'\0',$1,$3);}
|
||||
| var STAR {$$=createNODE(NODE_STAR,'\0',$1,NULL);}
|
||||
| PAR_G expr PAR_D STAR {$$=createNODE(NODE_STAR,'\0',$2,NULL);}
|
||||
;
|
||||
|
||||
var : VARIABLE
|
||||
{$$=createNODE(NODE_VAR,$1,NULL,NULL);}
|
||||
;
|
||||
|
||||
%%
|
||||
/*--------------------------------------------------------
|
||||
* FONCTIONS LEX/YACC
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
void yyerror(char *s)
|
||||
{
|
||||
printf("\n erreur ! (%s)\n",s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------
|
||||
*
|
||||
*--------------------------------------------------------*/
|
||||
NODE *createNODE(int type,char v,NODE *fg,NODE *fd)
|
||||
{
|
||||
NODE *x;
|
||||
x=(NODE *)malloc(sizeof(NODE));
|
||||
|
||||
x->type = type;
|
||||
x->var = v;
|
||||
x->fd = fd;
|
||||
x->fg = fg;
|
||||
|
||||
x->numero = 0;
|
||||
x->position = 0;
|
||||
x->annulable = 0;
|
||||
x->PP = 0;
|
||||
x->DP = 0;
|
||||
return (x);
|
||||
}
|
||||
|
||||
|
83
dic/regexp.c
83
dic/regexp.c
|
@ -16,15 +16,20 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*
|
||||
* $Id: regexp.c,v 1.1 2004/06/21 16:06:54 afrab Exp $
|
||||
* $Id: regexp.c,v 1.2 2005/04/09 19:16:09 afrab Exp $
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
# include <sys/wait.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#include "regexp.h"
|
||||
#include "automaton.h"
|
||||
|
||||
#define MAX 32
|
||||
|
||||
#ifndef PDBG
|
||||
#ifdef DEBUG
|
||||
|
@ -34,6 +39,8 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
static void print_node(NODE *n);
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// position, annulable, PP, DP
|
||||
// r = root
|
||||
|
@ -42,13 +49,13 @@
|
|||
// ptl = position to letter
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void parcours(NODE* r, int *p, int *n, int ptl[])
|
||||
void regexp_parcours(NODE* r, int *p, int *n, int ptl[])
|
||||
{
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
parcours(r->fg,p,n,ptl);
|
||||
parcours(r->fd,p,n,ptl);
|
||||
regexp_parcours(r->fg,p,n,ptl);
|
||||
regexp_parcours(r->fd,p,n,ptl);
|
||||
|
||||
switch (r->type)
|
||||
{
|
||||
|
@ -91,14 +98,14 @@ void parcours(NODE* r, int *p, int *n, int ptl[])
|
|||
// PosSuivante
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void possuivante(NODE* r, int PS[])
|
||||
void regexp_possuivante(NODE* r, int PS[])
|
||||
{
|
||||
int pos;
|
||||
if (r == NULL)
|
||||
return;
|
||||
|
||||
possuivante(r->fg,PS);
|
||||
possuivante(r->fd,PS);
|
||||
regexp_possuivante(r->fg,PS);
|
||||
regexp_possuivante(r->fd,PS);
|
||||
|
||||
switch (r->type)
|
||||
{
|
||||
|
@ -122,8 +129,7 @@ void possuivante(NODE* r, int PS[])
|
|||
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
#if 0
|
||||
void print_node(NODE *n)
|
||||
static void print_node(NODE *n)
|
||||
{
|
||||
if (n == NULL)
|
||||
return;
|
||||
|
@ -151,7 +157,7 @@ void print_node(NODE *n)
|
|||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void print_PS(int PS[])
|
||||
void regexp_print_PS(int PS[])
|
||||
{
|
||||
int i;
|
||||
printf("** positions suivantes **\n");
|
||||
|
@ -164,7 +170,7 @@ void print_PS(int PS[])
|
|||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void print_ptl(int ptl[])
|
||||
void regexp_print_ptl(int ptl[])
|
||||
{
|
||||
int i;
|
||||
printf("** pos -> lettre: ");
|
||||
|
@ -178,7 +184,7 @@ void print_ptl(int ptl[])
|
|||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
void print_tree_nodes(FILE* f, NODE* n)
|
||||
static void print_tree_nodes(FILE* f, NODE* n)
|
||||
{
|
||||
if (n == NULL)
|
||||
return;
|
||||
|
@ -205,7 +211,7 @@ void print_tree_nodes(FILE* f, NODE* n)
|
|||
fprintf(f,"\\n annulable=%d\\n PP=0x%08x\\n DP=0x%08x\"];\n",n->annulable,n->PP,n->DP);
|
||||
}
|
||||
|
||||
void print_tree_edges(FILE* f, NODE* n)
|
||||
static void print_tree_edges(FILE* f, NODE* n)
|
||||
{
|
||||
if (n == NULL)
|
||||
return;
|
||||
|
@ -229,7 +235,7 @@ void print_tree_edges(FILE* f, NODE* n)
|
|||
}
|
||||
}
|
||||
|
||||
void print_tree(NODE* n)
|
||||
void regexp_print_tree(NODE* n)
|
||||
{
|
||||
FILE* f;
|
||||
pid_t pid;
|
||||
|
@ -243,6 +249,7 @@ void print_tree(NODE* n)
|
|||
fprintf(f,"}\n");
|
||||
fclose(f);
|
||||
|
||||
#ifdef HAVE_SYS_WAIT_H
|
||||
pid = fork ();
|
||||
if (pid > 0) {
|
||||
wait(NULL);
|
||||
|
@ -251,52 +258,6 @@ void print_tree(NODE* n)
|
|||
printf("exec dotty failed\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
#if 0
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i,p,n;
|
||||
int ptl[MAX+1]; // mapping postition -> lettre
|
||||
int PS [MAX+1]; // Position Suivante [ 1 << (position-1)] = \cup { 1 << (p-1) | p \in position acceptée }
|
||||
automaton a,b;
|
||||
|
||||
for(i=0; i < MAX; i++)
|
||||
{
|
||||
PS[i] = 0;
|
||||
ptl[i] = 0;
|
||||
}
|
||||
|
||||
yyparse();
|
||||
|
||||
n = 1;
|
||||
p = 1;
|
||||
parcours(root,&p,&n,ptl);
|
||||
PS [0] = p - 1;
|
||||
ptl[0] = p - 1;
|
||||
PDBG(printf("** regexp: nombre de terminaux: %d\n",PS[0]));
|
||||
PDBG(printf("** regexp: nombre de noeuds dans l'arbre: %d\n",n));
|
||||
PDBG(print_ptl(ptl));
|
||||
|
||||
possuivante(root,PS);
|
||||
PDBG(print_tree(root));
|
||||
PDBG(print_PS(PS));
|
||||
|
||||
automaton_build(&a,root->PP,ptl,PS);
|
||||
PDBG(printf("** auto: nombre d'états: %d\n",a.nstate));
|
||||
print_automaton(&a);
|
||||
|
||||
automaton_minimize(&a,&b);
|
||||
PDBG(printf("** auto: nombre d'états: %d\n",b.nstate));
|
||||
PDBG(print_automaton(&b));
|
||||
|
||||
automaton_destroy(&a);
|
||||
automaton_destroy(&b);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
//////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
|
|
15
dic/regexp.h
15
dic/regexp.h
|
@ -16,7 +16,7 @@
|
|||
/* along with this program; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*
|
||||
* $Id: regexp.h,v 1.1 2004/06/20 20:13:59 afrab Exp $
|
||||
* $Id: regexp.h,v 1.2 2005/04/09 19:16:09 afrab Exp $
|
||||
*/
|
||||
#ifndef _TREE_H_
|
||||
#define _TREE_H_
|
||||
|
@ -40,6 +40,19 @@ typedef struct node {
|
|||
int DP;
|
||||
} NODE;
|
||||
|
||||
extern NODE* root;
|
||||
|
||||
/* max regexp length */
|
||||
#define REGEXP_MAX 32
|
||||
|
||||
void regexp_parcours(NODE* r, int *p, int *n, int ptl[]);
|
||||
void regexp_possuivante(NODE* r, int PS[]);
|
||||
|
||||
void regexp_print_PS(int PS[]);
|
||||
void regexp_print_ptl(int ptl[]);
|
||||
void regexp_print_tree(NODE* n);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
73
dic/regexpmain.c
Normal file
73
dic/regexpmain.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* 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 */
|
||||
/*
|
||||
* $Id: regexpmain.c,v 1.1 2005/04/09 19:16:09 afrab Exp $
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "regexp.h"
|
||||
#include "automaton.h"
|
||||
|
||||
#ifndef PDBG
|
||||
#ifdef DEBUG
|
||||
#define PDBG(x) { x ; }
|
||||
#else
|
||||
#define PDBG(x) { }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
NODE* root;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int i,p,n;
|
||||
int ptl[REGEXP_MAX+1]; // mapping postition -> lettre
|
||||
int PS [REGEXP_MAX+1]; // Position Suivante [ 1 << (position-1)] = \cup { 1 << (p-1) | p \in position acceptée }
|
||||
automaton a;
|
||||
|
||||
for(i=0; i < REGEXP_MAX; i++)
|
||||
{
|
||||
PS[i] = 0;
|
||||
ptl[i] = 0;
|
||||
}
|
||||
|
||||
yyparse(argv[1]);
|
||||
|
||||
n = 1;
|
||||
p = 1;
|
||||
regexp_parcours(root,&p,&n,ptl);
|
||||
PS [0] = p - 1;
|
||||
ptl[0] = p - 1;
|
||||
PDBG(printf("** regexp: nombre de terminaux: %d\n",PS[0]));
|
||||
PDBG(printf("** regexp: nombre de noeuds dans l'arbre: %d\n",n));
|
||||
PDBG(regexp_print_ptl(ptl));
|
||||
|
||||
regexp_possuivante(root,PS);
|
||||
PDBG(regexp_print_tree(root));
|
||||
PDBG(regexp_print_PS(PS));
|
||||
|
||||
a = automaton_build(root->PP,ptl,PS);
|
||||
PDBG(printf("** auto: nombre d'états: %d\n",a->nstate));
|
||||
automaton_dump(a,"regexp.auto");
|
||||
|
||||
automaton_delete(a);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue