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