File:  [local] / rpl / src / analyse_notation_rpn.c
Revision 1.55: download - view: text, annotated - select for diffs - revision graph
Mon Jan 5 13:12:29 2015 UTC (9 years, 4 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_19, HEAD
Mise à jour du copyright et ajout de la gestion de EQV dans les expressions
algébriques.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.19
    4:   Copyright (C) 1989-2015 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Analyseur syntaxique d'une expression RPN
   29: ================================================================================
   30:   Entrées : chaîne de caractères comprenant l'expression RPN
   31: --------------------------------------------------------------------------------
   32:   Sorties : liste chaînée comprenant l'expression sous la forme d'arbre
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: struct_liste_chainee *
   39: analyse_rpn(struct_processus *s_etat_processus, unsigned char *chaine_rpn)
   40: {
   41:     struct_liste_chainee            *l_ancienne_base_pile;
   42:     struct_liste_chainee            *l_base_liste;
   43:     struct_liste_chainee            *l_element_courant;
   44:     struct_liste_chainee            *l_element_precedent;
   45:     struct_liste_chainee            *l_liste1;
   46:     struct_liste_chainee            *l_liste2;
   47: 
   48:     struct_objet                    *s_objet;
   49: 
   50:     unsigned char                   registre_autorisation_empilement;
   51:     unsigned char                   *registre_instruction;
   52:     unsigned char                   *registre_programme;
   53: 
   54:     integer8                        element_en_cours;
   55:     integer8                        i;
   56:     integer8                        j;
   57:     integer8                        nombre_termes;
   58:     integer8                        registre_compteur_programme;
   59: 
   60:     registre_autorisation_empilement = (*s_etat_processus)
   61:             .autorisation_empilement_programme;
   62:     registre_compteur_programme = (*s_etat_processus).position_courante;
   63:     registre_programme = (*s_etat_processus).definitions_chainees;
   64:     registre_instruction = (*s_etat_processus).instruction_courante;
   65: 
   66:     (*s_etat_processus).position_courante = 0;
   67:     (*s_etat_processus).definitions_chainees = chaine_rpn;
   68:     (*s_etat_processus).autorisation_empilement_programme = 'N';
   69: 
   70:     l_ancienne_base_pile = (*s_etat_processus).l_base_pile;
   71:     nombre_termes = 0;
   72: 
   73:     while((*s_etat_processus).definitions_chainees
   74:             [(*s_etat_processus).position_courante] != d_code_fin_chaine)
   75:     {
   76:         if (recherche_instruction_suivante(s_etat_processus) == d_erreur)
   77:         {
   78:             return NULL;
   79:         }
   80: 
   81:         (*s_etat_processus).type_en_cours = NON;
   82:         recherche_type(s_etat_processus);
   83:         free((*s_etat_processus).instruction_courante);
   84: 
   85:         if ((*s_etat_processus).erreur_execution != d_ex)
   86:         {
   87:             while((*s_etat_processus).l_base_pile != l_ancienne_base_pile)
   88:             {
   89:                 if (depilement(s_etat_processus, &((*s_etat_processus)
   90:                         .l_base_pile), &s_objet) == d_erreur)
   91:                 {
   92:                     return NULL;
   93:                 }
   94: 
   95:                 liberation(s_etat_processus, s_objet);
   96:             }
   97: 
   98:             (*s_etat_processus).position_courante = registre_compteur_programme;
   99:             (*s_etat_processus).definitions_chainees = registre_programme;
  100:             (*s_etat_processus).instruction_courante = registre_instruction;
  101:             (*s_etat_processus).autorisation_empilement_programme =
  102:                     registre_autorisation_empilement;
  103: 
  104:             return NULL;
  105:         }
  106: 
  107:         if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCT)
  108:         {
  109:             if (strcmp((*((struct_fonction *) (*(*(*s_etat_processus)
  110:                     .l_base_pile).donnee).objet)).nom_fonction, "->") == 0)
  111:             {
  112:                 (*s_etat_processus).autorisation_empilement_programme = 'N';
  113:             }
  114:             else if (strcmp((*((struct_fonction *) (*(*(*s_etat_processus)
  115:                     .l_base_pile).donnee).objet)).nom_fonction, "<<") == 0)
  116:             {
  117:                 (*s_etat_processus).autorisation_empilement_programme = 'Y';
  118:             }
  119:         }
  120: 
  121:         nombre_termes++;
  122:     }
  123: 
  124:     l_base_liste = NULL;
  125:     l_element_courant = NULL;
  126: 
  127:     for(i = 0; i < nombre_termes; i++)
  128:     {
  129:         element_en_cours = nombre_termes - i;
  130: 
  131:         if (element_en_cours > 1)
  132:         {
  133:             l_liste1 = (*s_etat_processus).l_base_pile;
  134: 
  135:             for(j = 2; j < element_en_cours; j++)
  136:             {
  137:                 l_liste1 = (*l_liste1).suivant;
  138:             }
  139: 
  140:             l_liste2 = (*l_liste1).suivant;
  141:             (*l_liste1).suivant = (*l_liste2).suivant;
  142:             (*l_liste2).suivant = (*s_etat_processus).l_base_pile;
  143:             (*s_etat_processus).l_base_pile = l_liste2;
  144:         }
  145: 
  146:         if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  147:                 &s_objet) == d_erreur)
  148:         {
  149:             return NULL;
  150:         }
  151: 
  152:         l_element_precedent = l_element_courant;
  153: 
  154:         if ((l_element_courant = malloc(sizeof(struct_liste_chainee))) == NULL)
  155:         {
  156:             return NULL;
  157:         }
  158: 
  159:         (*l_element_courant).suivant = NULL;
  160:         (*l_element_courant).donnee = s_objet;
  161: 
  162:         if (l_element_precedent == NULL)
  163:         {
  164:             l_base_liste = l_element_courant;
  165:         }
  166:         else
  167:         {
  168:             (*l_element_precedent).suivant = l_element_courant;
  169:         }
  170:     }
  171: 
  172:     (*s_etat_processus).position_courante = registre_compteur_programme;
  173:     (*s_etat_processus).definitions_chainees = registre_programme;
  174:     (*s_etat_processus).autorisation_empilement_programme =
  175:             registre_autorisation_empilement;
  176:     (*s_etat_processus).instruction_courante = registre_instruction;
  177:     
  178:     return l_base_liste;
  179: }
  180: 
  181: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>