File:  [local] / rpl / src / compilation.c
Revision 1.19: download - view: text, annotated - select for diffs - revision graph
Thu Aug 26 19:07:35 2010 UTC (13 years, 8 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_0_19, HEAD
En route pour la 4.0.19 !

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.0.19
    4:   Copyright (C) 1989-2010 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   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: 
  361: logical1
  362: analyse_syntaxique(struct_processus *s_etat_processus)
  363: {
  364:     enum t_condition    { AN_IF = 1, AN_IFERR, AN_THEN, AN_ELSE, AN_ELSEIF,
  365:                         AN_END, AN_DO, AN_UNTIL, AN_WHILE, AN_REPEAT, AN_SELECT,
  366:                         AN_CASE, AN_DEFAULT, AN_UP, AN_DOWN, AN_FOR, AN_START,
  367:                         AN_NEXT, AN_STEP };
  368: 
  369:     unsigned char       *instruction;
  370:     unsigned char       registre;
  371: 
  372:     typedef struct pile
  373:     {
  374:         enum t_condition    condition;
  375:         struct pile         *suivant;
  376:     } struct_pile_analyse;
  377: 
  378:     struct_pile_analyse     *l_base_pile;
  379:     struct_pile_analyse     *l_nouvelle_base_pile;
  380: 
  381:     inline struct_pile_analyse *
  382:     empilement_analyse(struct_pile_analyse *ancienne_base,
  383:             enum t_condition condition)
  384:     {
  385:         struct_pile_analyse     *nouvelle_base;
  386: 
  387:         if ((nouvelle_base = malloc(sizeof(struct_pile_analyse))) == NULL)
  388:         {
  389:             return(NULL);
  390:         }
  391: 
  392:         (*nouvelle_base).suivant = ancienne_base;
  393:         (*nouvelle_base).condition = condition;
  394: 
  395:         return(nouvelle_base);
  396:     }
  397: 
  398:     inline struct_pile_analyse *
  399:     depilement_analyse(struct_pile_analyse *ancienne_base)
  400:     {
  401:         struct_pile_analyse     *nouvelle_base;
  402: 
  403:         if (ancienne_base == NULL)
  404:         {
  405:             return(NULL);
  406:         }
  407: 
  408:         nouvelle_base = (*ancienne_base).suivant;
  409:         free(ancienne_base);
  410: 
  411:         return(nouvelle_base);
  412:     }
  413: 
  414:     inline logical1
  415:     test_analyse(struct_pile_analyse *l_base_pile, enum t_condition condition)
  416:     {
  417:         if (l_base_pile == NULL)
  418:         {
  419:             return(d_faux);
  420:         }
  421: 
  422:         return(((*l_base_pile).condition == condition) ? d_vrai : d_faux);
  423:     }
  424: 
  425:     inline void
  426:     liberation_analyse(struct_pile_analyse *l_base_pile)
  427:     {
  428:         struct_pile_analyse     *l_nouvelle_base_pile;
  429: 
  430:         while(l_base_pile != NULL)
  431:         {
  432:             l_nouvelle_base_pile = (*l_base_pile).suivant;
  433:             free(l_base_pile);
  434:             l_base_pile = l_nouvelle_base_pile;
  435:         }
  436: 
  437:         return;
  438:     }
  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:         }
  517:         else if (strcmp(instruction, "THEN") == 0)
  518:         {
  519:             if ((test_analyse(l_base_pile, AN_IF) == d_faux) &&
  520:                     (test_analyse(l_base_pile, AN_ELSEIF) == d_faux) &&
  521:                     (test_analyse(l_base_pile, AN_CASE) == d_faux) &&
  522:                     (test_analyse(l_base_pile, AN_IFERR) == d_faux))
  523:             {
  524:                 liberation_analyse(l_base_pile);
  525: 
  526:                 (*s_etat_processus).autorisation_empilement_programme =
  527:                         registre;
  528: 
  529:                 (*s_etat_processus).erreur_compilation =
  530:                         d_ec_erreur_instruction_then;
  531:                 return(d_erreur);
  532:             }
  533: 
  534:             (*l_base_pile).condition = AN_THEN;
  535:         }
  536:         else if (strcmp(instruction, "ELSE") == 0)
  537:         {
  538:             if (test_analyse(l_base_pile, AN_THEN) == d_faux)
  539:             {
  540:                 liberation_analyse(l_base_pile);
  541: 
  542:                 (*s_etat_processus).autorisation_empilement_programme =
  543:                         registre;
  544: 
  545:                 (*s_etat_processus).erreur_compilation =
  546:                         d_ec_erreur_instruction_else;
  547:                 return(d_erreur);
  548:             }
  549: 
  550:             (*l_base_pile).condition = AN_ELSE;
  551:         }
  552:         else if (strcmp(instruction, "ELSEIF") == 0)
  553:         {
  554:             if (test_analyse(l_base_pile, AN_THEN) == d_faux)
  555:             {
  556:                 liberation_analyse(l_base_pile);
  557: 
  558:                 (*s_etat_processus).autorisation_empilement_programme =
  559:                         registre;
  560: 
  561:                 (*s_etat_processus).erreur_compilation =
  562:                         d_ec_erreur_instruction_elseif;
  563:                 return(d_erreur);
  564:             }
  565: 
  566:             (*l_base_pile).condition = AN_ELSEIF;
  567:         }
  568:         else if (strcmp(instruction, "END") == 0)
  569:         {
  570:             if ((test_analyse(l_base_pile, AN_UNTIL) == d_faux) &&
  571:                     (test_analyse(l_base_pile, AN_REPEAT) == d_faux) &&
  572:                     (test_analyse(l_base_pile, AN_DEFAULT) == d_faux) &&
  573:                     (test_analyse(l_base_pile, AN_SELECT) == d_faux) &&
  574:                     (test_analyse(l_base_pile, AN_THEN) == d_faux) &&
  575:                     (test_analyse(l_base_pile, AN_ELSE) == d_faux))
  576:             {
  577:                 liberation_analyse(l_base_pile);
  578: 
  579:                 (*s_etat_processus).autorisation_empilement_programme =
  580:                         registre;
  581: 
  582:                 (*s_etat_processus).erreur_compilation =
  583:                         d_ec_erreur_instruction_end;
  584:                 return(d_erreur);
  585:             }
  586: 
  587:             l_base_pile = depilement_analyse(l_base_pile);
  588:         }
  589:         else if (strcmp(instruction, "DO") == 0)
  590:         {
  591:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_DO))
  592:                     == NULL)
  593:             {
  594:                 liberation_analyse(l_base_pile);
  595: 
  596:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  597:                 return(d_erreur);
  598:             }
  599: 
  600:             l_base_pile = l_nouvelle_base_pile;
  601:         }
  602:         else if (strcmp(instruction, "UNTIL") == 0)
  603:         {
  604:             if (test_analyse(l_base_pile, AN_DO) == d_faux)
  605:             {
  606:                 liberation_analyse(l_base_pile);
  607: 
  608:                 (*s_etat_processus).autorisation_empilement_programme =
  609:                         registre;
  610: 
  611:                 (*s_etat_processus).erreur_compilation =
  612:                         d_ec_erreur_instruction_until;
  613:                 return(d_erreur);
  614:             }
  615: 
  616:             (*l_base_pile).condition = AN_UNTIL;
  617:         }
  618:         else if (strcmp(instruction, "WHILE") == 0)
  619:         {
  620:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
  621:                     AN_WHILE)) == NULL)
  622:             {
  623:                 liberation_analyse(l_base_pile);
  624: 
  625:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  626:                 return(d_erreur);
  627:             }
  628: 
  629:             l_base_pile = l_nouvelle_base_pile;
  630:         }
  631:         else if (strcmp(instruction, "REPEAT") == 0)
  632:         {
  633:             if (test_analyse(l_base_pile, AN_WHILE) == d_faux)
  634:             {
  635:                 liberation_analyse(l_base_pile);
  636: 
  637:                 (*s_etat_processus).autorisation_empilement_programme =
  638:                         registre;
  639: 
  640:                 (*s_etat_processus).erreur_compilation =
  641:                         d_ec_erreur_instruction_while;
  642:                 return(d_erreur);
  643:             }
  644: 
  645:             (*l_base_pile).condition = AN_REPEAT;
  646:         }
  647:         else if (strcmp(instruction, "SELECT") == 0)
  648:         {
  649:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
  650:                     AN_SELECT)) == NULL)
  651:             {
  652:                 liberation_analyse(l_base_pile);
  653: 
  654:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  655:                 return(d_erreur);
  656:             }
  657: 
  658:             l_base_pile = l_nouvelle_base_pile;
  659:         }
  660:         else if (strcmp(instruction, "CASE") == 0)
  661:         {
  662:             if (test_analyse(l_base_pile, AN_SELECT) == d_faux)
  663:             {
  664:                 liberation_analyse(l_base_pile);
  665: 
  666:                 (*s_etat_processus).autorisation_empilement_programme =
  667:                         registre;
  668: 
  669:                 (*s_etat_processus).erreur_compilation =
  670:                         d_ec_erreur_instruction_case;
  671:                 return(d_erreur);
  672:             }
  673: 
  674:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
  675:                     AN_CASE)) == NULL)
  676:             {
  677:                 liberation_analyse(l_base_pile);
  678: 
  679:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  680:                 return(d_erreur);
  681:             }
  682: 
  683:             l_base_pile = l_nouvelle_base_pile;
  684:         }
  685:         else if (strcmp(instruction, "DEFAULT") == 0)
  686:         {
  687:             if (test_analyse(l_base_pile, AN_SELECT) == d_faux)
  688:             {
  689:                 liberation_analyse(l_base_pile);
  690: 
  691:                 (*s_etat_processus).autorisation_empilement_programme =
  692:                         registre;
  693: 
  694:                 (*s_etat_processus).erreur_compilation =
  695:                         d_ec_erreur_instruction_select;
  696:                 return(d_erreur);
  697:             }
  698: 
  699:             (*l_base_pile).condition = AN_DEFAULT;
  700:         }
  701:         else if (strcmp(instruction, "<<") == 0)
  702:         {
  703:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_UP))
  704:                     == NULL)
  705:             {
  706:                 liberation_analyse(l_base_pile);
  707: 
  708:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  709:                 return(d_erreur);
  710:             }
  711: 
  712:             l_base_pile = l_nouvelle_base_pile;
  713:         }
  714:         else if (strcmp(instruction, ">>") == 0)
  715:         {
  716:             if (test_analyse(l_base_pile, AN_UP) == d_faux)
  717:             {
  718:                 liberation_analyse(l_base_pile);
  719: 
  720:                 (*s_etat_processus).autorisation_empilement_programme =
  721:                         registre;
  722: 
  723:                 (*s_etat_processus).erreur_compilation =
  724:                         d_ec_source_incoherent;
  725:                 return(d_erreur);
  726:             }
  727: 
  728:             l_base_pile = depilement_analyse(l_base_pile);
  729:         }
  730:         else if (strcmp(instruction, "FOR") == 0)
  731:         {
  732:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile, AN_FOR))
  733:                     == NULL)
  734:             {
  735:                 liberation_analyse(l_base_pile);
  736: 
  737:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  738:                 return(d_erreur);
  739:             }
  740: 
  741:             l_base_pile = l_nouvelle_base_pile;
  742:         }
  743:         else if (strcmp(instruction, "START") == 0)
  744:         {
  745:             if ((l_nouvelle_base_pile = empilement_analyse(l_base_pile,
  746:                     AN_START)) == NULL)
  747:             {
  748:                 liberation_analyse(l_base_pile);
  749: 
  750:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  751:                 return(d_erreur);
  752:             }
  753: 
  754:             l_base_pile = l_nouvelle_base_pile;
  755:         }
  756:         else if (strcmp(instruction, "NEXT") == 0)
  757:         {
  758:             if ((test_analyse(l_base_pile, AN_FOR) == d_faux) &&
  759:                     (test_analyse(l_base_pile, AN_START) == d_faux))
  760:             {
  761:                 liberation_analyse(l_base_pile);
  762: 
  763:                 (*s_etat_processus).autorisation_empilement_programme =
  764:                         registre;
  765: 
  766:                 (*s_etat_processus).erreur_compilation =
  767:                         d_ec_erreur_boucle_definie;
  768:                 return(d_erreur);
  769:             }
  770: 
  771:             l_base_pile = depilement_analyse(l_base_pile);
  772:         }
  773:         else if (strcmp(instruction, "STEP") == 0)
  774:         {
  775:             if ((test_analyse(l_base_pile, AN_FOR) == d_faux) &&
  776:                     (test_analyse(l_base_pile, AN_START) == d_faux))
  777:             {
  778:                 liberation_analyse(l_base_pile);
  779: 
  780:                 (*s_etat_processus).autorisation_empilement_programme =
  781:                         registre;
  782: 
  783:                 (*s_etat_processus).erreur_compilation =
  784:                         d_ec_erreur_boucle_definie;
  785:                 return(d_erreur);
  786:             }
  787: 
  788:             l_base_pile = depilement_analyse(l_base_pile);
  789:         }
  790: 
  791:         // Invalidation de l'instruction courante dans le fichier rpl-core
  792:         free((*s_etat_processus).instruction_courante);
  793:         (*s_etat_processus).instruction_courante = NULL;
  794:         free(instruction);
  795:     }
  796: 
  797:     (*s_etat_processus).autorisation_empilement_programme = registre;
  798: 
  799:     if (l_base_pile != NULL)
  800:     {
  801:         liberation_analyse(l_base_pile);
  802: 
  803:         (*s_etat_processus).autorisation_empilement_programme = registre;
  804:         (*s_etat_processus).erreur_compilation = d_ec_source_incoherent;
  805:         return(d_erreur);
  806:     }
  807: 
  808:     return(d_absence_erreur);
  809: }
  810: 
  811: 
  812: /*
  813: ================================================================================
  814:   Routine d'échange de deux variables
  815: ================================================================================
  816:   Entrées :
  817:     -   pointeurs génériques sur les deux variables,
  818:     -   longueur en octet des objets à permuter.
  819: --------------------------------------------------------------------------------
  820:   Sorties : idem.
  821: --------------------------------------------------------------------------------
  822:   Effets de bord : néant.
  823: ================================================================================
  824: */
  825: 
  826: void
  827: swap(void *variable_1, void *variable_2, unsigned long taille)
  828: {
  829:     register unsigned char      *t_var_1;
  830:     register unsigned char      *t_var_2;
  831:     register unsigned char      variable_temporaire;
  832: 
  833:     register unsigned long      i;
  834: 
  835:     t_var_1 = (unsigned char *) variable_1;
  836:     t_var_2 = (unsigned char *) variable_2;
  837: 
  838:     for(i = 0; i < taille; i++)
  839:     {
  840:         variable_temporaire = (*t_var_1);
  841:         (*(t_var_1++)) = (*t_var_2);
  842:         (*(t_var_2++)) = variable_temporaire;
  843:     }
  844: 
  845:     return;
  846: }
  847: 
  848: 
  849: /*
  850: ================================================================================
  851:   Routine recherchant l'instruction suivante dans le programme compilé
  852: ================================================================================
  853:   Entrée :
  854: --------------------------------------------------------------------------------
  855:   Sortie :
  856: --------------------------------------------------------------------------------
  857:   Effets de bord : néant.
  858: ================================================================================
  859: */
  860: 
  861: logical1
  862: recherche_instruction_suivante(struct_processus *s_etat_processus)
  863: {
  864:     logical1                    drapeau_fin_objet;
  865:     logical1                    erreur;
  866:     logical1                    erreur_analyse;
  867:     logical1                    erreur_format;
  868: 
  869:     unsigned char               base_binaire;
  870:     unsigned char               *pointeur_caractere_courant;
  871:     unsigned char               *pointeur_caractere_destination;
  872:     unsigned char               *pointeur_debut_instruction;
  873:     unsigned char               *pointeur_fin_instruction;
  874: 
  875:     signed long                 niveau;
  876:     signed long                 niveau_annexe;
  877: 
  878:     erreur_analyse = d_ex;
  879:     erreur_format = d_ex;
  880:     erreur = d_absence_erreur;
  881: 
  882:     drapeau_fin_objet = d_faux;
  883:     niveau = 0;
  884: 
  885:     pointeur_caractere_courant = (*s_etat_processus).definitions_chainees +
  886:             (*s_etat_processus).position_courante;
  887: 
  888:     while(((*pointeur_caractere_courant) == d_code_espace) &&
  889:             ((*pointeur_caractere_courant) != d_code_fin_chaine))
  890:     {
  891:         pointeur_caractere_courant++;
  892:     }
  893: 
  894:     if ((*pointeur_caractere_courant) == d_code_fin_chaine)
  895:     {
  896:         (*s_etat_processus).instruction_courante = (unsigned char *)
  897:                 malloc(sizeof(unsigned char));
  898: 
  899:         if ((*s_etat_processus).instruction_courante == NULL)
  900:         {
  901:             erreur = d_erreur;
  902:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  903:         }
  904:         else
  905:         {
  906:             erreur = d_absence_erreur;
  907:             (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
  908:             (*s_etat_processus).position_courante = pointeur_caractere_courant
  909:                     - (*s_etat_processus).definitions_chainees;
  910:         }
  911: 
  912:         return(erreur);
  913:     }
  914: 
  915:     pointeur_debut_instruction = pointeur_caractere_courant;
  916: 
  917:     while(((*pointeur_caractere_courant) != d_code_espace) &&
  918:             ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
  919:             (drapeau_fin_objet == d_faux) &&
  920:             (erreur_analyse == d_ex) &&
  921:             (erreur_format == d_ex))
  922:     {
  923:         switch(*pointeur_caractere_courant++)
  924:         {
  925:             case ']' :
  926:             case '}' :
  927:             case ')' :
  928:             {
  929:                 erreur_format = d_ex_syntaxe;
  930:                 break;
  931:             }
  932: 
  933:             case '"' :
  934:             {
  935:                 if (pointeur_debut_instruction !=
  936:                         (pointeur_caractere_courant - 1))
  937:                 {
  938:                     erreur_format = d_ex_syntaxe;
  939:                 }
  940: 
  941:                 while((*pointeur_caractere_courant != '"') &&
  942:                         ((*pointeur_caractere_courant) != d_code_fin_chaine))
  943:                 {
  944:                     if (*pointeur_caractere_courant == '\\')
  945:                     {
  946:                         pointeur_caractere_courant++;
  947: 
  948:                         switch(*pointeur_caractere_courant)
  949:                         {
  950:                             case '\\' :
  951:                             case '"' :
  952:                             {
  953:                                 pointeur_caractere_courant++;
  954:                                 break;
  955:                             }
  956:                         }
  957:                     }
  958:                     else
  959:                     {
  960:                         pointeur_caractere_courant++;
  961:                     }
  962:                 }
  963: 
  964:                 if ((*pointeur_caractere_courant) != '"')
  965:                 {
  966:                     erreur_analyse = d_ex_syntaxe;
  967:                 }
  968: 
  969:                 if (erreur_analyse == d_ex)
  970:                 {
  971:                     pointeur_caractere_courant++;
  972:                 }
  973: 
  974:                 drapeau_fin_objet = d_vrai;
  975:                 break;
  976:             }
  977: 
  978:             case '\'' :
  979:             {
  980:                 if (pointeur_debut_instruction !=
  981:                         (pointeur_caractere_courant - 1))
  982:                 {
  983:                     erreur_format = d_ex_syntaxe;
  984:                 }
  985: 
  986:                 while(((*pointeur_caractere_courant) != '\'') &&
  987:                         ((*pointeur_caractere_courant) != d_code_fin_chaine))
  988:                 {
  989:                     if ((*pointeur_caractere_courant) == '(')
  990:                     {
  991:                         niveau++;
  992:                     }
  993:                     else if ((*pointeur_caractere_courant) == ')')
  994:                     {
  995:                         niveau--;
  996:                     }
  997: 
  998:                     pointeur_caractere_courant++;
  999:                 }
 1000: 
 1001:                 if ((*pointeur_caractere_courant) != '\'')
 1002:                 {
 1003:                     erreur_analyse = d_ex_syntaxe;
 1004:                 }
 1005:                 else if (niveau != 0)
 1006:                 {
 1007:                     erreur_analyse = d_ex_syntaxe;
 1008:                 }
 1009: 
 1010:                 if (erreur_analyse == d_ex)
 1011:                 {
 1012:                     pointeur_caractere_courant++;
 1013:                 }
 1014: 
 1015:                 drapeau_fin_objet = d_vrai;
 1016:                 break;
 1017:             }
 1018: 
 1019:             case '(' :
 1020:             {
 1021:                 if (pointeur_debut_instruction !=
 1022:                         (pointeur_caractere_courant - 1))
 1023:                 {
 1024:                     erreur_format = d_ex_syntaxe;
 1025:                 }
 1026: 
 1027:                 while(((*pointeur_caractere_courant) != ')') &&
 1028:                         ((*pointeur_caractere_courant) != d_code_fin_chaine)
 1029:                         && (erreur_analyse == d_ex))
 1030:                 {
 1031:                     switch(*pointeur_caractere_courant)
 1032:                     {
 1033:                         case '0' :
 1034:                         case '1' :
 1035:                         case '2' :
 1036:                         case '3' :
 1037:                         case '4' :
 1038:                         case '5' :
 1039:                         case '6' :
 1040:                         case '7' :
 1041:                         case '8' :
 1042:                         case '9' :
 1043:                         case 'e' :
 1044:                         case 'E' :
 1045:                         case ',' :
 1046:                         case '.' :
 1047:                         case ' ' :
 1048:                         case '-' :
 1049:                         case '+' :
 1050:                         case ')' :
 1051:                         {
 1052:                             break;
 1053:                         }
 1054: 
 1055:                         default :
 1056:                         {
 1057:                             erreur_analyse = d_ex_syntaxe;
 1058:                             break;
 1059:                         }
 1060:                     }
 1061: 
 1062:                     pointeur_caractere_courant++;
 1063:                 }
 1064: 
 1065:                 if ((*pointeur_caractere_courant) != ')')
 1066:                 {
 1067:                     erreur_analyse = d_ex_syntaxe;
 1068:                 }
 1069: 
 1070:                 if (erreur_analyse == d_ex)
 1071:                 {
 1072:                     pointeur_caractere_courant++;
 1073:                 }
 1074: 
 1075:                 drapeau_fin_objet = d_vrai;
 1076:                 break;
 1077:             }
 1078: 
 1079:             case '#' :
 1080:             {
 1081:                 if (pointeur_debut_instruction !=
 1082:                         (pointeur_caractere_courant - 1))
 1083:                 {
 1084:                     erreur_format = d_ex_syntaxe;
 1085:                 }
 1086: 
 1087:                 while(((*pointeur_caractere_courant) != 'b') &&
 1088:                         ((*pointeur_caractere_courant) != 'o') &&
 1089:                         ((*pointeur_caractere_courant) != 'd') &&
 1090:                         ((*pointeur_caractere_courant) != 'h') &&
 1091:                         ((*pointeur_caractere_courant) !=
 1092:                         d_code_fin_chaine) &&
 1093:                         (erreur_analyse == d_ex))
 1094:                 {
 1095:                     switch(*pointeur_caractere_courant)
 1096:                     {
 1097:                         case ' ' :
 1098:                         case '0' :
 1099:                         case '1' :
 1100:                         case '2' :
 1101:                         case '3' :
 1102:                         case '4' :
 1103:                         case '5' :
 1104:                         case '6' :
 1105:                         case '7' :
 1106:                         case '8' :
 1107:                         case '9' :
 1108:                         case 'A' :
 1109:                         case 'B' :
 1110:                         case 'C' :
 1111:                         case 'D' :
 1112:                         case 'E' :
 1113:                         case 'F' :
 1114:                         case 'b' :
 1115:                         case 'o' :
 1116:                         case 'd' :
 1117:                         case 'h' :
 1118:                         {
 1119:                             break;
 1120:                         }
 1121: 
 1122:                         default :
 1123:                         {
 1124:                             erreur_analyse = d_ex_syntaxe;
 1125:                             break;
 1126:                         }
 1127:                     }
 1128: 
 1129:                     pointeur_caractere_courant++;
 1130:                 }
 1131: 
 1132:                 base_binaire = (*pointeur_caractere_courant);
 1133:                 pointeur_caractere_courant++;
 1134: 
 1135:                 if (((*pointeur_caractere_courant) != d_code_fin_chaine) &&
 1136:                         ((*pointeur_caractere_courant) != ' '))
 1137:                 {
 1138:                     erreur_analyse = d_ex_syntaxe;
 1139:                 }
 1140:                 else
 1141:                 {
 1142:                     pointeur_caractere_courant = pointeur_debut_instruction + 1;
 1143: 
 1144:                     switch(base_binaire)
 1145:                     {
 1146:                         case 'b' :
 1147:                         case 'o' :
 1148:                         case 'd' :
 1149:                         case 'h' :
 1150:                         {
 1151:                             break;
 1152:                         }
 1153: 
 1154:                         default :
 1155:                         {
 1156:                             erreur_analyse = d_ex_syntaxe;
 1157:                             break;
 1158:                         }
 1159:                     }
 1160:                 }
 1161: 
 1162:                 while(((*pointeur_caractere_courant) != base_binaire) &&
 1163:                         ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
 1164:                         (erreur_analyse == d_ex))
 1165:                 {
 1166:                     if (base_binaire == 'b')
 1167:                     {
 1168:                         switch(*pointeur_caractere_courant)
 1169:                         {
 1170:                             case ' ' :
 1171:                             case '0' :
 1172:                             case '1' :
 1173:                             {
 1174:                                 break;
 1175:                             }
 1176: 
 1177:                             default :
 1178:                             {
 1179:                                 erreur_analyse = d_ex_syntaxe;
 1180:                                 break;
 1181:                             }
 1182:                         }
 1183:                     }
 1184:                     else if (base_binaire == 'o')
 1185:                     {
 1186:                         switch(*pointeur_caractere_courant)
 1187:                         {
 1188:                             case ' ' :
 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:                             {
 1198:                                 break;
 1199:                             }
 1200: 
 1201:                             default :
 1202:                             {
 1203:                                 erreur_analyse = d_ex_syntaxe;
 1204:                                 break;
 1205:                             }
 1206:                         }
 1207:                     }
 1208:                     else if (base_binaire == 'd')
 1209:                     {
 1210:                         switch(*pointeur_caractere_courant)
 1211:                         {
 1212:                             case ' ' :
 1213:                             case '0' :
 1214:                             case '1' :
 1215:                             case '2' :
 1216:                             case '3' :
 1217:                             case '4' :
 1218:                             case '5' :
 1219:                             case '6' :
 1220:                             case '7' :
 1221:                             case '8' :
 1222:                             case '9' :
 1223:                             {
 1224:                                 break;
 1225:                             }
 1226: 
 1227:                             default :
 1228:                             {
 1229:                                 erreur_analyse = d_ex_syntaxe;
 1230:                                 break;
 1231:                             }
 1232:                         }
 1233:                     }
 1234:                     else if (base_binaire != 'h')
 1235:                     {
 1236:                         erreur_analyse = d_ex_syntaxe;
 1237:                     }
 1238: 
 1239:                     pointeur_caractere_courant++;
 1240:                 }
 1241: 
 1242:                 if (erreur_analyse == d_ex)
 1243:                 {
 1244:                     pointeur_caractere_courant++;
 1245:                 }
 1246: 
 1247:                 drapeau_fin_objet = d_vrai;
 1248:                 break;
 1249:             }
 1250: 
 1251:             case '{' :
 1252:             {
 1253:                 if (pointeur_debut_instruction !=
 1254:                         (pointeur_caractere_courant - 1))
 1255:                 {
 1256:                     erreur_format = d_ex_syntaxe;
 1257:                 }
 1258: 
 1259:                 niveau = 1;
 1260:                 niveau_annexe = 0;
 1261: 
 1262:                 while((niveau != 0) && ((*pointeur_caractere_courant) !=
 1263:                         d_code_fin_chaine))
 1264:                 {
 1265:                     switch(*pointeur_caractere_courant)
 1266:                     {
 1267:                         case '{' :
 1268:                         {
 1269:                             if (niveau_annexe == 0)
 1270:                             {
 1271:                                 niveau++;
 1272:                             }
 1273:                             else
 1274:                             {
 1275:                                 erreur_analyse = d_ex_syntaxe;
 1276:                             }
 1277: 
 1278:                             break;
 1279:                         }
 1280: 
 1281:                         case '}' :
 1282:                         {
 1283:                             if (niveau_annexe == 0)
 1284:                             {
 1285:                                 niveau--;
 1286:                             }
 1287:                             else
 1288:                             {
 1289:                                 erreur_analyse = d_ex_syntaxe;
 1290:                             }
 1291: 
 1292:                             break;
 1293:                         }
 1294: 
 1295:                         case '[' :
 1296:                         {
 1297:                             niveau_annexe++;
 1298: 
 1299:                             if (niveau_annexe > 2)
 1300:                             {
 1301:                                 erreur_analyse = d_ex_syntaxe;
 1302:                             }
 1303: 
 1304:                             break;
 1305:                         }
 1306: 
 1307:                         case ']' :
 1308:                         {
 1309:                             niveau_annexe--;
 1310: 
 1311:                             if (niveau_annexe < 0)
 1312:                             {
 1313:                                 erreur_analyse = d_ex_syntaxe;
 1314:                             }
 1315: 
 1316:                             break;
 1317:                         }
 1318: 
 1319:                         case '"' :
 1320:                         {
 1321:                             if (niveau_annexe == 0)
 1322:                             {
 1323:                                 pointeur_caractere_courant++;
 1324: 
 1325:                                 while((*pointeur_caractere_courant != '"') &&
 1326:                                         ((*pointeur_caractere_courant) !=
 1327:                                         d_code_fin_chaine))
 1328:                                 {
 1329:                                     if (*pointeur_caractere_courant == '\\')
 1330:                                     {
 1331:                                         pointeur_caractere_courant++;
 1332: 
 1333:                                         switch(*pointeur_caractere_courant)
 1334:                                         {
 1335:                                             case '\\' :
 1336:                                             case '"' :
 1337:                                             {
 1338:                                                 pointeur_caractere_courant++;
 1339:                                                 break;
 1340:                                             }
 1341:                                         }
 1342:                                     }
 1343:                                     else
 1344:                                     {
 1345:                                         pointeur_caractere_courant++;
 1346:                                     }
 1347:                                 }
 1348:                             }
 1349:                             else
 1350:                             {
 1351:                                 erreur_analyse = d_ex_syntaxe;
 1352:                             }
 1353: 
 1354:                             break;
 1355:                         }
 1356:                     }
 1357: 
 1358:                     pointeur_caractere_courant++;
 1359:                 }
 1360: 
 1361:                 if ((niveau != 0) || (niveau_annexe != 0))
 1362:                 {
 1363:                     erreur_analyse = d_ex_syntaxe;
 1364:                 }
 1365: 
 1366:                 drapeau_fin_objet = d_vrai;
 1367:                 break;
 1368:             }
 1369: 
 1370:             case '[' :
 1371:             {
 1372:                 if (pointeur_debut_instruction !=
 1373:                         (pointeur_caractere_courant - 1))
 1374:                 {
 1375:                     erreur_format = d_ex_syntaxe;
 1376:                 }
 1377: 
 1378:                 niveau = 1;
 1379: 
 1380:                 while((niveau > 0) && ((*pointeur_caractere_courant) !=
 1381:                         d_code_fin_chaine) && (erreur_analyse == d_ex))
 1382:                 {
 1383:                     switch(*pointeur_caractere_courant)
 1384:                     {
 1385:                         case '[' :
 1386:                         {
 1387:                             niveau++;
 1388:                             break;
 1389:                         }
 1390: 
 1391:                         case ']' :
 1392:                         {
 1393:                             niveau--;
 1394:                             break;
 1395:                         }
 1396: 
 1397:                         case '0' :
 1398:                         case '1' :
 1399:                         case '2' :
 1400:                         case '3' :
 1401:                         case '4' :
 1402:                         case '5' :
 1403:                         case '6' :
 1404:                         case '7' :
 1405:                         case '8' :
 1406:                         case '9' :
 1407:                         case '+' :
 1408:                         case '-' :
 1409:                         case 'e' :
 1410:                         case 'E' :
 1411:                         case '.' :
 1412:                         case ',' :
 1413:                         case '(' :
 1414:                         case ')' :
 1415:                         case ' ' :
 1416:                         {
 1417:                             break;
 1418:                         }
 1419: 
 1420:                         default :
 1421:                         {
 1422:                             erreur_analyse = d_ex_syntaxe;
 1423:                             break;
 1424:                         }
 1425:                     }
 1426: 
 1427:                     if (niveau < 0)
 1428:                     {
 1429:                         erreur_analyse = d_ex_syntaxe;
 1430:                     }
 1431:                     else if (niveau > 2)
 1432:                     {
 1433:                         erreur_format = d_ex_syntaxe;
 1434:                     }
 1435: 
 1436:                     pointeur_caractere_courant++;
 1437:                 }
 1438: 
 1439:                 if (niveau != 0)
 1440:                 {
 1441:                     erreur_analyse = d_ex_syntaxe;
 1442:                 }
 1443: 
 1444:                 drapeau_fin_objet = d_vrai;
 1445:                 break;
 1446:             }
 1447: 
 1448:             case '<' :
 1449:             {
 1450:                 if (((*s_etat_processus).autorisation_empilement_programme
 1451:                         == 'Y') && ((*pointeur_caractere_courant) == '<'))
 1452:                 {
 1453:                     if (pointeur_debut_instruction !=
 1454:                             (pointeur_caractere_courant - 1))
 1455:                     {
 1456:                         erreur_format = d_ex_syntaxe;
 1457:                     }
 1458: 
 1459:                     niveau = 1;
 1460: 
 1461:                     while((niveau != 0) && ((*pointeur_caractere_courant) !=
 1462:                             d_code_fin_chaine))
 1463:                     {
 1464:                         if (((*pointeur_caractere_courant) == '<') &&
 1465:                                 ((*(pointeur_caractere_courant + 1)) == '<'))
 1466:                         {
 1467:                             niveau++;
 1468:                             pointeur_caractere_courant++;
 1469:                         }
 1470:                         else if (((*pointeur_caractere_courant) == '>') &&
 1471:                                 ((*(pointeur_caractere_courant + 1)) == '>'))
 1472:                         {
 1473:                             niveau--;
 1474:                             pointeur_caractere_courant++;
 1475:                         }
 1476:                         else if ((*pointeur_caractere_courant) == '"')
 1477:                         {
 1478:                             pointeur_caractere_courant++;
 1479: 
 1480:                             while((*pointeur_caractere_courant != '"') &&
 1481:                                     ((*pointeur_caractere_courant) !=
 1482:                                     d_code_fin_chaine))
 1483:                             {
 1484:                                 if (*pointeur_caractere_courant == '\\')
 1485:                                 {
 1486:                                     pointeur_caractere_courant++;
 1487: 
 1488:                                     switch(*pointeur_caractere_courant)
 1489:                                     {
 1490:                                         case '\\' :
 1491:                                         case '"' :
 1492:                                         {
 1493:                                             pointeur_caractere_courant++;
 1494:                                             break;
 1495:                                         }
 1496:                                     }
 1497:                                 }
 1498:                                 else
 1499:                                 {
 1500:                                     pointeur_caractere_courant++;
 1501:                                 }
 1502:                             }
 1503:                         }
 1504: 
 1505:                         pointeur_caractere_courant++;
 1506:                     }
 1507: 
 1508:                     if (niveau != 0)
 1509:                     {
 1510:                         erreur_analyse = d_ex_syntaxe;
 1511:                     }
 1512: 
 1513:                     drapeau_fin_objet = d_vrai;
 1514:                 }
 1515:                 else if ((*pointeur_caractere_courant) == '[')
 1516:                 {
 1517:                     if (pointeur_debut_instruction !=
 1518:                             (pointeur_caractere_courant - 1))
 1519:                     {
 1520:                         erreur_format = d_ex_syntaxe;
 1521:                     }
 1522: 
 1523:                     pointeur_caractere_courant++;
 1524:                     drapeau_fin_objet = d_faux;
 1525: 
 1526:                     while(((*pointeur_caractere_courant) != d_code_fin_chaine)
 1527:                             && (erreur_format == d_absence_erreur))
 1528:                     {
 1529:                         while((*pointeur_caractere_courant) == d_code_espace)
 1530:                         {
 1531:                             pointeur_caractere_courant++;
 1532:                         }
 1533: 
 1534:                         if ((*pointeur_caractere_courant) == ']')
 1535:                         {
 1536:                             if ((*(++pointeur_caractere_courant)) == '>')
 1537:                             {
 1538:                                 drapeau_fin_objet = d_vrai;
 1539:                             }
 1540:                             else
 1541:                             {
 1542:                                 erreur_analyse = d_ex_syntaxe;
 1543:                             }
 1544: 
 1545:                             pointeur_caractere_courant++;
 1546:                             break;
 1547:                         }
 1548: 
 1549:                         if ((erreur_format == d_absence_erreur) &&
 1550:                                 (drapeau_fin_objet == d_faux))
 1551:                         {
 1552:                             (*s_etat_processus).position_courante =
 1553:                                     pointeur_caractere_courant
 1554:                                     - (*s_etat_processus).definitions_chainees;
 1555: 
 1556:                             if ((erreur = recherche_instruction_suivante(
 1557:                                     s_etat_processus)) != d_absence_erreur)
 1558:                             {
 1559:                                 if ((*s_etat_processus).instruction_courante
 1560:                                         != NULL)
 1561:                                 {
 1562:                                     free((*s_etat_processus)
 1563:                                             .instruction_courante);
 1564:                                 }
 1565: 
 1566:                                 return(d_erreur);
 1567:                             }
 1568: 
 1569:                             pointeur_caractere_courant = (*s_etat_processus)
 1570:                                     .definitions_chainees + (*s_etat_processus)
 1571:                                     .position_courante;
 1572: 
 1573:                             free((*s_etat_processus).instruction_courante);
 1574:                         }
 1575:                     }
 1576: 
 1577:                     if (drapeau_fin_objet == d_faux)
 1578:                     {
 1579:                         erreur_analyse = d_ex_syntaxe;
 1580:                         drapeau_fin_objet = d_vrai;
 1581:                     }
 1582:                 }
 1583: 
 1584:                 break;
 1585:             }
 1586:         }
 1587:     }
 1588: 
 1589:     pointeur_fin_instruction = pointeur_caractere_courant;
 1590: 
 1591:     (*s_etat_processus).instruction_courante = (unsigned char *)
 1592:                 malloc(((pointeur_fin_instruction - pointeur_debut_instruction)
 1593:                 + 1) * sizeof(unsigned char));
 1594: 
 1595:     if ((*s_etat_processus).instruction_courante == NULL)
 1596:     {
 1597:         erreur = d_erreur;
 1598:         (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
 1599:     }
 1600:     else if (pointeur_fin_instruction != pointeur_debut_instruction)
 1601:     {
 1602:         pointeur_caractere_courant = pointeur_debut_instruction;
 1603:         pointeur_caractere_destination =
 1604:                 (*s_etat_processus).instruction_courante;
 1605: 
 1606:         do
 1607:         {
 1608:             *pointeur_caractere_destination++ = *pointeur_caractere_courant++;
 1609:         } while(pointeur_caractere_courant < pointeur_fin_instruction);
 1610: 
 1611:         (*pointeur_caractere_destination) = d_code_fin_chaine;
 1612: 
 1613:         erreur = ((erreur_analyse == d_ex) && (erreur_format == d_ex))
 1614:                 ? d_absence_erreur : d_erreur;
 1615:         (*s_etat_processus).erreur_execution = erreur_analyse;
 1616:     }
 1617:     else
 1618:     {
 1619:         (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
 1620:     }
 1621: 
 1622:     (*s_etat_processus).position_courante = pointeur_fin_instruction
 1623:             - (*s_etat_processus).definitions_chainees;
 1624: 
 1625:     return(erreur);
 1626: }
 1627: 
 1628: 
 1629: /*
 1630: ================================================================================
 1631:   Routine mettant la chaine d'entrée en majuscule
 1632: ================================================================================
 1633:   Entrée : pointeur sur une chaine en minuscules.
 1634: --------------------------------------------------------------------------------
 1635:   Sortie : pointeur sur la chaine en majuscules. Si le pointeur retourné
 1636:     est nul, il s'est produit une erreur. L'allocation est faite dans la
 1637:     routine.
 1638: --------------------------------------------------------------------------------
 1639:   Effets de bord : néant.
 1640: ================================================================================
 1641: */
 1642: 
 1643: unsigned char *
 1644: conversion_majuscule(unsigned char *chaine)
 1645: {
 1646:     register unsigned char      *caractere_courant;
 1647:     register unsigned char      *caractere_courant_converti;
 1648:     register unsigned char      *chaine_convertie;
 1649: 
 1650:     unsigned long               longueur_chaine_plus_terminaison;
 1651: 
 1652:     longueur_chaine_plus_terminaison = 0;
 1653:     caractere_courant = chaine;
 1654: 
 1655:     while((*caractere_courant) != d_code_fin_chaine)
 1656:     {
 1657:         caractere_courant++;
 1658:         longueur_chaine_plus_terminaison++;
 1659:     }
 1660: 
 1661:     caractere_courant = chaine;
 1662:     caractere_courant_converti = chaine_convertie = (unsigned char *) malloc(
 1663:             (longueur_chaine_plus_terminaison + 1) * sizeof(unsigned char));
 1664: 
 1665:     if (chaine_convertie != NULL)
 1666:     {
 1667:         while((*caractere_courant) != d_code_fin_chaine)
 1668:         {
 1669:             if (isalpha((*caractere_courant)))
 1670:             {
 1671:                 (*caractere_courant_converti) = (unsigned char)
 1672:                         toupper((*caractere_courant));
 1673:             }
 1674:             else
 1675:             {
 1676:                 (*caractere_courant_converti) = (*caractere_courant);
 1677:             }
 1678: 
 1679:             caractere_courant++;
 1680:             caractere_courant_converti++;
 1681:         }
 1682: 
 1683:         (*caractere_courant_converti) = d_code_fin_chaine;
 1684:     }
 1685: 
 1686:     return(chaine_convertie);
 1687: }
 1688: 
 1689: void
 1690: conversion_majuscule_limitee(unsigned char *chaine_entree,
 1691:         unsigned char *chaine_sortie, unsigned long longueur)
 1692: {
 1693:     unsigned long           i;
 1694: 
 1695:     for(i = 0; i < longueur; i++)
 1696:     {
 1697:         if (isalpha((*chaine_entree)))
 1698:         {
 1699:             (*chaine_sortie) = (unsigned char) toupper((*chaine_entree));
 1700:         }
 1701:         else
 1702:         {
 1703:             (*chaine_sortie) = (*chaine_entree);
 1704:         }
 1705: 
 1706:         if ((*chaine_entree) == d_code_fin_chaine)
 1707:         {
 1708:             break;
 1709:         }
 1710: 
 1711:         chaine_entree++;
 1712:         chaine_sortie++;
 1713:     }
 1714: 
 1715:     return;
 1716: }
 1717: 
 1718: 
 1719: /*
 1720: ================================================================================
 1721:   Initialisation de l'état du calculateur
 1722:     Configuration par défaut d'un calculateur HP-28S
 1723: ================================================================================
 1724:   Entrée : pointeur sur la structure struct_processus
 1725: --------------------------------------------------------------------------------
 1726:   Sortie : néant
 1727: --------------------------------------------------------------------------------
 1728:   Effets de bord : néant
 1729: ================================================================================
 1730: */
 1731: 
 1732: void
 1733: initialisation_drapeaux(struct_processus *s_etat_processus)
 1734: {
 1735:     unsigned long                   i;
 1736: 
 1737:     for(i = 0; i < 31; cf(s_etat_processus, i++));
 1738: 
 1739:     if ((*s_etat_processus).lancement_interactif == d_vrai)
 1740:     {
 1741:         sf(s_etat_processus, 31);
 1742:                                 /* LAST autorisé                            */
 1743:     }
 1744:     else
 1745:     {
 1746:         cf(s_etat_processus, 31);
 1747:                                 /* LAST invalidé                            */
 1748:     }
 1749: 
 1750:     cf(s_etat_processus, 32);   /* Impression automatique                   */
 1751:     cf(s_etat_processus, 33);   /* CR automatique (disp)                    */
 1752:     cf(s_etat_processus, 34);   /* Valeur principale (intervalle de déf.)   */
 1753:     sf(s_etat_processus, 35);   /* Evaluation symbolique des constantes     */
 1754:     sf(s_etat_processus, 36);   /* Evaluation symbolique des fonctions      */
 1755:     sf(s_etat_processus, 37);   /* Taille de mot pour les entiers binaires  */
 1756:     sf(s_etat_processus, 38);   /* Taille de mot pour les entiers binaires  */
 1757:     sf(s_etat_processus, 39);   /* Taille de mot pour les entiers binaires  */
 1758:     sf(s_etat_processus, 40);   /* Taille de mot pour les entiers binaires  */
 1759:     sf(s_etat_processus, 41);   /* Taille de mot pour les entiers binaires  */
 1760:     sf(s_etat_processus, 42);   /* Taille de mot pour les entiers binaires  */
 1761: /*
 1762: 37 : bit de poids faible
 1763: 42 : bit de poids fort
 1764: Les six drapeaux peuvent être nuls. Dans ce cas, la longueur des mots
 1765: binaires reste de un bit.
 1766: */
 1767:     cf(s_etat_processus, 43);   /* Base de numération binaire               */
 1768:     cf(s_etat_processus, 44);   /* Base de numération binaire               */
 1769: /*
 1770: 43 44 = 00 => décimal
 1771: 43 44 = 01 => binaire
 1772: 43 44 = 10 => octal
 1773: 43 44 = 11 => hexadécimal
 1774: */
 1775:     sf(s_etat_processus, 45);   /* Affichage multiligne du niveau 1         */
 1776:     cf(s_etat_processus, 46);   /* Réservé                                  */
 1777:     cf(s_etat_processus, 47);   /* Réservé                                  */
 1778: /*
 1779: 46 et 47 réservés sur le calculateur HP28S
 1780: 46 47 = 00 => système rectangulaire
 1781: 46 47 = 01 => système cylindrique
 1782: 46 47 = 10 => système sphérique
 1783: */
 1784:     cf(s_etat_processus, 48);   /* Séparateur décimal                       */
 1785:     cf(s_etat_processus, 49);   /* Format des nombres réels                 */
 1786:     cf(s_etat_processus, 50);   /* Format des nombres réels                 */
 1787: /*
 1788: 49 50 = 00 => standard
 1789: 49 50 = 01 => scientifique
 1790: 49 50 = 10 => virgule fixe
 1791: 49 50 = 11 => ingénieur
 1792: */
 1793:     cf(s_etat_processus, 51);   /* Tonalité                                 */
 1794:     cf(s_etat_processus, 52);   /* REDRAW automatique                       */
 1795:     cf(s_etat_processus, 53);   /* Nombre de chiffres décimaux              */
 1796:     cf(s_etat_processus, 54);   /* Nombre de chiffres décimaux              */
 1797:     cf(s_etat_processus, 55);   /* Nombre de chiffres décimaux              */
 1798:     cf(s_etat_processus, 56);   /* Nombre de chiffres décimaux              */
 1799: /*
 1800: 53 : bit de poids faible
 1801: 56 : bit de poids fort
 1802: */
 1803:     cf(s_etat_processus, 57);   /* Underflow traité normalement             */
 1804:     cf(s_etat_processus, 58);   /* Overflow traité normalement              */
 1805:     sf(s_etat_processus, 59);   /* Infinite result traité normalement       */
 1806:     sf(s_etat_processus, 60);   /* Angles                                   */
 1807: /*
 1808: 60 = 0 => degrés
 1809: 60 = 1 => radians
 1810: */
 1811:     cf(s_etat_processus, 61);   /* Underflow- traité en exception           */
 1812:     cf(s_etat_processus, 62);   /* Underflow+ traité en exception           */
 1813:     cf(s_etat_processus, 63);   /* Overflow traité en exception             */
 1814:     cf(s_etat_processus, 64);   /* Infinite result traité en exception      */
 1815: }
 1816: 
 1817: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>