![]() ![]() | ![]() |
1.1 bertrand 1: /*
2: ================================================================================
1.83 ! bertrand 3: RPL/2 (R) version 4.1.23
1.70 bertrand 4: Copyright (C) 1989-2015 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:
1.70 bertrand 22:
1.15 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
28: Procédure de vérification syntaxique du source et de précompilation
29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: - renvoi : erreur
34: --------------------------------------------------------------------------------
35: Effets de bord :
36: ================================================================================
37: */
38:
39: logical1
40: compilation(struct_processus *s_etat_processus)
41: {
42: struct_objet *s_objet;
43:
44: struct_variable *s_variable;
45:
46: unsigned char apostrophe_ouverte;
47: unsigned char apostrophe_ouverte_registre;
48: unsigned char caractere_courant;
49: unsigned char caractere_precedent;
50: unsigned char caractere_suivant;
51: unsigned char *definition;
52: unsigned char fermeture_definition;
53: unsigned char guillemet_ouvert;
54: unsigned char ouverture_definition;
55: unsigned char position_debut_nom_definition_valide;
56:
1.58 bertrand 57: integer8 *adresse;
58: integer8 i;
59: integer8 niveau_definition;
60: integer8 niveau_definition_registre;
61: integer8 position_courante;
62: integer8 position_debut_nom_definition;
63: integer8 position_fin_nom_definition;
64: integer8 validation;
65: integer8 validation_registre;
1.1 bertrand 66:
67: (*s_etat_processus).erreur_compilation = d_ec;
68: (*s_etat_processus).erreur_systeme = d_es;
69: (*s_etat_processus).erreur_execution = d_ex;
70: (*s_etat_processus).exception = d_ep;
71: (*s_etat_processus).arret_si_exception = d_vrai;
72:
73: (*s_etat_processus).position_courante = 0;
74:
75: /*
76: --------------------------------------------------------------------------------
77: Recheche des définitions
78: --------------------------------------------------------------------------------
79: */
80:
81: niveau_definition = 0;
82: niveau_definition_registre = 0;
83: position_courante = 0;
84: position_debut_nom_definition = 0;
85: validation = 0;
86:
87: apostrophe_ouverte = d_faux;
88: apostrophe_ouverte_registre = d_faux;
89: guillemet_ouvert = d_faux;
90: position_debut_nom_definition_valide = d_faux;
91:
92: if ((*s_etat_processus).debug == d_vrai)
93: if (((*s_etat_processus).type_debug & d_debug_analyse) != 0)
94: {
95: printf("\n");
96: printf("[%d] Compilation\n", (int) getpid());
97: fflush(stdout);
98: }
99:
100: while((*s_etat_processus).definitions_chainees[position_courante] !=
101: d_code_fin_chaine)
102: {
103: caractere_courant = (*s_etat_processus)
104: .definitions_chainees[position_courante];
105:
106: fermeture_definition = d_faux;
107: ouverture_definition = d_faux;
108:
109: if (position_courante >= 1)
110: {
111: if (position_courante >= 2)
112: {
113: if (((*s_etat_processus).definitions_chainees
114: [position_courante - 2] == '\\') &&
115: ((*s_etat_processus).definitions_chainees
116: [position_courante - 1] == '\\'))
117: {
118: caractere_precedent = '*';
119: }
120: else
121: {
122: caractere_precedent = (*s_etat_processus)
123: .definitions_chainees[position_courante - 1];
124: }
125: }
126: else
127: {
128: caractere_precedent = (*s_etat_processus)
129: .definitions_chainees[position_courante - 1];
130: }
131: }
132: else
133: {
134: caractere_precedent = ' ';
135: }
136:
137: caractere_suivant = (*s_etat_processus)
138: .definitions_chainees[position_courante + 1];
139:
140: if (caractere_suivant == d_code_fin_chaine)
141: {
142: caractere_suivant = ' ';
143: }
144:
145: if ((caractere_courant == '[') || (caractere_courant == '{'))
146: {
147: validation++;
148: }
149: else if ((caractere_courant == ']') || (caractere_courant == '}'))
150: {
151: validation--;
152: }
153: else if (caractere_courant == '\'')
154: {
155: if (apostrophe_ouverte == d_faux)
156: {
157: validation++;
158: apostrophe_ouverte = d_vrai;
159: }
160: else
161: {
162: validation--;
163: apostrophe_ouverte = d_faux;
164: }
165: }
166: else if (caractere_courant == '"')
167: {
168: if (caractere_precedent != '\\')
169: {
170: swap((void *) &validation, (void *) &validation_registre,
171: sizeof(validation));
172: swap((void *) &apostrophe_ouverte,
173: (void *) &apostrophe_ouverte_registre,
174: sizeof(apostrophe_ouverte));
175: swap((void *) &niveau_definition,
176: (void *) &niveau_definition_registre,
177: sizeof(niveau_definition));
178:
179: guillemet_ouvert = (guillemet_ouvert == d_faux)
180: ? d_vrai : d_faux;
181: }
182: }
183: else if ((caractere_courant == '<') &&
184: (caractere_precedent == ' ') &&
185: (caractere_suivant == '<'))
186: {
187: if ((*s_etat_processus)
188: .definitions_chainees[position_courante + 2] == ' ')
189: {
190: niveau_definition++;
191: ouverture_definition = d_vrai;
192: }
193: }
194: else if ((caractere_courant == '>') &&
195: (caractere_precedent == ' ') &&
196: (caractere_suivant == '>'))
197: {
198: if (((*s_etat_processus)
199: .definitions_chainees[position_courante + 2] == ' ') ||
200: ((*s_etat_processus).definitions_chainees
201: [position_courante + 2] == d_code_fin_chaine))
202: {
203: if (niveau_definition == 0)
204: {
205: (*s_etat_processus).erreur_compilation =
206: d_ec_niveau_definition_negatif;
207: return(d_erreur);
208: }
209: else
210: {
211: niveau_definition--;
212: fermeture_definition = d_vrai;
213: position_courante++;
214: }
215: }
216: }
217:
218: if ((niveau_definition == 0) && (guillemet_ouvert == d_faux) &&
219: (caractere_courant != ' ') && (fermeture_definition == d_faux))
220: {
221: if (position_debut_nom_definition_valide == d_faux)
222: {
223: position_debut_nom_definition_valide = d_vrai;
224: position_debut_nom_definition = position_courante;
225: }
226: }
227:
228: if (((niveau_definition == 1) && (ouverture_definition == d_vrai)) &&
229: (position_debut_nom_definition_valide == d_vrai))
230: {
231: position_fin_nom_definition = position_courante - 1;
232: position_debut_nom_definition_valide = d_faux;
233:
234: while((*s_etat_processus).definitions_chainees
235: [position_fin_nom_definition] == ' ')
236: {
237: position_fin_nom_definition--;
238: }
239:
240: i = position_debut_nom_definition;
241:
242: while(i <= position_fin_nom_definition)
243: {
244: if ((*s_etat_processus).definitions_chainees[i] == ' ')
245: {
246: (*s_etat_processus).erreur_compilation =
247: d_ec_nom_definition_invalide;
248: return(d_erreur);
249: }
250: else
251: {
252: i++;
253: }
254: }
255:
256: s_objet = allocation(s_etat_processus, ADR);
257: s_variable = (struct_variable *)
258: malloc(sizeof(struct_variable));
259: adresse = (*s_objet).objet;
1.58 bertrand 260: definition = (unsigned char *) malloc(((size_t)
1.1 bertrand 261: (position_fin_nom_definition -
1.58 bertrand 262: position_debut_nom_definition + 2)) *
1.1 bertrand 263: sizeof(unsigned char));
264:
265: if ((s_objet == NULL) || (s_variable == NULL) ||
266: (adresse == NULL) || definition == NULL)
267: {
268: (*s_etat_processus).erreur_systeme =
269: d_es_allocation_memoire;
270: return(d_erreur);
271: }
272: else
273: {
274: (*adresse) = position_fin_nom_definition + 1;
275:
276: (*s_variable).nom = definition;
277: (*s_variable).niveau = (*s_etat_processus).niveau_courant;
278: (*s_variable).objet = s_objet;
279:
280: i = position_debut_nom_definition;
281:
282: while(i <= position_fin_nom_definition)
283: {
1.73 bertrand 284: if ((*s_etat_processus).pointeurs_caracteres_variables
285: [(*s_etat_processus).definitions_chainees[i]] < 0)
286: {
287: free(s_variable);
288:
289: (*s_etat_processus).erreur_execution = d_ex_syntaxe;
290: return(d_erreur);
291: }
292:
1.1 bertrand 293: *(definition++) = (*s_etat_processus)
294: .definitions_chainees[i++];
295: }
296:
297: *definition = d_code_fin_chaine;
298:
299: if (recherche_variable(s_etat_processus, (*s_variable).nom)
300: == d_vrai)
301: {
1.73 bertrand 302: free(s_variable);
303:
1.1 bertrand 304: if ((*s_etat_processus).langue == 'F')
305: {
306: printf("+++Attention : Plusieurs définitions de"
307: " même nom\n");
308: }
309: else
310: {
311: printf("+++Warning : Same name for several"
312: " definitions\n");
313: }
314:
315: fflush(stdout);
316: return(d_erreur);
317: }
318:
319: (*s_etat_processus).erreur_systeme = d_es;
320: creation_variable(s_etat_processus, s_variable, 'V', 'P');
321:
322: if ((*s_etat_processus).erreur_systeme != d_es)
323: {
324: free(s_variable);
325: return(d_erreur);
326: }
327:
328: if ((*s_etat_processus).debug == d_vrai)
329: if (((*s_etat_processus).type_debug & d_debug_analyse) != 0)
330: {
331: if ((*s_etat_processus).langue == 'F')
332: {
333: printf("[%d] Compilation : Définition %s ($ %016lX) "
334: "\n", (int) getpid(), (*s_variable).nom,
335: (*adresse));
336: }
337: else
338: {
339: printf("[%d] Compilation : %s definition ($ %016lX) "
340: "\n", (int) getpid(), (*s_variable).nom,
341: (*adresse));
342: }
343:
344: fflush(stdout);
345: }
346: }
347:
348: free(s_variable);
349: }
350:
351: position_courante++;
352: }
353:
354: return(analyse_syntaxique(s_etat_processus));
355: }
356:
357:
358: /*
359: ================================================================================
360: Procédure de d'analyse syntaxique du source
361: ================================================================================
362: Entrées :
363: --------------------------------------------------------------------------------
364: Sorties :
365: - renvoi : erreur
366: --------------------------------------------------------------------------------
367: Effets de bord :
368: ================================================================================
369: */
370:
1.50 bertrand 371: enum t_condition { AN_IF = 1, AN_IFERR, AN_THEN, AN_ELSE, AN_ELSEIF,
372: AN_END, AN_DO, AN_UNTIL, AN_WHILE, AN_REPEAT, AN_SELECT,
373: AN_CASE, AN_DEFAULT, AN_UP, AN_DOWN, AN_FOR, AN_START,
374: AN_NEXT, AN_STEP, AN_CRITICAL, AN_FORALL };
375:
376: typedef struct pile
377: {
378: enum t_condition condition;
379: struct pile *suivant;
380: } struct_pile_analyse;
381:
382: static inline struct_pile_analyse *
1.72 bertrand 383: empilement_analyse(struct_processus *s_etat_processus,
384: struct_pile_analyse *ancienne_base,
1.50 bertrand 385: enum t_condition condition)
1.1 bertrand 386: {
1.50 bertrand 387: struct_pile_analyse *nouvelle_base;
388:
389: if ((nouvelle_base = malloc(sizeof(struct_pile_analyse))) == NULL)
390: {
391: return(NULL);
392: }
1.1 bertrand 393:
1.50 bertrand 394: (*nouvelle_base).suivant = ancienne_base;
395: (*nouvelle_base).condition = condition;
1.1 bertrand 396:
1.50 bertrand 397: return(nouvelle_base);
398: }
1.1 bertrand 399:
1.50 bertrand 400: static inline struct_pile_analyse *
1.72 bertrand 401: depilement_analyse(struct_processus *s_etat_processus,
402: struct_pile_analyse *ancienne_base)
1.50 bertrand 403: {
404: struct_pile_analyse *nouvelle_base;
1.1 bertrand 405:
1.50 bertrand 406: if (ancienne_base == NULL)
1.1 bertrand 407: {
1.50 bertrand 408: return(NULL);
409: }
1.1 bertrand 410:
1.50 bertrand 411: nouvelle_base = (*ancienne_base).suivant;
412: free(ancienne_base);
1.1 bertrand 413:
1.50 bertrand 414: return(nouvelle_base);
415: }
1.1 bertrand 416:
1.50 bertrand 417: static inline logical1
418: test_analyse(struct_pile_analyse *l_base_pile, enum t_condition condition)
419: {
420: if (l_base_pile == NULL)
421: {
422: return(d_faux);
1.1 bertrand 423: }
424:
1.50 bertrand 425: return(((*l_base_pile).condition == condition) ? d_vrai : d_faux);
426: }
1.1 bertrand 427:
1.50 bertrand 428: static inline void
1.72 bertrand 429: liberation_analyse(struct_processus *s_etat_processus,
430: struct_pile_analyse *l_base_pile)
1.50 bertrand 431: {
432: struct_pile_analyse *l_nouvelle_base_pile;
1.1 bertrand 433:
1.50 bertrand 434: while(l_base_pile != NULL)
1.1 bertrand 435: {
1.50 bertrand 436: l_nouvelle_base_pile = (*l_base_pile).suivant;
437: free(l_base_pile);
438: l_base_pile = l_nouvelle_base_pile;
1.1 bertrand 439: }
440:
1.50 bertrand 441: return;
442: }
1.1 bertrand 443:
1.50 bertrand 444: logical1
445: analyse_syntaxique(struct_processus *s_etat_processus)
446: {
447: unsigned char *instruction;
448: unsigned char registre;
1.1 bertrand 449:
1.50 bertrand 450: struct_pile_analyse *l_base_pile;
451: struct_pile_analyse *l_nouvelle_base_pile;
1.1 bertrand 452:
453: l_base_pile = NULL;
454: l_nouvelle_base_pile = NULL;
455:
456: if ((*s_etat_processus).debug == d_vrai)
457: if (((*s_etat_processus).type_debug & d_debug_analyse) != 0)
458: {
459: if ((*s_etat_processus).langue == 'F')
460: {
461: printf("[%d] Analyse\n", (int) getpid());
462: }
463: else
464: {
465: printf("[%d] Analysis\n", (int) getpid());
466: }
467:
468: fflush(stdout);
469: }
470:
471: (*s_etat_processus).position_courante = 0;
472: registre = (*s_etat_processus).autorisation_empilement_programme;
473: (*s_etat_processus).autorisation_empilement_programme = 'N';
474:
475: /*
476: --------------------------------------------------------------------------------
477: Analyse structurelle
478: --------------------------------------------------------------------------------
479: */
480:
481: while((*s_etat_processus).definitions_chainees
482: [(*s_etat_processus).position_courante] != d_code_fin_chaine)
483: {
484: if (recherche_instruction_suivante(s_etat_processus) !=
485: d_absence_erreur)
486: {
1.72 bertrand 487: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 488:
489: (*s_etat_processus).autorisation_empilement_programme = registre;
490: return(d_erreur);
491: }
492:
1.72 bertrand 493: if ((instruction = conversion_majuscule(s_etat_processus,
1.1 bertrand 494: (*s_etat_processus).instruction_courante)) == NULL)
495: {
1.72 bertrand 496: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 497:
498: (*s_etat_processus).autorisation_empilement_programme = registre;
499: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
500: return(d_erreur);
501: }
502:
503: if (strcmp(instruction, "IF") == 0)
504: {
1.72 bertrand 505: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
506: l_base_pile, AN_IF)) == NULL)
1.1 bertrand 507: {
1.72 bertrand 508: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 509:
510: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
511: return(d_erreur);
512: }
513:
514: l_base_pile = l_nouvelle_base_pile;
515: (*l_base_pile).condition = AN_IF;
516: }
517: else if (strcmp(instruction, "IFERR") == 0)
518: {
1.72 bertrand 519: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
520: l_base_pile, AN_IFERR)) == NULL)
1.1 bertrand 521: {
1.72 bertrand 522: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 523:
524: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
525: return(d_erreur);
526: }
527:
528: l_base_pile = l_nouvelle_base_pile;
529: }
1.48 bertrand 530: else if (strcmp(instruction, "CRITICAL") == 0)
531: {
1.72 bertrand 532: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
533: l_base_pile, AN_CRITICAL)) == NULL)
1.48 bertrand 534: {
1.72 bertrand 535: liberation_analyse(s_etat_processus, l_base_pile);
1.48 bertrand 536:
537: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
538: return(d_erreur);
539: }
540:
541: l_base_pile = l_nouvelle_base_pile;
542: }
1.1 bertrand 543: else if (strcmp(instruction, "THEN") == 0)
544: {
545: if ((test_analyse(l_base_pile, AN_IF) == d_faux) &&
546: (test_analyse(l_base_pile, AN_ELSEIF) == d_faux) &&
547: (test_analyse(l_base_pile, AN_CASE) == d_faux) &&
548: (test_analyse(l_base_pile, AN_IFERR) == d_faux))
549: {
1.72 bertrand 550: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 551:
552: (*s_etat_processus).autorisation_empilement_programme =
553: registre;
554:
555: (*s_etat_processus).erreur_compilation =
556: d_ec_erreur_instruction_then;
557: return(d_erreur);
558: }
559:
560: (*l_base_pile).condition = AN_THEN;
561: }
562: else if (strcmp(instruction, "ELSE") == 0)
563: {
564: if (test_analyse(l_base_pile, AN_THEN) == d_faux)
565: {
1.72 bertrand 566: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 567:
568: (*s_etat_processus).autorisation_empilement_programme =
569: registre;
570:
571: (*s_etat_processus).erreur_compilation =
572: d_ec_erreur_instruction_else;
573: return(d_erreur);
574: }
575:
576: (*l_base_pile).condition = AN_ELSE;
577: }
578: else if (strcmp(instruction, "ELSEIF") == 0)
579: {
580: if (test_analyse(l_base_pile, AN_THEN) == d_faux)
581: {
1.72 bertrand 582: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 583:
584: (*s_etat_processus).autorisation_empilement_programme =
585: registre;
586:
587: (*s_etat_processus).erreur_compilation =
588: d_ec_erreur_instruction_elseif;
589: return(d_erreur);
590: }
591:
592: (*l_base_pile).condition = AN_ELSEIF;
593: }
594: else if (strcmp(instruction, "END") == 0)
595: {
596: if ((test_analyse(l_base_pile, AN_UNTIL) == d_faux) &&
597: (test_analyse(l_base_pile, AN_REPEAT) == d_faux) &&
598: (test_analyse(l_base_pile, AN_DEFAULT) == d_faux) &&
599: (test_analyse(l_base_pile, AN_SELECT) == d_faux) &&
600: (test_analyse(l_base_pile, AN_THEN) == d_faux) &&
1.48 bertrand 601: (test_analyse(l_base_pile, AN_CRITICAL) == d_faux) &&
1.1 bertrand 602: (test_analyse(l_base_pile, AN_ELSE) == d_faux))
603: {
1.72 bertrand 604: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 605:
606: (*s_etat_processus).autorisation_empilement_programme =
607: registre;
608:
609: (*s_etat_processus).erreur_compilation =
610: d_ec_erreur_instruction_end;
611: return(d_erreur);
612: }
613:
1.72 bertrand 614: l_base_pile = depilement_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 615: }
616: else if (strcmp(instruction, "DO") == 0)
617: {
1.72 bertrand 618: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
619: l_base_pile, AN_DO)) == NULL)
1.1 bertrand 620: {
1.72 bertrand 621: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 622:
623: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
624: return(d_erreur);
625: }
626:
627: l_base_pile = l_nouvelle_base_pile;
628: }
629: else if (strcmp(instruction, "UNTIL") == 0)
630: {
631: if (test_analyse(l_base_pile, AN_DO) == d_faux)
632: {
1.72 bertrand 633: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 634:
635: (*s_etat_processus).autorisation_empilement_programme =
636: registre;
637:
638: (*s_etat_processus).erreur_compilation =
639: d_ec_erreur_instruction_until;
640: return(d_erreur);
641: }
642:
643: (*l_base_pile).condition = AN_UNTIL;
644: }
645: else if (strcmp(instruction, "WHILE") == 0)
646: {
1.72 bertrand 647: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
648: l_base_pile, AN_WHILE)) == NULL)
1.1 bertrand 649: {
1.72 bertrand 650: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 651:
652: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
653: return(d_erreur);
654: }
655:
656: l_base_pile = l_nouvelle_base_pile;
657: }
658: else if (strcmp(instruction, "REPEAT") == 0)
659: {
660: if (test_analyse(l_base_pile, AN_WHILE) == d_faux)
661: {
1.72 bertrand 662: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 663:
664: (*s_etat_processus).autorisation_empilement_programme =
665: registre;
666:
667: (*s_etat_processus).erreur_compilation =
668: d_ec_erreur_instruction_while;
669: return(d_erreur);
670: }
671:
672: (*l_base_pile).condition = AN_REPEAT;
673: }
674: else if (strcmp(instruction, "SELECT") == 0)
675: {
1.72 bertrand 676: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
677: l_base_pile, AN_SELECT)) == NULL)
1.1 bertrand 678: {
1.72 bertrand 679: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 680:
681: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
682: return(d_erreur);
683: }
684:
685: l_base_pile = l_nouvelle_base_pile;
686: }
687: else if (strcmp(instruction, "CASE") == 0)
688: {
689: if (test_analyse(l_base_pile, AN_SELECT) == d_faux)
690: {
1.72 bertrand 691: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 692:
693: (*s_etat_processus).autorisation_empilement_programme =
694: registre;
695:
696: (*s_etat_processus).erreur_compilation =
697: d_ec_erreur_instruction_case;
698: return(d_erreur);
699: }
700:
1.72 bertrand 701: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
702: l_base_pile, AN_CASE)) == NULL)
1.1 bertrand 703: {
1.72 bertrand 704: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 705:
706: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
707: return(d_erreur);
708: }
709:
710: l_base_pile = l_nouvelle_base_pile;
711: }
712: else if (strcmp(instruction, "DEFAULT") == 0)
713: {
714: if (test_analyse(l_base_pile, AN_SELECT) == d_faux)
715: {
1.72 bertrand 716: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 717:
718: (*s_etat_processus).autorisation_empilement_programme =
719: registre;
720:
721: (*s_etat_processus).erreur_compilation =
722: d_ec_erreur_instruction_select;
723: return(d_erreur);
724: }
725:
726: (*l_base_pile).condition = AN_DEFAULT;
727: }
728: else if (strcmp(instruction, "<<") == 0)
729: {
1.72 bertrand 730: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
731: l_base_pile, AN_UP)) == NULL)
1.1 bertrand 732: {
1.72 bertrand 733: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 734:
735: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
736: return(d_erreur);
737: }
738:
739: l_base_pile = l_nouvelle_base_pile;
740: }
741: else if (strcmp(instruction, ">>") == 0)
742: {
743: if (test_analyse(l_base_pile, AN_UP) == d_faux)
744: {
1.72 bertrand 745: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 746:
747: (*s_etat_processus).autorisation_empilement_programme =
748: registre;
749:
750: (*s_etat_processus).erreur_compilation =
751: d_ec_source_incoherent;
752: return(d_erreur);
753: }
754:
1.72 bertrand 755: l_base_pile = depilement_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 756: }
757: else if (strcmp(instruction, "FOR") == 0)
758: {
1.72 bertrand 759: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
760: l_base_pile, AN_FOR)) == NULL)
1.1 bertrand 761: {
1.72 bertrand 762: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 763:
764: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
765: return(d_erreur);
766: }
767:
768: l_base_pile = l_nouvelle_base_pile;
769: }
770: else if (strcmp(instruction, "START") == 0)
771: {
1.72 bertrand 772: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
773: l_base_pile, AN_START)) == NULL)
1.1 bertrand 774: {
1.72 bertrand 775: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 776:
777: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
778: return(d_erreur);
779: }
780:
781: l_base_pile = l_nouvelle_base_pile;
782: }
1.49 bertrand 783: else if (strcmp(instruction, "FORALL") == 0)
784: {
1.72 bertrand 785: if ((l_nouvelle_base_pile = empilement_analyse(s_etat_processus,
786: l_base_pile, AN_FORALL)) == NULL)
1.49 bertrand 787: {
1.72 bertrand 788: liberation_analyse(s_etat_processus, l_base_pile);
1.49 bertrand 789:
790: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
791: return(d_erreur);
792: }
793:
794: l_base_pile = l_nouvelle_base_pile;
795: }
1.1 bertrand 796: else if (strcmp(instruction, "NEXT") == 0)
797: {
798: if ((test_analyse(l_base_pile, AN_FOR) == d_faux) &&
1.49 bertrand 799: (test_analyse(l_base_pile, AN_FORALL) == d_faux) &&
1.1 bertrand 800: (test_analyse(l_base_pile, AN_START) == d_faux))
801: {
1.72 bertrand 802: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 803:
804: (*s_etat_processus).autorisation_empilement_programme =
805: registre;
806:
807: (*s_etat_processus).erreur_compilation =
808: d_ec_erreur_boucle_definie;
809: return(d_erreur);
810: }
811:
1.72 bertrand 812: l_base_pile = depilement_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 813: }
814: else if (strcmp(instruction, "STEP") == 0)
815: {
816: if ((test_analyse(l_base_pile, AN_FOR) == d_faux) &&
817: (test_analyse(l_base_pile, AN_START) == d_faux))
818: {
1.72 bertrand 819: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 820:
821: (*s_etat_processus).autorisation_empilement_programme =
822: registre;
823:
824: (*s_etat_processus).erreur_compilation =
825: d_ec_erreur_boucle_definie;
826: return(d_erreur);
827: }
828:
1.72 bertrand 829: l_base_pile = depilement_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 830: }
831:
832: // Invalidation de l'instruction courante dans le fichier rpl-core
833: free((*s_etat_processus).instruction_courante);
834: (*s_etat_processus).instruction_courante = NULL;
835: free(instruction);
836: }
837:
838: (*s_etat_processus).autorisation_empilement_programme = registre;
839:
840: if (l_base_pile != NULL)
841: {
1.72 bertrand 842: liberation_analyse(s_etat_processus, l_base_pile);
1.1 bertrand 843:
844: (*s_etat_processus).autorisation_empilement_programme = registre;
845: (*s_etat_processus).erreur_compilation = d_ec_source_incoherent;
846: return(d_erreur);
847: }
848:
849: return(d_absence_erreur);
850: }
851:
852:
853: /*
854: ================================================================================
855: Routine d'échange de deux variables
856: ================================================================================
857: Entrées :
858: - pointeurs génériques sur les deux variables,
859: - longueur en octet des objets à permuter.
860: --------------------------------------------------------------------------------
861: Sorties : idem.
862: --------------------------------------------------------------------------------
863: Effets de bord : néant.
864: ================================================================================
865: */
866:
867: void
1.57 bertrand 868: swap(void *variable_1, void *variable_2, integer8 taille)
1.1 bertrand 869: {
870: register unsigned char *t_var_1;
871: register unsigned char *t_var_2;
872: register unsigned char variable_temporaire;
873:
1.57 bertrand 874: register integer8 i;
1.1 bertrand 875:
876: t_var_1 = (unsigned char *) variable_1;
877: t_var_2 = (unsigned char *) variable_2;
878:
1.14 bertrand 879: for(i = 0; i < taille; i++)
1.1 bertrand 880: {
1.14 bertrand 881: variable_temporaire = (*t_var_1);
882: (*(t_var_1++)) = (*t_var_2);
883: (*(t_var_2++)) = variable_temporaire;
1.1 bertrand 884: }
1.14 bertrand 885:
886: return;
1.1 bertrand 887: }
888:
889:
890: /*
891: ================================================================================
892: Routine recherchant l'instruction suivante dans le programme compilé
893: ================================================================================
894: Entrée :
895: --------------------------------------------------------------------------------
896: Sortie :
897: --------------------------------------------------------------------------------
898: Effets de bord : néant.
899: ================================================================================
900: */
901:
902: logical1
903: recherche_instruction_suivante(struct_processus *s_etat_processus)
904: {
1.69 bertrand 905: return(recherche_instruction_suivante_recursive(s_etat_processus, 0));
906: }
907:
908: logical1
909: recherche_instruction_suivante_recursive(struct_processus *s_etat_processus,
910: integer8 recursivite)
911: {
1.68 bertrand 912: enum t_type registre_type_en_cours;
913:
1.1 bertrand 914: logical1 drapeau_fin_objet;
915: logical1 erreur;
1.60 bertrand 916:
917: int erreur_analyse;
918: int erreur_format;
1.1 bertrand 919:
920: unsigned char base_binaire;
1.68 bertrand 921: unsigned char caractere_fin;
1.1 bertrand 922: unsigned char *pointeur_caractere_courant;
923: unsigned char *pointeur_caractere_destination;
924: unsigned char *pointeur_debut_instruction;
925: unsigned char *pointeur_fin_instruction;
926:
927: signed long niveau;
928:
929: erreur_analyse = d_ex;
930: erreur_format = d_ex;
931: erreur = d_absence_erreur;
932:
1.68 bertrand 933: switch((*s_etat_processus).type_en_cours)
934: {
935: case RPN:
936: {
937: caractere_fin = '>';
938: break;
939: }
940:
941: case LST:
942: {
943: caractere_fin = '}';
944: break;
945: }
946:
947: case TBL:
948: {
949: caractere_fin = ']';
950: break;
951: }
952:
953: default:
954: {
955: caractere_fin = d_code_espace;
956: break;
957: }
958: }
959:
1.1 bertrand 960: drapeau_fin_objet = d_faux;
961: niveau = 0;
962:
963: pointeur_caractere_courant = (*s_etat_processus).definitions_chainees +
964: (*s_etat_processus).position_courante;
965:
966: while(((*pointeur_caractere_courant) == d_code_espace) &&
967: ((*pointeur_caractere_courant) != d_code_fin_chaine))
968: {
969: pointeur_caractere_courant++;
970: }
971:
972: if ((*pointeur_caractere_courant) == d_code_fin_chaine)
973: {
974: (*s_etat_processus).instruction_courante = (unsigned char *)
975: malloc(sizeof(unsigned char));
976:
977: if ((*s_etat_processus).instruction_courante == NULL)
978: {
979: erreur = d_erreur;
980: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
981: }
982: else
983: {
984: erreur = d_absence_erreur;
985: (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
986: (*s_etat_processus).position_courante = pointeur_caractere_courant
987: - (*s_etat_processus).definitions_chainees;
988: }
989:
990: return(erreur);
991: }
992:
993: pointeur_debut_instruction = pointeur_caractere_courant;
994:
995: while(((*pointeur_caractere_courant) != d_code_espace) &&
996: ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
997: (drapeau_fin_objet == d_faux) &&
1.68 bertrand 998: (erreur_analyse == d_ex) && (erreur_format == d_ex))
1.1 bertrand 999: {
1000: switch(*pointeur_caractere_courant++)
1001: {
1002: case ']' :
1003: case '}' :
1.56 bertrand 1004: {
1005: break;
1006: }
1007:
1.1 bertrand 1008: case ')' :
1009: {
1010: erreur_format = d_ex_syntaxe;
1011: break;
1012: }
1013:
1014: case '"' :
1015: {
1016: if (pointeur_debut_instruction !=
1017: (pointeur_caractere_courant - 1))
1018: {
1019: erreur_format = d_ex_syntaxe;
1020: }
1021:
1022: while((*pointeur_caractere_courant != '"') &&
1023: ((*pointeur_caractere_courant) != d_code_fin_chaine))
1024: {
1025: if (*pointeur_caractere_courant == '\\')
1026: {
1027: pointeur_caractere_courant++;
1028:
1029: switch(*pointeur_caractere_courant)
1030: {
1031: case '\\' :
1032: case '"' :
1033: {
1034: pointeur_caractere_courant++;
1035: break;
1036: }
1037: }
1038: }
1039: else
1040: {
1041: pointeur_caractere_courant++;
1042: }
1043: }
1044:
1045: if ((*pointeur_caractere_courant) != '"')
1046: {
1047: erreur_analyse = d_ex_syntaxe;
1048: }
1049:
1050: if (erreur_analyse == d_ex)
1051: {
1052: pointeur_caractere_courant++;
1053: }
1054:
1055: drapeau_fin_objet = d_vrai;
1056: break;
1057: }
1058:
1059: case '\'' :
1060: {
1061: if (pointeur_debut_instruction !=
1062: (pointeur_caractere_courant - 1))
1063: {
1064: erreur_format = d_ex_syntaxe;
1065: }
1066:
1067: while(((*pointeur_caractere_courant) != '\'') &&
1068: ((*pointeur_caractere_courant) != d_code_fin_chaine))
1069: {
1070: if ((*pointeur_caractere_courant) == '(')
1071: {
1072: niveau++;
1073: }
1074: else if ((*pointeur_caractere_courant) == ')')
1075: {
1076: niveau--;
1077: }
1078:
1079: pointeur_caractere_courant++;
1080: }
1081:
1082: if ((*pointeur_caractere_courant) != '\'')
1083: {
1084: erreur_analyse = d_ex_syntaxe;
1085: }
1086: else if (niveau != 0)
1087: {
1088: erreur_analyse = d_ex_syntaxe;
1089: }
1090:
1091: if (erreur_analyse == d_ex)
1092: {
1093: pointeur_caractere_courant++;
1094: }
1095:
1096: drapeau_fin_objet = d_vrai;
1097: break;
1098: }
1099:
1100: case '(' :
1101: {
1102: if (pointeur_debut_instruction !=
1103: (pointeur_caractere_courant - 1))
1104: {
1105: erreur_format = d_ex_syntaxe;
1106: }
1107:
1108: while(((*pointeur_caractere_courant) != ')') &&
1109: ((*pointeur_caractere_courant) != d_code_fin_chaine)
1110: && (erreur_analyse == d_ex))
1111: {
1112: switch(*pointeur_caractere_courant)
1113: {
1114: case '0' :
1115: case '1' :
1116: case '2' :
1117: case '3' :
1118: case '4' :
1119: case '5' :
1120: case '6' :
1121: case '7' :
1122: case '8' :
1123: case '9' :
1124: case 'e' :
1125: case 'E' :
1126: case ',' :
1127: case '.' :
1128: case ' ' :
1129: case '-' :
1130: case '+' :
1131: case ')' :
1132: {
1133: break;
1134: }
1135:
1136: default :
1137: {
1138: erreur_analyse = d_ex_syntaxe;
1139: break;
1140: }
1141: }
1142:
1143: pointeur_caractere_courant++;
1144: }
1145:
1146: if ((*pointeur_caractere_courant) != ')')
1147: {
1148: erreur_analyse = d_ex_syntaxe;
1149: }
1150:
1151: if (erreur_analyse == d_ex)
1152: {
1153: pointeur_caractere_courant++;
1154: }
1155:
1156: drapeau_fin_objet = d_vrai;
1157: break;
1158: }
1159:
1160: case '#' :
1161: {
1162: if (pointeur_debut_instruction !=
1163: (pointeur_caractere_courant - 1))
1164: {
1165: erreur_format = d_ex_syntaxe;
1166: }
1167:
1168: while(((*pointeur_caractere_courant) != 'b') &&
1169: ((*pointeur_caractere_courant) != 'o') &&
1170: ((*pointeur_caractere_courant) != 'd') &&
1171: ((*pointeur_caractere_courant) != 'h') &&
1172: ((*pointeur_caractere_courant) !=
1173: d_code_fin_chaine) &&
1174: (erreur_analyse == d_ex))
1175: {
1176: switch(*pointeur_caractere_courant)
1177: {
1178: case ' ' :
1179: case '0' :
1180: case '1' :
1181: case '2' :
1182: case '3' :
1183: case '4' :
1184: case '5' :
1185: case '6' :
1186: case '7' :
1187: case '8' :
1188: case '9' :
1189: case 'A' :
1190: case 'B' :
1191: case 'C' :
1192: case 'D' :
1193: case 'E' :
1194: case 'F' :
1195: case 'b' :
1196: case 'o' :
1197: case 'd' :
1198: case 'h' :
1199: {
1200: break;
1201: }
1202:
1203: default :
1204: {
1205: erreur_analyse = d_ex_syntaxe;
1206: break;
1207: }
1208: }
1209:
1210: pointeur_caractere_courant++;
1211: }
1212:
1213: base_binaire = (*pointeur_caractere_courant);
1214: pointeur_caractere_courant++;
1215:
1216: if (((*pointeur_caractere_courant) != d_code_fin_chaine) &&
1.68 bertrand 1217: ((*pointeur_caractere_courant) != d_code_espace) &&
1218: ((*pointeur_caractere_courant) != caractere_fin))
1.1 bertrand 1219: {
1220: erreur_analyse = d_ex_syntaxe;
1221: }
1222: else
1223: {
1224: pointeur_caractere_courant = pointeur_debut_instruction + 1;
1225:
1226: switch(base_binaire)
1227: {
1228: case 'b' :
1229: case 'o' :
1230: case 'd' :
1231: case 'h' :
1232: {
1233: break;
1234: }
1235:
1236: default :
1237: {
1238: erreur_analyse = d_ex_syntaxe;
1239: break;
1240: }
1241: }
1242: }
1243:
1244: while(((*pointeur_caractere_courant) != base_binaire) &&
1245: ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
1246: (erreur_analyse == d_ex))
1247: {
1248: if (base_binaire == 'b')
1249: {
1250: switch(*pointeur_caractere_courant)
1251: {
1252: case ' ' :
1253: case '0' :
1254: case '1' :
1255: {
1256: break;
1257: }
1258:
1259: default :
1260: {
1261: erreur_analyse = d_ex_syntaxe;
1262: break;
1263: }
1264: }
1265: }
1266: else if (base_binaire == 'o')
1267: {
1268: switch(*pointeur_caractere_courant)
1269: {
1270: case ' ' :
1271: case '0' :
1272: case '1' :
1273: case '2' :
1274: case '3' :
1275: case '4' :
1276: case '5' :
1277: case '6' :
1278: case '7' :
1279: {
1280: break;
1281: }
1282:
1283: default :
1284: {
1285: erreur_analyse = d_ex_syntaxe;
1286: break;
1287: }
1288: }
1289: }
1290: else if (base_binaire == 'd')
1291: {
1292: switch(*pointeur_caractere_courant)
1293: {
1294: case ' ' :
1295: case '0' :
1296: case '1' :
1297: case '2' :
1298: case '3' :
1299: case '4' :
1300: case '5' :
1301: case '6' :
1302: case '7' :
1303: case '8' :
1304: case '9' :
1305: {
1306: break;
1307: }
1308:
1309: default :
1310: {
1311: erreur_analyse = d_ex_syntaxe;
1312: break;
1313: }
1314: }
1315: }
1316: else if (base_binaire != 'h')
1317: {
1318: erreur_analyse = d_ex_syntaxe;
1319: }
1320:
1321: pointeur_caractere_courant++;
1322: }
1323:
1324: if (erreur_analyse == d_ex)
1325: {
1326: pointeur_caractere_courant++;
1327: }
1328:
1329: drapeau_fin_objet = d_vrai;
1330: break;
1331: }
1332:
1333: case '{' :
1334: {
1335: if (pointeur_debut_instruction !=
1336: (pointeur_caractere_courant - 1))
1337: {
1338: erreur_format = d_ex_syntaxe;
1339: }
1340:
1341: niveau = 1;
1342:
1343: while((niveau != 0) && ((*pointeur_caractere_courant) !=
1344: d_code_fin_chaine))
1345: {
1.56 bertrand 1346: (*s_etat_processus).position_courante =
1347: pointeur_caractere_courant
1348: - (*s_etat_processus).definitions_chainees;
1349:
1.68 bertrand 1350: registre_type_en_cours = (*s_etat_processus).type_en_cours;
1351: (*s_etat_processus).type_en_cours = LST;
1352:
1.69 bertrand 1353: if (recherche_instruction_suivante_recursive(
1354: s_etat_processus, recursivite + 1) == d_erreur)
1.1 bertrand 1355: {
1.68 bertrand 1356: (*s_etat_processus).type_en_cours =
1357: registre_type_en_cours;
1358:
1.56 bertrand 1359: if ((*s_etat_processus).instruction_courante
1360: != NULL)
1.1 bertrand 1361: {
1.56 bertrand 1362: free((*s_etat_processus).instruction_courante);
1.68 bertrand 1363: (*s_etat_processus).instruction_courante = NULL;
1.56 bertrand 1364: }
1365:
1366: return(d_erreur);
1367: }
1368:
1.69 bertrand 1369: (*s_etat_processus).type_en_cours = registre_type_en_cours;
1.56 bertrand 1370: pointeur_caractere_courant =
1371: (*s_etat_processus).definitions_chainees +
1372: (*s_etat_processus).position_courante;
1.1 bertrand 1373:
1.68 bertrand 1374: if (strcmp((*s_etat_processus).instruction_courante, "}")
1.56 bertrand 1375: == 0)
1376: {
1377: niveau--;
1378: }
1.1 bertrand 1379:
1.56 bertrand 1380: free((*s_etat_processus).instruction_courante);
1.1 bertrand 1381: }
1382:
1.68 bertrand 1383: if (niveau != 0)
1.1 bertrand 1384: {
1385: erreur_analyse = d_ex_syntaxe;
1386: }
1387:
1388: drapeau_fin_objet = d_vrai;
1389: break;
1390: }
1391:
1392: case '[' :
1393: {
1394: if (pointeur_debut_instruction !=
1395: (pointeur_caractere_courant - 1))
1396: {
1397: erreur_format = d_ex_syntaxe;
1398: }
1399:
1400: niveau = 1;
1401:
1402: while((niveau > 0) && ((*pointeur_caractere_courant) !=
1403: d_code_fin_chaine) && (erreur_analyse == d_ex))
1404: {
1405: switch(*pointeur_caractere_courant)
1406: {
1407: case '[' :
1408: {
1409: niveau++;
1410: break;
1411: }
1412:
1413: case ']' :
1414: {
1415: niveau--;
1416: break;
1417: }
1418:
1419: case '0' :
1420: case '1' :
1421: case '2' :
1422: case '3' :
1423: case '4' :
1424: case '5' :
1425: case '6' :
1426: case '7' :
1427: case '8' :
1428: case '9' :
1429: case '+' :
1430: case '-' :
1431: case 'e' :
1432: case 'E' :
1433: case '.' :
1434: case ',' :
1435: case '(' :
1436: case ')' :
1437: case ' ' :
1438: {
1439: break;
1440: }
1441:
1442: default :
1443: {
1444: erreur_analyse = d_ex_syntaxe;
1445: break;
1446: }
1447: }
1448:
1449: if (niveau < 0)
1450: {
1451: erreur_analyse = d_ex_syntaxe;
1452: }
1453: else if (niveau > 2)
1454: {
1455: erreur_format = d_ex_syntaxe;
1456: }
1457:
1458: pointeur_caractere_courant++;
1459: }
1460:
1461: if (niveau != 0)
1462: {
1463: erreur_analyse = d_ex_syntaxe;
1464: }
1465:
1466: drapeau_fin_objet = d_vrai;
1467: break;
1468: }
1469:
1470: case '<' :
1471: {
1472: if (((*s_etat_processus).autorisation_empilement_programme
1473: == 'Y') && ((*pointeur_caractere_courant) == '<'))
1.56 bertrand 1474: { // Cas << >>
1.1 bertrand 1475: if (pointeur_debut_instruction !=
1476: (pointeur_caractere_courant - 1))
1477: {
1478: erreur_format = d_ex_syntaxe;
1479: }
1480:
1.69 bertrand 1481: pointeur_caractere_courant++;
1482: drapeau_fin_objet = d_faux;
1.1 bertrand 1483:
1.69 bertrand 1484: while(((*pointeur_caractere_courant) != d_code_fin_chaine)
1485: && (erreur_format == d_absence_erreur))
1.1 bertrand 1486: {
1.69 bertrand 1487: while((*pointeur_caractere_courant) == d_code_espace)
1488: {
1489: pointeur_caractere_courant++;
1490: }
1491:
1.75 bertrand 1492: if (((*pointeur_caractere_courant) == '>') &&
1493: ((*(pointeur_caractere_courant - 1)) ==
1494: d_code_espace))
1.69 bertrand 1495: {
1.76 bertrand 1496: pointeur_caractere_courant++;
1497:
1498: if ((*pointeur_caractere_courant) == '>')
1499: { // Cas de '>>'
1.69 bertrand 1500: drapeau_fin_objet = d_vrai;
1.76 bertrand 1501: pointeur_caractere_courant++;
1502: break;
1.69 bertrand 1503: }
1.80 bertrand 1504: else if ((*pointeur_caractere_courant) == '=')
1505: { // Cas de '>='
1506: pointeur_caractere_courant++;
1507: }
1.76 bertrand 1508: else if ((*pointeur_caractere_courant) !=
1509: d_code_espace)
1510: { // Tous les cas différents de '>'
1.69 bertrand 1511: erreur_analyse = d_ex_syntaxe;
1.76 bertrand 1512: break;
1.69 bertrand 1513: }
1.56 bertrand 1514:
1.76 bertrand 1515: pointeur_caractere_courant--;
1.69 bertrand 1516: }
1.68 bertrand 1517:
1.69 bertrand 1518: if ((erreur_format == d_absence_erreur) &&
1519: (drapeau_fin_objet == d_faux))
1.56 bertrand 1520: {
1.69 bertrand 1521: (*s_etat_processus).position_courante =
1522: pointeur_caractere_courant
1523: - (*s_etat_processus).definitions_chainees;
1524:
1525: registre_type_en_cours = (*s_etat_processus)
1526: .type_en_cours;
1527: (*s_etat_processus).type_en_cours = RPN;
1.68 bertrand 1528:
1.69 bertrand 1529: if ((erreur =
1530: recherche_instruction_suivante_recursive(
1531: s_etat_processus, recursivite + 1))
1532: != d_absence_erreur)
1.56 bertrand 1533: {
1.69 bertrand 1534: (*s_etat_processus).type_en_cours =
1535: registre_type_en_cours;
1536:
1537: if ((*s_etat_processus).instruction_courante
1538: != NULL)
1539: {
1540: free((*s_etat_processus)
1541: .instruction_courante);
1542: (*s_etat_processus).instruction_courante
1543: = NULL;
1544: }
1545:
1546: return(d_erreur);
1.56 bertrand 1547: }
1548:
1.69 bertrand 1549: (*s_etat_processus).type_en_cours =
1550: registre_type_en_cours;
1551: pointeur_caractere_courant = (*s_etat_processus)
1552: .definitions_chainees + (*s_etat_processus)
1553: .position_courante;
1.56 bertrand 1554:
1.69 bertrand 1555: free((*s_etat_processus).instruction_courante);
1.1 bertrand 1556: }
1557: }
1558:
1.69 bertrand 1559: if (drapeau_fin_objet == d_faux)
1.1 bertrand 1560: {
1561: erreur_analyse = d_ex_syntaxe;
1.69 bertrand 1562: drapeau_fin_objet = d_vrai;
1.1 bertrand 1563: }
1564: }
1565: else if ((*pointeur_caractere_courant) == '[')
1.56 bertrand 1566: { // Cas <[ ]>
1.1 bertrand 1567: if (pointeur_debut_instruction !=
1568: (pointeur_caractere_courant - 1))
1569: {
1570: erreur_format = d_ex_syntaxe;
1571: }
1572:
1573: pointeur_caractere_courant++;
1574: drapeau_fin_objet = d_faux;
1575:
1576: while(((*pointeur_caractere_courant) != d_code_fin_chaine)
1577: && (erreur_format == d_absence_erreur))
1578: {
1579: while((*pointeur_caractere_courant) == d_code_espace)
1580: {
1581: pointeur_caractere_courant++;
1582: }
1583:
1584: if ((*pointeur_caractere_courant) == ']')
1585: {
1586: if ((*(++pointeur_caractere_courant)) == '>')
1587: {
1588: drapeau_fin_objet = d_vrai;
1589: }
1590: else
1591: {
1592: erreur_analyse = d_ex_syntaxe;
1593: }
1594:
1595: pointeur_caractere_courant++;
1596: break;
1597: }
1598:
1599: if ((erreur_format == d_absence_erreur) &&
1600: (drapeau_fin_objet == d_faux))
1601: {
1602: (*s_etat_processus).position_courante =
1603: pointeur_caractere_courant
1604: - (*s_etat_processus).definitions_chainees;
1605:
1.68 bertrand 1606: registre_type_en_cours = (*s_etat_processus)
1607: .type_en_cours;
1608: (*s_etat_processus).type_en_cours = TBL;
1609:
1.69 bertrand 1610: if ((erreur =
1611: recherche_instruction_suivante_recursive(
1612: s_etat_processus, recursivite + 1))
1613: != d_absence_erreur)
1.1 bertrand 1614: {
1.68 bertrand 1615: (*s_etat_processus).type_en_cours =
1616: registre_type_en_cours;
1617:
1.1 bertrand 1618: if ((*s_etat_processus).instruction_courante
1619: != NULL)
1620: {
1621: free((*s_etat_processus)
1622: .instruction_courante);
1.68 bertrand 1623: (*s_etat_processus).instruction_courante
1624: = NULL;
1.1 bertrand 1625: }
1626:
1627: return(d_erreur);
1628: }
1629:
1.68 bertrand 1630: (*s_etat_processus).type_en_cours =
1631: registre_type_en_cours;
1.1 bertrand 1632: pointeur_caractere_courant = (*s_etat_processus)
1633: .definitions_chainees + (*s_etat_processus)
1634: .position_courante;
1635:
1636: free((*s_etat_processus).instruction_courante);
1637: }
1638: }
1639:
1640: if (drapeau_fin_objet == d_faux)
1641: {
1642: erreur_analyse = d_ex_syntaxe;
1643: drapeau_fin_objet = d_vrai;
1644: }
1645: }
1646:
1647: break;
1648: }
1649: }
1.68 bertrand 1650:
1.69 bertrand 1651: if ((*(pointeur_caractere_courant - 1)) == caractere_fin)
1.68 bertrand 1652: {
1.69 bertrand 1653: // Cas des objets composites (LST, RPN, TBL)
1654: break;
1655: }
1656: else if ((*pointeur_caractere_courant) == caractere_fin)
1657: {
1658: // Condition pour traiter les cas 123}
1.68 bertrand 1659: break;
1660: }
1.1 bertrand 1661: }
1662:
1663: pointeur_fin_instruction = pointeur_caractere_courant;
1664:
1.69 bertrand 1665: if (recursivite == 0)
1666: {
1667: // Si la variable récursivité est nulle, il faut que le caractère
1668: // suivant l'objet soit un espace ou une fin de chaîne. Si ce n'est pas
1669: // le cas, il faut retourner une erreur car les objets de type
1670: // [[ 1 4 ]]3 doivent être invalides.
1671:
1672: switch((*pointeur_fin_instruction))
1673: {
1674: case d_code_fin_chaine:
1675: case d_code_espace:
1676: {
1677: break;
1678: }
1679:
1680: default:
1681: {
1682: (*s_etat_processus).erreur_execution = d_ex_syntaxe;
1.74 bertrand 1683: // return(d_erreur);
1.69 bertrand 1684: }
1685: }
1686: }
1687:
1.1 bertrand 1688: (*s_etat_processus).instruction_courante = (unsigned char *)
1.57 bertrand 1689: malloc((((size_t) (pointeur_fin_instruction
1690: - pointeur_debut_instruction)) + 1) * sizeof(unsigned char));
1.1 bertrand 1691:
1692: if ((*s_etat_processus).instruction_courante == NULL)
1693: {
1694: erreur = d_erreur;
1695: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1696: }
1697: else if (pointeur_fin_instruction != pointeur_debut_instruction)
1698: {
1699: pointeur_caractere_courant = pointeur_debut_instruction;
1700: pointeur_caractere_destination =
1701: (*s_etat_processus).instruction_courante;
1702:
1703: do
1704: {
1705: *pointeur_caractere_destination++ = *pointeur_caractere_courant++;
1706: } while(pointeur_caractere_courant < pointeur_fin_instruction);
1707:
1708: (*pointeur_caractere_destination) = d_code_fin_chaine;
1709:
1710: erreur = ((erreur_analyse == d_ex) && (erreur_format == d_ex))
1711: ? d_absence_erreur : d_erreur;
1712: (*s_etat_processus).erreur_execution = erreur_analyse;
1.78 bertrand 1713:
1714: if ((*s_etat_processus).erreur_execution == d_ex)
1715: {
1716: (*s_etat_processus).erreur_execution = erreur_format;
1717: }
1.1 bertrand 1718: }
1719: else
1720: {
1721: (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
1722: }
1723:
1724: (*s_etat_processus).position_courante = pointeur_fin_instruction
1725: - (*s_etat_processus).definitions_chainees;
1726:
1727: return(erreur);
1728: }
1729:
1730:
1731: /*
1732: ================================================================================
1.69 bertrand 1733: Routine mettant la chaîne d'entrée en majuscule
1.1 bertrand 1734: ================================================================================
1.69 bertrand 1735: Entrée : pointeur sur une chaîne en minuscules.
1.1 bertrand 1736: --------------------------------------------------------------------------------
1.69 bertrand 1737: Sortie : pointeur sur la chaîne en majuscules. Si le pointeur retourné
1.1 bertrand 1738: est nul, il s'est produit une erreur. L'allocation est faite dans la
1739: routine.
1740: --------------------------------------------------------------------------------
1741: Effets de bord : néant.
1742: ================================================================================
1743: */
1744:
1745: unsigned char *
1.72 bertrand 1746: conversion_majuscule(struct_processus *s_etat_processus, unsigned char *chaine)
1.1 bertrand 1747: {
1748: register unsigned char *caractere_courant;
1749: register unsigned char *caractere_courant_converti;
1750: register unsigned char *chaine_convertie;
1751:
1.58 bertrand 1752: integer8 longueur_chaine_plus_terminaison;
1.1 bertrand 1753:
1754: longueur_chaine_plus_terminaison = 0;
1755: caractere_courant = chaine;
1756:
1757: while((*caractere_courant) != d_code_fin_chaine)
1758: {
1759: caractere_courant++;
1760: longueur_chaine_plus_terminaison++;
1761: }
1762:
1763: caractere_courant = chaine;
1764: caractere_courant_converti = chaine_convertie = (unsigned char *) malloc(
1.59 bertrand 1765: ((size_t) (longueur_chaine_plus_terminaison + 1))
1766: * sizeof(unsigned char));
1.1 bertrand 1767:
1768: if (chaine_convertie != NULL)
1769: {
1770: while((*caractere_courant) != d_code_fin_chaine)
1771: {
1772: if (isalpha((*caractere_courant)))
1773: {
1774: (*caractere_courant_converti) = (unsigned char)
1775: toupper((*caractere_courant));
1776: }
1777: else
1778: {
1779: (*caractere_courant_converti) = (*caractere_courant);
1780: }
1781:
1782: caractere_courant++;
1783: caractere_courant_converti++;
1784: }
1785:
1786: (*caractere_courant_converti) = d_code_fin_chaine;
1787: }
1788:
1789: return(chaine_convertie);
1790: }
1791:
1.9 bertrand 1792: void
1793: conversion_majuscule_limitee(unsigned char *chaine_entree,
1.57 bertrand 1794: unsigned char *chaine_sortie, integer8 longueur)
1.9 bertrand 1795: {
1.57 bertrand 1796: integer8 i;
1.9 bertrand 1797:
1798: for(i = 0; i < longueur; i++)
1799: {
1800: if (isalpha((*chaine_entree)))
1801: {
1802: (*chaine_sortie) = (unsigned char) toupper((*chaine_entree));
1803: }
1804: else
1805: {
1806: (*chaine_sortie) = (*chaine_entree);
1807: }
1808:
1809: if ((*chaine_entree) == d_code_fin_chaine)
1810: {
1811: break;
1812: }
1813:
1814: chaine_entree++;
1815: chaine_sortie++;
1816: }
1817:
1818: return;
1819: }
1820:
1.1 bertrand 1821:
1822: /*
1823: ================================================================================
1824: Initialisation de l'état du calculateur
1825: Configuration par défaut d'un calculateur HP-28S
1826: ================================================================================
1827: Entrée : pointeur sur la structure struct_processus
1828: --------------------------------------------------------------------------------
1829: Sortie : néant
1830: --------------------------------------------------------------------------------
1831: Effets de bord : néant
1832: ================================================================================
1833: */
1834:
1835: void
1836: initialisation_drapeaux(struct_processus *s_etat_processus)
1837: {
1838: unsigned long i;
1839:
1.57 bertrand 1840: for(i = 0; i < 31; cf(s_etat_processus, (unsigned char) i++));
1.1 bertrand 1841:
1842: if ((*s_etat_processus).lancement_interactif == d_vrai)
1843: {
1844: sf(s_etat_processus, 31);
1845: /* LAST autorisé */
1846: }
1847: else
1848: {
1849: cf(s_etat_processus, 31);
1850: /* LAST invalidé */
1851: }
1852:
1853: cf(s_etat_processus, 32); /* Impression automatique */
1854: cf(s_etat_processus, 33); /* CR automatique (disp) */
1.23 bertrand 1855: sf(s_etat_processus, 34); /* Évaluation des caractères de contrôle */
1856: sf(s_etat_processus, 35); /* Évaluation symbolique des constantes */
1857: sf(s_etat_processus, 36); /* Évaluation symbolique des fonctions */
1.1 bertrand 1858: sf(s_etat_processus, 37); /* Taille de mot pour les entiers binaires */
1859: sf(s_etat_processus, 38); /* Taille de mot pour les entiers binaires */
1860: sf(s_etat_processus, 39); /* Taille de mot pour les entiers binaires */
1861: sf(s_etat_processus, 40); /* Taille de mot pour les entiers binaires */
1862: sf(s_etat_processus, 41); /* Taille de mot pour les entiers binaires */
1863: sf(s_etat_processus, 42); /* Taille de mot pour les entiers binaires */
1864: /*
1865: 37 : bit de poids faible
1866: 42 : bit de poids fort
1867: Les six drapeaux peuvent être nuls. Dans ce cas, la longueur des mots
1868: binaires reste de un bit.
1869: */
1870: cf(s_etat_processus, 43); /* Base de numération binaire */
1871: cf(s_etat_processus, 44); /* Base de numération binaire */
1872: /*
1873: 43 44 = 00 => décimal
1874: 43 44 = 01 => binaire
1875: 43 44 = 10 => octal
1876: 43 44 = 11 => hexadécimal
1877: */
1878: sf(s_etat_processus, 45); /* Affichage multiligne du niveau 1 */
1879: cf(s_etat_processus, 46); /* Réservé */
1880: cf(s_etat_processus, 47); /* Réservé */
1881: /*
1882: 46 et 47 réservés sur le calculateur HP28S
1883: 46 47 = 00 => système rectangulaire
1884: 46 47 = 01 => système cylindrique
1885: 46 47 = 10 => système sphérique
1886: */
1887: cf(s_etat_processus, 48); /* Séparateur décimal */
1888: cf(s_etat_processus, 49); /* Format des nombres réels */
1889: cf(s_etat_processus, 50); /* Format des nombres réels */
1890: /*
1891: 49 50 = 00 => standard
1892: 49 50 = 01 => scientifique
1893: 49 50 = 10 => virgule fixe
1894: 49 50 = 11 => ingénieur
1895: */
1896: cf(s_etat_processus, 51); /* Tonalité */
1897: cf(s_etat_processus, 52); /* REDRAW automatique */
1898: cf(s_etat_processus, 53); /* Nombre de chiffres décimaux */
1899: cf(s_etat_processus, 54); /* Nombre de chiffres décimaux */
1900: cf(s_etat_processus, 55); /* Nombre de chiffres décimaux */
1901: cf(s_etat_processus, 56); /* Nombre de chiffres décimaux */
1902: /*
1903: 53 : bit de poids faible
1904: 56 : bit de poids fort
1905: */
1906: cf(s_etat_processus, 57); /* Underflow traité normalement */
1907: cf(s_etat_processus, 58); /* Overflow traité normalement */
1908: sf(s_etat_processus, 59); /* Infinite result traité normalement */
1909: sf(s_etat_processus, 60); /* Angles */
1910: /*
1911: 60 = 0 => degrés
1912: 60 = 1 => radians
1913: */
1914: cf(s_etat_processus, 61); /* Underflow- traité en exception */
1915: cf(s_etat_processus, 62); /* Underflow+ traité en exception */
1916: cf(s_etat_processus, 63); /* Overflow traité en exception */
1917: cf(s_etat_processus, 64); /* Infinite result traité en exception */
1918: }
1919:
1920: // vim: ts=4