Annotation of rpl/src/analyse_notation_rpn.c, revision 1.1
1.1 ! bertrand 1: /*
! 2: ================================================================================
! 3: RPL/2 (R) version 4.0.9
! 4: Copyright (C) 1989-2010 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,
! 40: unsigned char *chaine_rpn)
! 41: {
! 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: unsigned long element_en_cours;
! 55: unsigned long i;
! 56: unsigned long j;
! 57: unsigned long nombre_termes;
! 58: unsigned long 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: nombre_termes = 0;
! 71:
! 72: while((*s_etat_processus).definitions_chainees
! 73: [(*s_etat_processus).position_courante] != d_code_fin_chaine)
! 74: {
! 75: if (recherche_instruction_suivante(s_etat_processus) == d_erreur)
! 76: {
! 77: return NULL;
! 78: }
! 79:
! 80: recherche_type(s_etat_processus);
! 81: free((*s_etat_processus).instruction_courante);
! 82:
! 83: if ((*s_etat_processus).erreur_execution != d_ex)
! 84: {
! 85: for(i = 0; i < nombre_termes; i++)
! 86: {
! 87: if (depilement(s_etat_processus, &((*s_etat_processus)
! 88: .l_base_pile), &s_objet) == d_erreur)
! 89: {
! 90: return NULL;
! 91: }
! 92:
! 93: liberation(s_etat_processus, s_objet);
! 94: }
! 95:
! 96: (*s_etat_processus).position_courante = registre_compteur_programme;
! 97: (*s_etat_processus).definitions_chainees = registre_programme;
! 98: (*s_etat_processus).instruction_courante = registre_instruction;
! 99: (*s_etat_processus).autorisation_empilement_programme =
! 100: registre_autorisation_empilement;
! 101:
! 102: return NULL;
! 103: }
! 104:
! 105: if ((*(*(*s_etat_processus).l_base_pile).donnee).type == FCT)
! 106: {
! 107: if (strcmp((*((struct_fonction *) (*(*(*s_etat_processus)
! 108: .l_base_pile).donnee).objet)).nom_fonction, "->") == 0)
! 109: {
! 110: (*s_etat_processus).autorisation_empilement_programme = 'N';
! 111: }
! 112: else if (strcmp((*((struct_fonction *) (*(*(*s_etat_processus)
! 113: .l_base_pile).donnee).objet)).nom_fonction, "<<") == 0)
! 114: {
! 115: (*s_etat_processus).autorisation_empilement_programme = 'Y';
! 116: }
! 117: }
! 118:
! 119: nombre_termes++;
! 120: }
! 121:
! 122: l_base_liste = NULL;
! 123: l_element_courant = NULL;
! 124:
! 125: for(i = 0; i < nombre_termes; i++)
! 126: {
! 127: element_en_cours = nombre_termes - i;
! 128:
! 129: if (element_en_cours > 1)
! 130: {
! 131: l_liste1 = (*s_etat_processus).l_base_pile;
! 132:
! 133: for(j = 2; j < element_en_cours; j++)
! 134: {
! 135: l_liste1 = (*l_liste1).suivant;
! 136: }
! 137:
! 138: l_liste2 = (*l_liste1).suivant;
! 139: (*l_liste1).suivant = (*l_liste2).suivant;
! 140: (*l_liste2).suivant = (*s_etat_processus).l_base_pile;
! 141: (*s_etat_processus).l_base_pile = l_liste2;
! 142: }
! 143:
! 144: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 145: &s_objet) == d_erreur)
! 146: {
! 147: return NULL;
! 148: }
! 149:
! 150: l_element_precedent = l_element_courant;
! 151:
! 152: if ((l_element_courant = malloc(sizeof(struct_liste_chainee))) == NULL)
! 153: {
! 154: return NULL;
! 155: }
! 156:
! 157: (*l_element_courant).suivant = NULL;
! 158: (*l_element_courant).donnee = s_objet;
! 159:
! 160: if (l_element_precedent == NULL)
! 161: {
! 162: l_base_liste = l_element_courant;
! 163: }
! 164: else
! 165: {
! 166: (*l_element_precedent).suivant = l_element_courant;
! 167: }
! 168: }
! 169:
! 170: (*s_etat_processus).position_courante = registre_compteur_programme;
! 171: (*s_etat_processus).definitions_chainees = registre_programme;
! 172: (*s_etat_processus).autorisation_empilement_programme =
! 173: registre_autorisation_empilement;
! 174: (*s_etat_processus).instruction_courante = registre_instruction;
! 175:
! 176: return l_base_liste;
! 177: }
! 178:
! 179: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>