From 084057754afdb911349d05aedf7b1c00c7b73f96 Mon Sep 17 00:00:00 2001 From: biouman Date: Sun, 29 Apr 2001 13:48:35 +0000 Subject: *** empty log message *** --- include/pile.h | 1 + lib/pile.c | 81 +++++++++++++++++++++++++++++++++++++-------------------- lib/scalaires.c | 1 + src/Polynom.c | 12 ++++----- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/include/pile.h b/include/pile.h index 02ad149..bcb15b6 100644 --- a/include/pile.h +++ b/include/pile.h @@ -33,4 +33,5 @@ int is_mute(char *st); void act_pile(int func); +void affichage_pile(void); #endif diff --git a/lib/pile.c b/lib/pile.c index 489ba9f..c3f6644 100644 --- a/lib/pile.c +++ b/lib/pile.c @@ -36,7 +36,6 @@ void push_pile(char *st) d_number = char_to_double(st, &valid2); valid3 = is_mute(st); poly = (polynome) NomVarToVar(st, variables, &valid4); - printf("%p\n", poly); if (valid1) { /* il s agit d un entier */ pushcontext("c est un entier"); push_pile_poly(ply_constr(rat_constr(i_number, 1), 0)); @@ -47,7 +46,7 @@ void push_pile(char *st) popcontext(); } else if (valid3) { /* il s agit de x */ pushcontext("c est X"); - push_pile_poly(ply_constr(rat_constr(1, 1), 0)); + push_pile_poly(ply_constr(rat_constr(1, 1), 1)); popcontext(); } else if (valid4) { /* il s agit d une variable */ pushcontext("c est une variable"); @@ -59,13 +58,14 @@ void push_pile(char *st) popcontext(); } popcontext(); + affichage_pile(); + fprintf(stderr, "sortie de push_pile\n"); } void push_pile_poly(polynome poly) { - pushcontext("entree dans push_pile_poly"); if (pile_ptr != PILE_MAX) { pile[pile_ptr].type = T_POLY; pile[pile_ptr].poly = poly; @@ -73,15 +73,11 @@ void push_pile_poly(polynome poly) } else { exception(1, _("push_pile_poly: Stack Overflow")); } - pushcontext("sortie de push_pile_poly"); - popcontext(); - popcontext(); } void push_pile_int(int val) { - pushcontext("appel a push_pile_int"); fprintf(stderr,"%d",val); if (pile_ptr != PILE_MAX) { pile[pile_ptr].type = T_INT; @@ -90,16 +86,12 @@ void push_pile_int(int val) } else { exception(1, _("push_pile_int: Stack Overflow")); } - pushcontext("sortie de push-pile_int"); - popcontext(); - popcontext(); } void push_pile_string(char *st) { - pushcontext("appel a push_pile_string"); if (pile_ptr != PILE_MAX) { pile[pile_ptr].type = T_STRING; pile[pile_ptr].label = Estrdup(st); @@ -107,9 +99,6 @@ void push_pile_string(char *st) } else { exception(1, _("push_pile_string: Stack Overflow")); } - pushcontext("sortie de push_pile_string"); - popcontext(); - popcontext(); } @@ -124,7 +113,6 @@ pile_elem pop_pile(unsigned int count) sprintf(buf, _("pop_pile: Can't pop %u elements"), count); exception(1, buf); } - fprintf(stderr,"pile_ptr = %d\n", pile_ptr); return pile[pile_ptr]; } @@ -162,8 +150,10 @@ void act_pile(int func) sprintf(buf, _("Calling act_pile(%i)\n"), func); pushcontext(buf); + affichage_pile(); switch (func) { case OP_PLUS: + printf("----- OP_PLUS\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -177,6 +167,7 @@ void act_pile(int func) } break; case OP_MOINS: + printf("----- OP_MOINS\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -190,6 +181,7 @@ void act_pile(int func) } break; case OP_MUL: + printf("----- OP_MUL\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -203,6 +195,7 @@ void act_pile(int func) } break; case OP_DIV: + printf("----- OP_DIV\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -216,6 +209,7 @@ void act_pile(int func) } break; case OP_MOD: + printf("----- OP_MOD\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { @@ -229,17 +223,18 @@ void act_pile(int func) } break; case OP_EXP: + printf("----- OP_EXP\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { - if (operande2.poly) { - if ((operande2.poly->coef.denom == 1) - && (operande2.poly->coef.num >= 0)) { + if (operande1.poly) { + if ((operande1.poly->coef.denom == 1) + && (operande1.poly->coef.num >= 0)) { push_pile_poly(ply_exposant - (operande1.poly, operande2.poly->coef.num)); - if (operande1.poly) - ply_destruct(operande1.poly); - ply_destruct(operande2.poly); + (operande2.poly, operande1.poly->coef.num)); + if (operande2.poly) + ply_destruct(operande2.poly); + ply_destruct(operande1.poly); } else { exception(1, _("act_pile: OP_EXP invalid arguments")); } @@ -251,6 +246,7 @@ void act_pile(int func) } break; case OP_ASSIGN: + printf("----- OP_ASSIGN\n"); operande1 = pop_pile(1); operande2 = pop_pile(1); if ((operande1.type == T_POLY) && (operande2.type == T_STRING)) { @@ -258,7 +254,7 @@ void act_pile(int func) InsererVarDansTab(&variables, CreerElement(operande2.label, (void *) operande1.poly)); - /* free(operande2.label); */ + free(operande2.label); } else { exception(1, _("act_pile: OP_ASSIGN empty string")); } @@ -267,8 +263,12 @@ void act_pile(int func) } break; case OP_PLUS_UNARY: + printf("----- OP_PLUS_UNARY\n"); + break; case OP_MOINS_UNARY: + printf("----- OP_MOINS_UNARY\n"); + operande1 = pop_pile(1); if (operande1.type == T_POLY) { push_pile_poly(ply_soustraction @@ -280,6 +280,8 @@ void act_pile(int func) } break; case OP_FUNC_CALL: + printf("----- OP_FUNC_CALL\n"); + operande1 = pop_pile(1); if ((operande1.type == T_INT) && (operande1.val == 1)) { operande1 = pop_pile(1); @@ -287,7 +289,7 @@ void act_pile(int func) if ((operande1.type == T_POLY) && (operande2.type == T_POLY)) { if (operande2.poly) { if (operande1.poly->degre == 0) { - double soja, soja2; + /*double soja, soja2; rationnel rat; polynome pl; fprintf(stderr,"soja"); @@ -297,10 +299,10 @@ void act_pile(int func) fprintf(stderr,"%f", soja2); rat=rat_constr_from_double(soja2); fprintf(stderr,"pl"); - pl=ply_constr(rat, 1); -/* -push_pile_poly(ply_constr(rat_constr_from_double(ply_valuation(operande2.poly,rat_to_double(operande1.poly->coef))), 1)); -*/ + pl=ply_constr(rat, 1);*/ + +push_pile_poly(ply_constr(rat_constr_from_double(ply_valuation(operande2.poly,rat_to_double(operande1.poly->coef))), 0)); + if (operande1.poly) ply_destruct(operande1.poly); ply_destruct(operande2.poly); @@ -324,3 +326,26 @@ push_pile_poly(ply_constr(rat_constr_from_double(ply_valuation(operande2.poly,ra } popcontext(); } + + +void affichage_pile(void) { + int i; + printf("\t-- affichage de la pile\n"); + if (pile_ptr) { + for (i=0;i<=pile_ptr-1;i++) { + switch (pile[i].type) { + case T_INT: + printf("\t\t%d:I: %d\n", i, pile[i].val); + break; + case T_STRING: + printf("\t\t%d:S: %s\n", i, pile[i].label); + break; + case T_POLY: + printf("\t\t%d:P: %s\n", i, ply_affichage(pile[i].poly)); + break; + } + } + } + printf("\t-- fin d affichage de pile\n"); +} + diff --git a/lib/scalaires.c b/lib/scalaires.c index 10c9196..b853741 100644 --- a/lib/scalaires.c +++ b/lib/scalaires.c @@ -5,6 +5,7 @@ */ #include "scalaires.h" +#include "exceptions.h" #include #define PRECISION 1E6 diff --git a/src/Polynom.c b/src/Polynom.c index 6a46d4a..5878e41 100644 --- a/src/Polynom.c +++ b/src/Polynom.c @@ -28,17 +28,17 @@ int main(void) textdomain(PACKAGE); Initialise(&variables); - mute = Estrdup("x"); + mute = "x"; /* nom de la variable utilisee pour la saisie des polynomes, a recuperer en argv eventuellt */ - parse_line("P=(x^2) + x + 1;"); + parse_line("P=3*x^2+2*x +4.5;"); //parse_line("P(2);"); - AfficheTableau(variables); - printf("%p\n",(polynome)NomVarToVar("P",variables,&valid)); - printf("-- affichage:%s\n",ply_affichage((polynome)NomVarToVar("P",variables,&valid))); + //AfficheTableau(variables); + //printf("%p\n",(polynome)NomVarToVar("P",variables,&valid)); + //printf("-- affichage:%s\n",ply_affichage((polynome)NomVarToVar("P",variables,&valid))); parse_line("P(2);"); //fprintf(stderr, "soja"); - //printf("%s\n", affichage_level_1()); + printf("Resultat: %s\n", affichage_level_1()); return 0; -- cgit v1.2.3