From 447388dbac66c6518a0f4e4cc3e165b680f532e9 Mon Sep 17 00:00:00 2001 From: biouman Date: Sat, 28 Apr 2001 22:08:37 +0000 Subject: *** empty log message *** --- include/main.h | 2 +- lib/main.c | 8 +++++--- lib/parser.c | 2 +- lib/pile.c | 29 ++++++++++++++++++++++++----- lib/polynom.c | 2 +- lib/scalaires.c | 2 +- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/main.h b/include/main.h index e7a730b..f8f8e6c 100644 --- a/include/main.h +++ b/include/main.h @@ -3,7 +3,7 @@ #include "hash.h" extern _TableauVariable variables; -extern char mute; +extern char *mute; #endif diff --git a/lib/main.c b/lib/main.c index 19f2fb6..702dfee 100644 --- a/lib/main.c +++ b/lib/main.c @@ -10,6 +10,7 @@ #include "parser.h" #include "polynom.h" #include "pile.h" +#include "exceptions.h" #ifdef HAVE_CONFIG_H #include "config.h" #else @@ -17,14 +18,15 @@ #endif _TableauVariable variables; -char mute; +char *mute; int main(void) { Initialise(&variables); - mute = 'x'; /* nom de la variable utilisee pour la saisie des polynomes, a recuperer en argv eventuellt */ - parse_line("x^2+x+1;"); + mute = Estrdup("x"); + /* nom de la variable utilisee pour la saisie des polynomes, a recuperer en argv eventuellt */ + parse_line("(x^2) + x + 1;"); //parse_line("P(2);"); //printf("%s\n", affichage_level_1()); return 0; diff --git a/lib/parser.c b/lib/parser.c index 3f0c6ce..9e8cf37 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -198,7 +198,7 @@ void parse_line(char *line) sprintf(imm, "Analysing word '%s' at position %i", buffer, line - d); pushcontext(imm); if (get_func(buffer[0]) != -1) { - /* Le mot lut est un operateur, on agit sur la pile */ + /* Le mot lu est un operateur, on agit sur la pile */ buffer[0] += got_unary; if (got_unary) { } diff --git a/lib/pile.c b/lib/pile.c index a1cac21..1fb1aff 100644 --- a/lib/pile.c +++ b/lib/pile.c @@ -9,6 +9,7 @@ #include "numbers.h" #include "main.h" #include "parser.h" +#include "scalaires.h" #ifdef HAVE_CONFIG_H #include "config.h" #else @@ -27,24 +28,44 @@ void push_pile(char *st) int i_number; double d_number; polynome poly; + char buf[128]; + rationnel rat; - + sprintf(buf,"appel à push_pile(%s)",st); + pushcontext(buf); i_number = char_to_number(st, &valid1); d_number = char_to_double(st, &valid2); valid3 = is_mute(st); poly = (polynome) NomVarToVar(st, variables, &valid4); if (valid1) { /* il s agit d un entier */ + pushcontext("c est un entier"); push_pile_poly(ply_constr(rat_constr(i_number, 1), 0)); + popcontext(); } else if (valid2) { /* il s agit d un flottant */ + pushcontext("c est un flottant"); push_pile_poly(ply_constr(rat_constr_from_double(d_number), 0)); + popcontext(); } else if (valid3) { /* il s agit de x */ - push_pile_poly(ply_constr(rat_constr(1, 1), 0)); + pushcontext("c est X"); + rat=rat_constr(1, 1); + /*pushcontext("rat construit"); + poly=ply_constr(rat, 0); + pushcontext("poly cstr"); + push_pile_poly(poly); + pushcontext("poly push"); + popcontext();*/ } else if (valid4) { /* il s agit d une variable */ + pushcontext("c est une variable"); push_pile_poly(ply_copy(poly)); + popcontext(); } else { /* il s agit d un nom */ + pushcontext("c est un nom"); push_pile_string(Estrdup(st)); + popcontext(); } + popcontext(); + fprintf(stderr, "sortie de push_pile\n"); } @@ -120,10 +141,8 @@ char *affichage_level_1(void) int is_mute(char *st) { /* FIXME: test lowercase / uppercase */ - char buf[2]; - sprintf(buf, "%c", mute); - return strcmp(st, buf); + return !(strcmp(st, mute)); } diff --git a/lib/polynom.c b/lib/polynom.c index f1c19a2..8e15297 100644 --- a/lib/polynom.c +++ b/lib/polynom.c @@ -267,7 +267,7 @@ char *ply_affichage(polynome poly) while (poly) { if (poly->degre != 0) { - sprintf(temp, "%+f*%c^%u", rat_to_double(poly->coef), mute, poly->degre); + sprintf(temp, "%+f*%s^%u", rat_to_double(poly->coef), mute, poly->degre); } else { sprintf(temp, "%+f", rat_to_double(poly->coef)); } diff --git a/lib/scalaires.c b/lib/scalaires.c index 71a106d..c40760f 100644 --- a/lib/scalaires.c +++ b/lib/scalaires.c @@ -14,7 +14,7 @@ static int pgcd(int a, int b) return b; if (a < b) return pgcd(b, a); - return pgcd(b, a % b); + return pgcd(b, b % a); } rationnel rat_constr_zero(void) -- cgit v1.2.3