#include #include /*************/ /* Arbres */ /*************/ typedef enum {Var, Num, Op} Nature; typedef union { char name; int val; struct op { char name; struct tcell *gauche,*droite; } op; } Contenu; typedef struct tcell { Nature nature; Contenu contenu; } *Tree; /* constructeurs des arbres */ Tree new_var(char name) { ... } Tree new_num(int val) { ... } Tree new_op(char name,Tree gauche,Tree droite) { ... } void print_tree(Tree t) { ... } /************************/ /* Piles */ /************************/ typedef struct lcell { Tree val; struct lcell *next; } Cell, *Stack; Stack stack = NULL; Cell *cons(Tree val,Cell *next) { Cell *r; r = (Cell *)malloc(sizeof(Cell)); if ( r == NULL) { fprintf(stderr,"Plus de memoire\n"); exit(-1); } r->val = val; r->next = next; return r; } void afficher(void) { Stack p; printf("["); for (p=stack ; p != NULL ; p = p->next) { print_tree(p->val); if (p->next != NULL) printf(", "); } printf("]"); } Tree pop(void) { Tree r; if (stack == NULL) { fprintf(stderr,"Tentative de depiler une pile vide, adieu\n"); exit(-1); } r = stack->val; stack = stack->next; return r; } void push(Tree i) { stack = cons(i,stack); } Tree derive(Tree t, char var) { } void main(void) { char pgm[] = "xx*xdxd"; char c; int i; Tree r1,r2; printf(" "); afficher(); printf("\n"); for(i=0; pgm[i] != '\0'; i++) { c = pgm[i]; switch (c) { case '+': case '-': case '*': case '/': /* cas des operateurs */ .... case 'd': /* cas de la derivation */ .... default: /* cas des variables et des nombres */ } printf("%c : ",c); afficher(); printf("\n"); } }