Annotation of rpl/src/analyse_notation_rpn.c, revision 1.67

1.1       bertrand    1: /*
                      2: ================================================================================
1.67    ! bertrand    3:   RPL/2 (R) version 4.1.29
        !             4:   Copyright (C) 1989-2018 Dr. BERTRAND Joël
1.1       bertrand    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: 
1.13      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   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 *
1.4       bertrand   39: analyse_rpn(struct_processus *s_etat_processus, unsigned char *chaine_rpn)
1.1       bertrand   40: {
1.4       bertrand   41:    struct_liste_chainee            *l_ancienne_base_pile;
1.1       bertrand   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: 
1.44      bertrand   54:    integer8                        element_en_cours;
                     55:    integer8                        i;
                     56:    integer8                        j;
                     57:    integer8                        nombre_termes;
                     58:    integer8                        registre_compteur_programme;
1.1       bertrand   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: 
1.4       bertrand   70:    l_ancienne_base_pile = (*s_etat_processus).l_base_pile;
1.1       bertrand   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:        {
1.57      bertrand   78:            while((*s_etat_processus).l_base_pile != l_ancienne_base_pile)
                     79:            {
                     80:                if (depilement(s_etat_processus, &((*s_etat_processus)
                     81:                        .l_base_pile), &s_objet) == d_erreur)
                     82:                {
                     83:                    return NULL;
                     84:                }
                     85: 
                     86:                liberation(s_etat_processus, s_objet);
                     87:            }
                     88: 
                     89:            (*s_etat_processus).position_courante = registre_compteur_programme;
                     90:            (*s_etat_processus).definitions_chainees = registre_programme;
                     91:            (*s_etat_processus).instruction_courante = registre_instruction;
                     92:            (*s_etat_processus).autorisation_empilement_programme =
                     93:                    registre_autorisation_empilement;
                     94: 
1.1       bertrand   95:            return NULL;
                     96:        }
                     97: 
1.52      bertrand   98:        (*s_etat_processus).type_en_cours = NON;
1.1       bertrand   99:        recherche_type(s_etat_processus);
                    100:        free((*s_etat_processus).instruction_courante);
                    101: 
                    102:        if ((*s_etat_processus).erreur_execution != d_ex)
                    103:        {
1.4       bertrand  104:            while((*s_etat_processus).l_base_pile != l_ancienne_base_pile)
1.1       bertrand  105:            {
                    106:                if (depilement(s_etat_processus, &((*s_etat_processus)
                    107:                        .l_base_pile), &s_objet) == d_erreur)
                    108:                {
                    109:                    return NULL;
                    110:                }
                    111: 
                    112:                liberation(s_etat_processus, s_objet);
                    113:            }
                    114: 
                    115:            (*s_etat_processus).position_courante = registre_compteur_programme;
                    116:            (*s_etat_processus).definitions_chainees = registre_programme;
                    117:            (*s_etat_processus).instruction_courante = registre_instruction;
                    118:            (*s_etat_processus).autorisation_empilement_programme =
                    119:                    registre_autorisation_empilement;
                    120: 
                    121:            return NULL;
                    122:        }
                    123: 
                    124:        if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCT)
                    125:        {
                    126:            if (strcmp((*((struct_fonction *) (*(*(*s_etat_processus)
                    127:                    .l_base_pile).donnee).objet)).nom_fonction, "->") == 0)
                    128:            {
                    129:                (*s_etat_processus).autorisation_empilement_programme = 'N';
                    130:            }
                    131:            else if (strcmp((*((struct_fonction *) (*(*(*s_etat_processus)
                    132:                    .l_base_pile).donnee).objet)).nom_fonction, "<<") == 0)
                    133:            {
                    134:                (*s_etat_processus).autorisation_empilement_programme = 'Y';
                    135:            }
                    136:        }
                    137: 
                    138:        nombre_termes++;
                    139:    }
                    140: 
                    141:    l_base_liste = NULL;
                    142:    l_element_courant = NULL;
                    143: 
                    144:    for(i = 0; i < nombre_termes; i++)
                    145:    {
                    146:        element_en_cours = nombre_termes - i;
                    147: 
                    148:        if (element_en_cours > 1)
                    149:        {
                    150:            l_liste1 = (*s_etat_processus).l_base_pile;
                    151: 
                    152:            for(j = 2; j < element_en_cours; j++)
                    153:            {
                    154:                l_liste1 = (*l_liste1).suivant;
                    155:            }
                    156: 
                    157:            l_liste2 = (*l_liste1).suivant;
                    158:            (*l_liste1).suivant = (*l_liste2).suivant;
                    159:            (*l_liste2).suivant = (*s_etat_processus).l_base_pile;
                    160:            (*s_etat_processus).l_base_pile = l_liste2;
                    161:        }
                    162: 
                    163:        if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
                    164:                &s_objet) == d_erreur)
                    165:        {
                    166:            return NULL;
                    167:        }
                    168: 
                    169:        l_element_precedent = l_element_courant;
                    170: 
                    171:        if ((l_element_courant = malloc(sizeof(struct_liste_chainee))) == NULL)
                    172:        {
                    173:            return NULL;
                    174:        }
                    175: 
                    176:        (*l_element_courant).suivant = NULL;
                    177:        (*l_element_courant).donnee = s_objet;
                    178: 
                    179:        if (l_element_precedent == NULL)
                    180:        {
                    181:            l_base_liste = l_element_courant;
                    182:        }
                    183:        else
                    184:        {
                    185:            (*l_element_precedent).suivant = l_element_courant;
                    186:        }
                    187:    }
                    188: 
                    189:    (*s_etat_processus).position_courante = registre_compteur_programme;
                    190:    (*s_etat_processus).definitions_chainees = registre_programme;
                    191:    (*s_etat_processus).autorisation_empilement_programme =
                    192:            registre_autorisation_empilement;
                    193:    (*s_etat_processus).instruction_courante = registre_instruction;
                    194:    
                    195:    return l_base_liste;
                    196: }
                    197: 
                    198: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>