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