コード例 #1
0
ファイル: vocab.c プロジェクト: ricpelo/prometeo
/*
	InsertarVocab():	Inserta una palabra en el vocabulario
	Recibe:    			tipo, lexema y c¢digo de la palabra
						(si ‚ste es == -1, se indica el siguiente c¢digo
						libre)
	Devuelve:			1 si no hay errores; 0 en caso contrario
*/
int InsertarVocab(TIPO_PALABRA tipoPal, char *lex, int cod)
{
	PALABRA *aux, *i;
	int pos;
	int j;

	if (CodigoVocab(lex) == -1) {	  	/* Si no existe ya esa palabra */

		if ((aux = (PALABRA*) Memoria((long) sizeof(PALABRA))) == NULL)
			return 0;

		if (cod == -1) {				/* Insertamos con un nuevo c¢digo */
			for (j = 0; j < INDICE_PALABRA && indicePal[j] != NULL; j++);
			if (j >= INDICE_PALABRA)
				return 0;
			else
				cod = j;
		}

		aux->codigo = cod;
		aux->tipo = tipoPal;
		aux->lexema = (char *) Memoria((long) (strlen(lex) + 1));
		strcpy(aux->lexema, lex);
		aux->sinonimos = NULL;
		aux->siguiente = NULL;

		/* B£squeda por lexema */
		pos = fHash(lex);
		i = tablaPal[pos];

		if (i == NULL)
			tablaPal[pos] = aux;			/* Actualizaci¢n del vector hash */
		else {

			while (i->siguiente != NULL)
				i = i->siguiente;

			i->siguiente = aux;
		}

		/* B£squeda por c¢digo */
		i = indicePal[cod];

		if (i == NULL) {
			indicePal[cod] = aux;			/* Actualizaci¢n del ¡ndice */
		} else {

			while (i->sinonimos != NULL)
				i = i->sinonimos;

			i->sinonimos = aux;
		}

		numPal++;
		return 1;
	} else
		return 0;
}
コード例 #2
0
ファイル: vocab.c プロジェクト: ricpelo/prometeo
/*
	CargarVocab():	Carga el vocabulario desde un stream
	Recibe:			El puntero al stream
*/
void CargarVocab(FILE *fp)
{
	int i, j, n;
	PALABRA p;
	char buffer[LONG_BUFFER];
	int c;

	fread(&n, sizeof n, 1, fp);			/* N§ de palabras almacenadas */

	for (i = 0; i < n; i++) {
		fread(&p.codigo, sizeof p.codigo, 1, fp);
		fread(&p.tipo, sizeof p.tipo, 1, fp);
		j = 0;

		while ((c = getc(fp)) != '\0')
			buffer[j++] = c;

		buffer[j] = '\0';

		p.lexema = (char *) Memoria((long) (strlen(buffer) + 1));
		strcpy(p.lexema, buffer);

		for (j = 0; j < strlen(p.lexema); j++)
			(p.lexema)[j] ^= 219;

		InsertarVocab(p.tipo, p.lexema, p.codigo);
	}

}
コード例 #3
0
ファイル: Tp1.c プロジェクト: drg91/SO1
void main(int argc, char **argv)
{
    Infocpu();
    KernelC();
    Tiempoactivo();
    Memoria();
    NombrePC();
    TiempoInicio();
    PromedioCarga();
    FechaHora();
    CambiosDeContexto();
}
コード例 #4
0
ファイル: interpre.c プロジェクト: ricpelo/prometeo
LOBJETO *SiguienteAux(LOBJETO *org)
{
	LOBJETO *dest;

	if (org == NULL)
		return NULL;
	else {
		dest = (LOBJETO*) Memoria((long) sizeof (LOBJETO));
		dest->codigo = org->codigo;
		dest->siguiente = SiguienteAux(org->siguiente);
		return dest;
	}
}
コード例 #5
0
ファイル: t_resp.c プロジェクト: ricpelo/prometeo
/*
	InsertarRespuesta():	Inserta una respuesta en la tabla de
							respuestas
	Recibe:					Respuesta (verbo y nombre) y direcci¢n
							de primera instrucci¢n a ejecutar en el
							vector de c¢digo
	Devuelve:				1 si no hay errores; 0 en caso contrario
*/
int InsertarRespuesta(int verb, int nomb, int dir)
{
	RESPUESTA *aux, *i;
	char *p;
	int pos, cod;
	int j;

	/* Si no existe ya esa respuesta */
	if (DarRespuesta(verb, nomb) == NULL) {

		if ((aux = (RESPUESTA*) Memoria((long) sizeof(RESPUESTA))) == NULL)
			return 0;

		aux->verbo = verb;
		aux->nombre = nomb;
		aux->direccion = dir;
		aux->siguiente = NULL;

		/* B£squeda por nombre y adjetivo */
		pos = fHash(verb, nomb);
		i = tablaResp[pos];

		if (i == NULL)
			tablaResp[pos] = aux;		 /* Actualizaci¢n del vector hash */
		else {

			while (i->siguiente != NULL)
				i = i->siguiente;

			i->siguiente = aux;
		}

		numResp++;
		return 1;
	} else
		return 0;
}
コード例 #6
0
ファイル: subrutin.c プロジェクト: ricpelo/prometeo
/*
	FijarNombreSubrutina():	Fija el nombre de una subrutina
	Recibe:					Un puntero al nombre
*/
void FijarNombreSubrutina(SUBR *subrutina, char *nomb)
{
	char *p = (char*) Memoria((long) strlen(nomb) + 1);
	strcpy(p, nomb);
	subrutina->nombre = p;
}