summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/parser.c14
-rw-r--r--lib/polynom.c51
-rw-r--r--po/cat-id-tbl.c59
3 files changed, 80 insertions, 44 deletions
diff --git a/lib/parser.c b/lib/parser.c
index ef3f0e9..3483d1e 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -208,8 +208,8 @@ void parse_line(char *line)
exception(1, _("Invalid binary operator"));
}
}
- while ((get_pri(get_last_op()) >= get_pri(buffer[0]))
- && ((get_last_op() & 127) != '(')) {
+ while (((get_pri(get_last_op()) >= get_pri(buffer[0]))
+ && ((get_last_op() & 127) != '(')) && !global_error) {
act_pile(get_func(pop_op()));
got_unary = 0;
}
@@ -226,7 +226,7 @@ void parse_line(char *line)
switch (buffer[0]) {
case ';':
/* Equivalent a fin de ligne */
- while (pileop_pos) {
+ while ((pileop_pos) && !global_error) {
op = pop_op();
if (op == '(')
exception(1, _("Parse error: too much left parenthesis"));
@@ -236,7 +236,7 @@ void parse_line(char *line)
break;
case ')':
/* Fin de parenthese (Appel de fonction ou expression mathématique) */
- while (1) {
+ while (!global_error) {
if (!pileop_pos)
exception(1, _("Parse error: too much right parenthesis"));
op = pop_op();
@@ -271,4 +271,10 @@ void parse_line(char *line)
popcontext();
}
popcontext();
+ if (global_error) {
+ got_unary = 0;
+ while (pileop_pos) {
+ pop_op();
+ }
+ }
}
diff --git a/lib/polynom.c b/lib/polynom.c
index 8478531..472eb24 100644
--- a/lib/polynom.c
+++ b/lib/polynom.c
@@ -222,21 +222,52 @@ polynome ply_multiplication(polynome poly1, polynome poly2)
return resultat;
}
-polynome ply_division(polynome poly1, polynome poly2)
+polynome ply_division(polynome dividende, polynome diviseur)
{ /* division de deux polynomes */
- polynome result = NULL;
-
-
- return result;
-
-
+ polynome interdividende = dividende, interdiviseur = NULL, inter = NULL, reste = dividende, resultat = NULL, r = NULL;
+
+ printf("On divise %s", ply_affichage(dividende));
+ printf("par %s\n", ply_affichage(diviseur));
+ printf("interdividende degre = %u\n", interdividende->degre);
+ printf("diviseur degre = %u\n", diviseur->degre);
+ while ((interdividende) && (interdividende->degre >= diviseur->degre)) {
+ inter = ply_constr(rat_division(dividende->coef, diviseur->coef), dividende->degre - diviseur->degre);
+ printf("On trouve qu'il nous faut soustraire %s fois\n", ply_affichage(inter));
+ r = ply_addition(resultat, inter);
+ printf("Resultat intermédiaire %s\n", ply_affichage(r));
+ interdiviseur = ply_multiplication(diviseur, inter);
+ printf("On soustrait donc %s\n", ply_affichage(interdiviseur));
+ reste = ply_soustraction(interdividende, interdiviseur);
+ printf("Reste intermédiaire %s\n", ply_affichage(reste));
+ ply_destruct(resultat);
+ ply_destruct(inter);
+ ply_destruct(interdividende);
+ ply_destruct(interdiviseur);
+ resultat = r;
+ interdividende = reste;
+ }
+
+ return resultat;
}
-polynome ply_modulo(polynome poly1, polynome poly2)
+polynome ply_modulo(polynome dividende, polynome diviseur)
{ /* reste de la division de deux polynomes */
- polynome result = NULL;
+ polynome interdividende = dividende, interdiviseur = NULL, inter = NULL, reste = dividende, resultat = NULL, r = NULL;
- return result;
+ while (interdividende->degre >= diviseur->degre) {
+ inter = ply_constr(rat_division(dividende->coef, diviseur->coef), dividende->degre - diviseur->degre);
+ interdiviseur = ply_multiplication(diviseur, inter);
+ r = ply_addition(resultat, inter);
+ reste = ply_soustraction(interdividende, interdiviseur);
+ ply_destruct(resultat);
+ ply_destruct(inter);
+ ply_destruct(interdividende);
+ ply_destruct(interdiviseur);
+ resultat = r;
+ interdividende = reste;
+ }
+
+ return reste;
}
polynome ply_exposant(polynome poly, unsigned int exp)
diff --git a/po/cat-id-tbl.c b/po/cat-id-tbl.c
index 33f4c45..99a737e 100644
--- a/po/cat-id-tbl.c
+++ b/po/cat-id-tbl.c
@@ -33,41 +33,40 @@ const struct _msg_ent _msg_tbl[] = {
{"move_to_resultat_pile()", 24},
{"move_to_resultat_pile: invalid argument type", 25},
{"move_to_resultat_pile: Stack Overflow", 26},
- {"pop_resultat()", 27},
- {"move_to_resultat_pile: empty stack", 28},
- {"Calling act_pile(%i)", 29},
- {"act_pile: OP_PLUS invalid arguments", 30},
- {"act_pile: OP_MOINS invalid arguments", 31},
- {"act_pile: OP_MUL invalid arguments", 32},
- {"act_pile: OP_DIV invalid arguments", 33},
- {"act_pile: OP_MOD invalid arguments", 34},
- {"act_pile: OP_EXP invalid power", 35},
- {"act_pile: OP_EXP empty polynom", 36},
- {"act_pile: OP_EXP invalid arguments", 37},
- {"act_pile: OP_ASSIGN empty string", 38},
- {"act_pile: OP_ASSIGN invalid arguments", 39},
- {"act_pile: OP_MOINS_UNARY invalid argument", 40},
- {"act_pile: OP_FUNC_CALL incorrect value for 2nd arg", 41},
- {"act_pile: OP_FUNC_CALL arg2 is an empty polynom", 42},
- {"act_pile: OP_FUNC_CALL invalid arguments", 43},
- {"act_pile: OP_FUNC_CALL incorrect argument number", 44},
- {"act_pile: Unknown operator", 45},
- {"\t-- Printing Stack\n", 46},
- {"\t-- End Printing Stack\n", 47},
- {"ply_affichage: strcat error, not enough space in buffer", 48},
- {"rat_constr: division by zero", 49},
- {"division by zero", 50},
- {"Signal received: segfault", 51},
- {"Signal received: break", 52},
+ {"move_to_resultat_pile: empty stack", 27},
+ {"Calling act_pile(%i)", 28},
+ {"act_pile: OP_PLUS invalid arguments", 29},
+ {"act_pile: OP_MOINS invalid arguments", 30},
+ {"act_pile: OP_MUL invalid arguments", 31},
+ {"act_pile: OP_DIV invalid arguments", 32},
+ {"act_pile: OP_MOD invalid arguments", 33},
+ {"act_pile: OP_EXP invalid power", 34},
+ {"act_pile: OP_EXP empty polynom", 35},
+ {"act_pile: OP_EXP invalid arguments", 36},
+ {"act_pile: OP_ASSIGN empty string", 37},
+ {"act_pile: OP_ASSIGN invalid arguments", 38},
+ {"act_pile: OP_MOINS_UNARY invalid argument", 39},
+ {"act_pile: OP_FUNC_CALL incorrect value for 2nd arg", 40},
+ {"act_pile: OP_FUNC_CALL arg2 is an empty polynom", 41},
+ {"act_pile: OP_FUNC_CALL invalid arguments", 42},
+ {"act_pile: OP_FUNC_CALL incorrect argument number", 43},
+ {"act_pile: Unknown operator", 44},
+ {"\t-- Printing Stack\n", 45},
+ {"\t-- End Printing Stack\n", 46},
+ {"ply_affichage: strcat error, not enough space in buffer", 47},
+ {"rat_constr: division by zero", 48},
+ {"division by zero", 49},
+ {"Signal received: segfault", 50},
+ {"Signal received: break", 51},
{"\
\n\
Performing initialisation...\n\
-\n", 53},
+\n", 52},
{"\
\n\
Performing shutdown...\n\
-\n", 54},
- {"Exitting, bye!\n", 55},
+\n", 53},
+ {"Exitting, bye!\n", 54},
};
-int _msg_tbl_length = 55;
+int _msg_tbl_length = 54;