Annotation of rpl/src/compilation.c, revision 1.47

1.1       bertrand    1: /*
                      2: ================================================================================
1.47    ! bertrand    3:   RPL/2 (R) version 4.1.10
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: 
                    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: ================================================================================
1.39      bertrand  814:   Procédure de d'analyse syntaxique du source pour readline
                    815: ================================================================================
                    816:   Entrées :
                    817: --------------------------------------------------------------------------------
                    818:   Sorties :
                    819:    - rl_done à 0 ou à 1.
                    820: --------------------------------------------------------------------------------
                    821:   Effets de bord :
                    822: ================================================================================
                    823: */
                    824: 
1.40      bertrand  825: static char                    *ligne = NULL;
                    826: static unsigned int            niveau = 0;
                    827: 
1.39      bertrand  828: int
                    829: readline_analyse_syntaxique(int count, int key)
                    830: {
1.40      bertrand  831:    char                        prompt[] = "+ %03d> ";
                    832:    char                        prompt2[8];
                    833:    char                        *registre;
                    834: 
1.39      bertrand  835:    struct_processus            s_etat_processus;
                    836: 
                    837:    if ((*rl_line_buffer) == d_code_fin_chaine)
                    838:    {
1.40      bertrand  839:        if (ligne == NULL)
                    840:        {
                    841:            rl_done = 1;
                    842:        }
                    843:        else
                    844:        {
                    845:            rl_done = 0;
                    846:        }
1.39      bertrand  847:    }
                    848:    else
                    849:    {
1.40      bertrand  850:        if (ligne == NULL)
                    851:        {
                    852:            if ((ligne = malloc((strlen(rl_line_buffer) + 1)
                    853:                    * sizeof(char))) == NULL)
                    854:            {
                    855:                rl_done = 1;
                    856:                return(0);
                    857:            }
                    858: 
                    859:            strcpy(ligne, rl_line_buffer);
                    860:        }
                    861:        else
                    862:        {
                    863:            registre = ligne;
                    864: 
                    865:            if ((ligne = malloc((strlen(registre)
1.41      bertrand  866:                    + strlen(rl_line_buffer) + 2) * sizeof(char))) == NULL)
1.40      bertrand  867:            {
                    868:                rl_done = 1;
                    869:                return(0);
                    870:            }
                    871: 
1.41      bertrand  872:            sprintf(ligne, "%s %s", registre, rl_line_buffer);
1.40      bertrand  873:        }
                    874: 
                    875:        rl_replace_line("", 1);
                    876: 
                    877:        s_etat_processus.definitions_chainees = ligne;
                    878:        s_etat_processus.debug = d_faux;
                    879:        s_etat_processus.erreur_systeme = d_es;
                    880:        s_etat_processus.erreur_execution = d_ex;
                    881: 
1.39      bertrand  882:        if (analyse_syntaxique(&s_etat_processus) == d_absence_erreur)
                    883:        {
                    884:            rl_done = 1;
                    885:        }
                    886:        else
                    887:        {
1.40      bertrand  888:            if (s_etat_processus.erreur_systeme != d_es)
                    889:            {
                    890:                rl_done = 1;
                    891:            }
                    892:            else
                    893:            {
                    894:                rl_done = 0;
                    895:                rl_crlf();
                    896: 
                    897:                sprintf(prompt2, prompt, ++niveau);
                    898: 
                    899:                rl_expand_prompt(prompt2);
                    900:                rl_on_new_line();
                    901:            }
1.39      bertrand  902:        }
                    903:    }
                    904: 
                    905:    if (rl_done != 0)
                    906:    {
                    907:        uprintf("\n");
1.40      bertrand  908: 
                    909:        if (ligne != NULL)
                    910:        {
                    911:            rl_replace_line(ligne, 1);
                    912: 
                    913:            free(ligne);
                    914:            ligne = NULL;
                    915:        }
                    916: 
                    917:        niveau = 0;
1.39      bertrand  918:    }
                    919: 
                    920:    return(0);
                    921: }
                    922: 
1.40      bertrand  923: int
                    924: readline_effacement(int count, int key)
                    925: {
                    926:    rl_done = 0;
                    927:    rl_replace_line("", 1);
                    928: 
                    929:    free(ligne);
                    930:    ligne = NULL;
                    931:    niveau = 0;
                    932: 
1.43      bertrand  933:    uprintf("^G\n");
1.40      bertrand  934:    rl_expand_prompt("RPL/2> ");
                    935:    rl_on_new_line();
                    936:    return(0);
                    937: }
1.39      bertrand  938: 
1.41      bertrand  939: 
1.39      bertrand  940: /*
                    941: ================================================================================
1.1       bertrand  942:   Routine d'échange de deux variables
                    943: ================================================================================
                    944:   Entrées :
                    945:    -   pointeurs génériques sur les deux variables,
                    946:    -   longueur en octet des objets à permuter.
                    947: --------------------------------------------------------------------------------
                    948:   Sorties : idem.
                    949: --------------------------------------------------------------------------------
                    950:   Effets de bord : néant.
                    951: ================================================================================
                    952: */
                    953: 
                    954: void
                    955: swap(void *variable_1, void *variable_2, unsigned long taille)
                    956: {
                    957:    register unsigned char      *t_var_1;
                    958:    register unsigned char      *t_var_2;
                    959:    register unsigned char      variable_temporaire;
                    960: 
1.14      bertrand  961:    register unsigned long      i;
1.1       bertrand  962: 
                    963:    t_var_1 = (unsigned char *) variable_1;
                    964:    t_var_2 = (unsigned char *) variable_2;
                    965: 
1.14      bertrand  966:    for(i = 0; i < taille; i++)
1.1       bertrand  967:    {
1.14      bertrand  968:        variable_temporaire = (*t_var_1);
                    969:        (*(t_var_1++)) = (*t_var_2);
                    970:        (*(t_var_2++)) = variable_temporaire;
1.1       bertrand  971:    }
1.14      bertrand  972: 
                    973:    return;
1.1       bertrand  974: }
                    975: 
                    976: 
                    977: /*
                    978: ================================================================================
                    979:   Routine recherchant l'instruction suivante dans le programme compilé
                    980: ================================================================================
                    981:   Entrée :
                    982: --------------------------------------------------------------------------------
                    983:   Sortie :
                    984: --------------------------------------------------------------------------------
                    985:   Effets de bord : néant.
                    986: ================================================================================
                    987: */
                    988: 
                    989: logical1
                    990: recherche_instruction_suivante(struct_processus *s_etat_processus)
                    991: {
                    992:    logical1                    drapeau_fin_objet;
                    993:    logical1                    erreur;
                    994:    logical1                    erreur_analyse;
                    995:    logical1                    erreur_format;
                    996: 
                    997:    unsigned char               base_binaire;
                    998:    unsigned char               *pointeur_caractere_courant;
                    999:    unsigned char               *pointeur_caractere_destination;
                   1000:    unsigned char               *pointeur_debut_instruction;
                   1001:    unsigned char               *pointeur_fin_instruction;
                   1002: 
                   1003:    signed long                 niveau;
                   1004:    signed long                 niveau_annexe;
                   1005: 
                   1006:    erreur_analyse = d_ex;
                   1007:    erreur_format = d_ex;
                   1008:    erreur = d_absence_erreur;
                   1009: 
                   1010:    drapeau_fin_objet = d_faux;
                   1011:    niveau = 0;
                   1012: 
                   1013:    pointeur_caractere_courant = (*s_etat_processus).definitions_chainees +
                   1014:            (*s_etat_processus).position_courante;
                   1015: 
                   1016:    while(((*pointeur_caractere_courant) == d_code_espace) &&
                   1017:            ((*pointeur_caractere_courant) != d_code_fin_chaine))
                   1018:    {
                   1019:        pointeur_caractere_courant++;
                   1020:    }
                   1021: 
                   1022:    if ((*pointeur_caractere_courant) == d_code_fin_chaine)
                   1023:    {
                   1024:        (*s_etat_processus).instruction_courante = (unsigned char *)
                   1025:                malloc(sizeof(unsigned char));
                   1026: 
                   1027:        if ((*s_etat_processus).instruction_courante == NULL)
                   1028:        {
                   1029:            erreur = d_erreur;
                   1030:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1031:        }
                   1032:        else
                   1033:        {
                   1034:            erreur = d_absence_erreur;
                   1035:            (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
                   1036:            (*s_etat_processus).position_courante = pointeur_caractere_courant
                   1037:                    - (*s_etat_processus).definitions_chainees;
                   1038:        }
                   1039: 
                   1040:        return(erreur);
                   1041:    }
                   1042: 
                   1043:    pointeur_debut_instruction = pointeur_caractere_courant;
                   1044: 
                   1045:    while(((*pointeur_caractere_courant) != d_code_espace) &&
                   1046:            ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
                   1047:            (drapeau_fin_objet == d_faux) &&
                   1048:            (erreur_analyse == d_ex) &&
                   1049:            (erreur_format == d_ex))
                   1050:    {
                   1051:        switch(*pointeur_caractere_courant++)
                   1052:        {
                   1053:            case ']' :
                   1054:            case '}' :
                   1055:            case ')' :
                   1056:            {
                   1057:                erreur_format = d_ex_syntaxe;
                   1058:                break;
                   1059:            }
                   1060: 
                   1061:            case '"' :
                   1062:            {
                   1063:                if (pointeur_debut_instruction !=
                   1064:                        (pointeur_caractere_courant - 1))
                   1065:                {
                   1066:                    erreur_format = d_ex_syntaxe;
                   1067:                }
                   1068: 
                   1069:                while((*pointeur_caractere_courant != '"') &&
                   1070:                        ((*pointeur_caractere_courant) != d_code_fin_chaine))
                   1071:                {
                   1072:                    if (*pointeur_caractere_courant == '\\')
                   1073:                    {
                   1074:                        pointeur_caractere_courant++;
                   1075: 
                   1076:                        switch(*pointeur_caractere_courant)
                   1077:                        {
                   1078:                            case '\\' :
                   1079:                            case '"' :
                   1080:                            {
                   1081:                                pointeur_caractere_courant++;
                   1082:                                break;
                   1083:                            }
                   1084:                        }
                   1085:                    }
                   1086:                    else
                   1087:                    {
                   1088:                        pointeur_caractere_courant++;
                   1089:                    }
                   1090:                }
                   1091: 
                   1092:                if ((*pointeur_caractere_courant) != '"')
                   1093:                {
                   1094:                    erreur_analyse = d_ex_syntaxe;
                   1095:                }
                   1096: 
                   1097:                if (erreur_analyse == d_ex)
                   1098:                {
                   1099:                    pointeur_caractere_courant++;
                   1100:                }
                   1101: 
                   1102:                drapeau_fin_objet = d_vrai;
                   1103:                break;
                   1104:            }
                   1105: 
                   1106:            case '\'' :
                   1107:            {
                   1108:                if (pointeur_debut_instruction !=
                   1109:                        (pointeur_caractere_courant - 1))
                   1110:                {
                   1111:                    erreur_format = d_ex_syntaxe;
                   1112:                }
                   1113: 
                   1114:                while(((*pointeur_caractere_courant) != '\'') &&
                   1115:                        ((*pointeur_caractere_courant) != d_code_fin_chaine))
                   1116:                {
                   1117:                    if ((*pointeur_caractere_courant) == '(')
                   1118:                    {
                   1119:                        niveau++;
                   1120:                    }
                   1121:                    else if ((*pointeur_caractere_courant) == ')')
                   1122:                    {
                   1123:                        niveau--;
                   1124:                    }
                   1125: 
                   1126:                    pointeur_caractere_courant++;
                   1127:                }
                   1128: 
                   1129:                if ((*pointeur_caractere_courant) != '\'')
                   1130:                {
                   1131:                    erreur_analyse = d_ex_syntaxe;
                   1132:                }
                   1133:                else if (niveau != 0)
                   1134:                {
                   1135:                    erreur_analyse = d_ex_syntaxe;
                   1136:                }
                   1137: 
                   1138:                if (erreur_analyse == d_ex)
                   1139:                {
                   1140:                    pointeur_caractere_courant++;
                   1141:                }
                   1142: 
                   1143:                drapeau_fin_objet = d_vrai;
                   1144:                break;
                   1145:            }
                   1146: 
                   1147:            case '(' :
                   1148:            {
                   1149:                if (pointeur_debut_instruction !=
                   1150:                        (pointeur_caractere_courant - 1))
                   1151:                {
                   1152:                    erreur_format = d_ex_syntaxe;
                   1153:                }
                   1154: 
                   1155:                while(((*pointeur_caractere_courant) != ')') &&
                   1156:                        ((*pointeur_caractere_courant) != d_code_fin_chaine)
                   1157:                        && (erreur_analyse == d_ex))
                   1158:                {
                   1159:                    switch(*pointeur_caractere_courant)
                   1160:                    {
                   1161:                        case '0' :
                   1162:                        case '1' :
                   1163:                        case '2' :
                   1164:                        case '3' :
                   1165:                        case '4' :
                   1166:                        case '5' :
                   1167:                        case '6' :
                   1168:                        case '7' :
                   1169:                        case '8' :
                   1170:                        case '9' :
                   1171:                        case 'e' :
                   1172:                        case 'E' :
                   1173:                        case ',' :
                   1174:                        case '.' :
                   1175:                        case ' ' :
                   1176:                        case '-' :
                   1177:                        case '+' :
                   1178:                        case ')' :
                   1179:                        {
                   1180:                            break;
                   1181:                        }
                   1182: 
                   1183:                        default :
                   1184:                        {
                   1185:                            erreur_analyse = d_ex_syntaxe;
                   1186:                            break;
                   1187:                        }
                   1188:                    }
                   1189: 
                   1190:                    pointeur_caractere_courant++;
                   1191:                }
                   1192: 
                   1193:                if ((*pointeur_caractere_courant) != ')')
                   1194:                {
                   1195:                    erreur_analyse = d_ex_syntaxe;
                   1196:                }
                   1197: 
                   1198:                if (erreur_analyse == d_ex)
                   1199:                {
                   1200:                    pointeur_caractere_courant++;
                   1201:                }
                   1202: 
                   1203:                drapeau_fin_objet = d_vrai;
                   1204:                break;
                   1205:            }
                   1206: 
                   1207:            case '#' :
                   1208:            {
                   1209:                if (pointeur_debut_instruction !=
                   1210:                        (pointeur_caractere_courant - 1))
                   1211:                {
                   1212:                    erreur_format = d_ex_syntaxe;
                   1213:                }
                   1214: 
                   1215:                while(((*pointeur_caractere_courant) != 'b') &&
                   1216:                        ((*pointeur_caractere_courant) != 'o') &&
                   1217:                        ((*pointeur_caractere_courant) != 'd') &&
                   1218:                        ((*pointeur_caractere_courant) != 'h') &&
                   1219:                        ((*pointeur_caractere_courant) !=
                   1220:                        d_code_fin_chaine) &&
                   1221:                        (erreur_analyse == d_ex))
                   1222:                {
                   1223:                    switch(*pointeur_caractere_courant)
                   1224:                    {
                   1225:                        case ' ' :
                   1226:                        case '0' :
                   1227:                        case '1' :
                   1228:                        case '2' :
                   1229:                        case '3' :
                   1230:                        case '4' :
                   1231:                        case '5' :
                   1232:                        case '6' :
                   1233:                        case '7' :
                   1234:                        case '8' :
                   1235:                        case '9' :
                   1236:                        case 'A' :
                   1237:                        case 'B' :
                   1238:                        case 'C' :
                   1239:                        case 'D' :
                   1240:                        case 'E' :
                   1241:                        case 'F' :
                   1242:                        case 'b' :
                   1243:                        case 'o' :
                   1244:                        case 'd' :
                   1245:                        case 'h' :
                   1246:                        {
                   1247:                            break;
                   1248:                        }
                   1249: 
                   1250:                        default :
                   1251:                        {
                   1252:                            erreur_analyse = d_ex_syntaxe;
                   1253:                            break;
                   1254:                        }
                   1255:                    }
                   1256: 
                   1257:                    pointeur_caractere_courant++;
                   1258:                }
                   1259: 
                   1260:                base_binaire = (*pointeur_caractere_courant);
                   1261:                pointeur_caractere_courant++;
                   1262: 
                   1263:                if (((*pointeur_caractere_courant) != d_code_fin_chaine) &&
                   1264:                        ((*pointeur_caractere_courant) != ' '))
                   1265:                {
                   1266:                    erreur_analyse = d_ex_syntaxe;
                   1267:                }
                   1268:                else
                   1269:                {
                   1270:                    pointeur_caractere_courant = pointeur_debut_instruction + 1;
                   1271: 
                   1272:                    switch(base_binaire)
                   1273:                    {
                   1274:                        case 'b' :
                   1275:                        case 'o' :
                   1276:                        case 'd' :
                   1277:                        case 'h' :
                   1278:                        {
                   1279:                            break;
                   1280:                        }
                   1281: 
                   1282:                        default :
                   1283:                        {
                   1284:                            erreur_analyse = d_ex_syntaxe;
                   1285:                            break;
                   1286:                        }
                   1287:                    }
                   1288:                }
                   1289: 
                   1290:                while(((*pointeur_caractere_courant) != base_binaire) &&
                   1291:                        ((*pointeur_caractere_courant) != d_code_fin_chaine) &&
                   1292:                        (erreur_analyse == d_ex))
                   1293:                {
                   1294:                    if (base_binaire == 'b')
                   1295:                    {
                   1296:                        switch(*pointeur_caractere_courant)
                   1297:                        {
                   1298:                            case ' ' :
                   1299:                            case '0' :
                   1300:                            case '1' :
                   1301:                            {
                   1302:                                break;
                   1303:                            }
                   1304: 
                   1305:                            default :
                   1306:                            {
                   1307:                                erreur_analyse = d_ex_syntaxe;
                   1308:                                break;
                   1309:                            }
                   1310:                        }
                   1311:                    }
                   1312:                    else if (base_binaire == 'o')
                   1313:                    {
                   1314:                        switch(*pointeur_caractere_courant)
                   1315:                        {
                   1316:                            case ' ' :
                   1317:                            case '0' :
                   1318:                            case '1' :
                   1319:                            case '2' :
                   1320:                            case '3' :
                   1321:                            case '4' :
                   1322:                            case '5' :
                   1323:                            case '6' :
                   1324:                            case '7' :
                   1325:                            {
                   1326:                                break;
                   1327:                            }
                   1328: 
                   1329:                            default :
                   1330:                            {
                   1331:                                erreur_analyse = d_ex_syntaxe;
                   1332:                                break;
                   1333:                            }
                   1334:                        }
                   1335:                    }
                   1336:                    else if (base_binaire == 'd')
                   1337:                    {
                   1338:                        switch(*pointeur_caractere_courant)
                   1339:                        {
                   1340:                            case ' ' :
                   1341:                            case '0' :
                   1342:                            case '1' :
                   1343:                            case '2' :
                   1344:                            case '3' :
                   1345:                            case '4' :
                   1346:                            case '5' :
                   1347:                            case '6' :
                   1348:                            case '7' :
                   1349:                            case '8' :
                   1350:                            case '9' :
                   1351:                            {
                   1352:                                break;
                   1353:                            }
                   1354: 
                   1355:                            default :
                   1356:                            {
                   1357:                                erreur_analyse = d_ex_syntaxe;
                   1358:                                break;
                   1359:                            }
                   1360:                        }
                   1361:                    }
                   1362:                    else if (base_binaire != 'h')
                   1363:                    {
                   1364:                        erreur_analyse = d_ex_syntaxe;
                   1365:                    }
                   1366: 
                   1367:                    pointeur_caractere_courant++;
                   1368:                }
                   1369: 
                   1370:                if (erreur_analyse == d_ex)
                   1371:                {
                   1372:                    pointeur_caractere_courant++;
                   1373:                }
                   1374: 
                   1375:                drapeau_fin_objet = d_vrai;
                   1376:                break;
                   1377:            }
                   1378: 
                   1379:            case '{' :
                   1380:            {
                   1381:                if (pointeur_debut_instruction !=
                   1382:                        (pointeur_caractere_courant - 1))
                   1383:                {
                   1384:                    erreur_format = d_ex_syntaxe;
                   1385:                }
                   1386: 
                   1387:                niveau = 1;
                   1388:                niveau_annexe = 0;
                   1389: 
                   1390:                while((niveau != 0) && ((*pointeur_caractere_courant) !=
                   1391:                        d_code_fin_chaine))
                   1392:                {
                   1393:                    switch(*pointeur_caractere_courant)
                   1394:                    {
                   1395:                        case '{' :
                   1396:                        {
                   1397:                            if (niveau_annexe == 0)
                   1398:                            {
                   1399:                                niveau++;
                   1400:                            }
                   1401:                            else
                   1402:                            {
                   1403:                                erreur_analyse = d_ex_syntaxe;
                   1404:                            }
                   1405: 
                   1406:                            break;
                   1407:                        }
                   1408: 
                   1409:                        case '}' :
                   1410:                        {
                   1411:                            if (niveau_annexe == 0)
                   1412:                            {
                   1413:                                niveau--;
                   1414:                            }
                   1415:                            else
                   1416:                            {
                   1417:                                erreur_analyse = d_ex_syntaxe;
                   1418:                            }
                   1419: 
                   1420:                            break;
                   1421:                        }
                   1422: 
                   1423:                        case '[' :
                   1424:                        {
                   1425:                            niveau_annexe++;
                   1426: 
                   1427:                            if (niveau_annexe > 2)
                   1428:                            {
                   1429:                                erreur_analyse = d_ex_syntaxe;
                   1430:                            }
                   1431: 
                   1432:                            break;
                   1433:                        }
                   1434: 
                   1435:                        case ']' :
                   1436:                        {
                   1437:                            niveau_annexe--;
                   1438: 
                   1439:                            if (niveau_annexe < 0)
                   1440:                            {
                   1441:                                erreur_analyse = d_ex_syntaxe;
                   1442:                            }
                   1443: 
                   1444:                            break;
                   1445:                        }
                   1446: 
                   1447:                        case '"' :
                   1448:                        {
                   1449:                            if (niveau_annexe == 0)
                   1450:                            {
                   1451:                                pointeur_caractere_courant++;
                   1452: 
                   1453:                                while((*pointeur_caractere_courant != '"') &&
                   1454:                                        ((*pointeur_caractere_courant) !=
                   1455:                                        d_code_fin_chaine))
                   1456:                                {
                   1457:                                    if (*pointeur_caractere_courant == '\\')
                   1458:                                    {
                   1459:                                        pointeur_caractere_courant++;
                   1460: 
                   1461:                                        switch(*pointeur_caractere_courant)
                   1462:                                        {
                   1463:                                            case '\\' :
                   1464:                                            case '"' :
                   1465:                                            {
                   1466:                                                pointeur_caractere_courant++;
                   1467:                                                break;
                   1468:                                            }
                   1469:                                        }
                   1470:                                    }
                   1471:                                    else
                   1472:                                    {
                   1473:                                        pointeur_caractere_courant++;
                   1474:                                    }
                   1475:                                }
                   1476:                            }
                   1477:                            else
                   1478:                            {
                   1479:                                erreur_analyse = d_ex_syntaxe;
                   1480:                            }
                   1481: 
                   1482:                            break;
                   1483:                        }
                   1484:                    }
                   1485: 
                   1486:                    pointeur_caractere_courant++;
                   1487:                }
                   1488: 
                   1489:                if ((niveau != 0) || (niveau_annexe != 0))
                   1490:                {
                   1491:                    erreur_analyse = d_ex_syntaxe;
                   1492:                }
                   1493: 
                   1494:                drapeau_fin_objet = d_vrai;
                   1495:                break;
                   1496:            }
                   1497: 
                   1498:            case '[' :
                   1499:            {
                   1500:                if (pointeur_debut_instruction !=
                   1501:                        (pointeur_caractere_courant - 1))
                   1502:                {
                   1503:                    erreur_format = d_ex_syntaxe;
                   1504:                }
                   1505: 
                   1506:                niveau = 1;
                   1507: 
                   1508:                while((niveau > 0) && ((*pointeur_caractere_courant) !=
                   1509:                        d_code_fin_chaine) && (erreur_analyse == d_ex))
                   1510:                {
                   1511:                    switch(*pointeur_caractere_courant)
                   1512:                    {
                   1513:                        case '[' :
                   1514:                        {
                   1515:                            niveau++;
                   1516:                            break;
                   1517:                        }
                   1518: 
                   1519:                        case ']' :
                   1520:                        {
                   1521:                            niveau--;
                   1522:                            break;
                   1523:                        }
                   1524: 
                   1525:                        case '0' :
                   1526:                        case '1' :
                   1527:                        case '2' :
                   1528:                        case '3' :
                   1529:                        case '4' :
                   1530:                        case '5' :
                   1531:                        case '6' :
                   1532:                        case '7' :
                   1533:                        case '8' :
                   1534:                        case '9' :
                   1535:                        case '+' :
                   1536:                        case '-' :
                   1537:                        case 'e' :
                   1538:                        case 'E' :
                   1539:                        case '.' :
                   1540:                        case ',' :
                   1541:                        case '(' :
                   1542:                        case ')' :
                   1543:                        case ' ' :
                   1544:                        {
                   1545:                            break;
                   1546:                        }
                   1547: 
                   1548:                        default :
                   1549:                        {
                   1550:                            erreur_analyse = d_ex_syntaxe;
                   1551:                            break;
                   1552:                        }
                   1553:                    }
                   1554: 
                   1555:                    if (niveau < 0)
                   1556:                    {
                   1557:                        erreur_analyse = d_ex_syntaxe;
                   1558:                    }
                   1559:                    else if (niveau > 2)
                   1560:                    {
                   1561:                        erreur_format = d_ex_syntaxe;
                   1562:                    }
                   1563: 
                   1564:                    pointeur_caractere_courant++;
                   1565:                }
                   1566: 
                   1567:                if (niveau != 0)
                   1568:                {
                   1569:                    erreur_analyse = d_ex_syntaxe;
                   1570:                }
                   1571: 
                   1572:                drapeau_fin_objet = d_vrai;
                   1573:                break;
                   1574:            }
                   1575: 
                   1576:            case '<' :
                   1577:            {
                   1578:                if (((*s_etat_processus).autorisation_empilement_programme
                   1579:                        == 'Y') && ((*pointeur_caractere_courant) == '<'))
                   1580:                {
                   1581:                    if (pointeur_debut_instruction !=
                   1582:                            (pointeur_caractere_courant - 1))
                   1583:                    {
                   1584:                        erreur_format = d_ex_syntaxe;
                   1585:                    }
                   1586: 
                   1587:                    niveau = 1;
                   1588: 
                   1589:                    while((niveau != 0) && ((*pointeur_caractere_courant) !=
                   1590:                            d_code_fin_chaine))
                   1591:                    {
                   1592:                        if (((*pointeur_caractere_courant) == '<') &&
                   1593:                                ((*(pointeur_caractere_courant + 1)) == '<'))
                   1594:                        {
                   1595:                            niveau++;
                   1596:                            pointeur_caractere_courant++;
                   1597:                        }
                   1598:                        else if (((*pointeur_caractere_courant) == '>') &&
                   1599:                                ((*(pointeur_caractere_courant + 1)) == '>'))
                   1600:                        {
                   1601:                            niveau--;
                   1602:                            pointeur_caractere_courant++;
                   1603:                        }
                   1604:                        else if ((*pointeur_caractere_courant) == '"')
                   1605:                        {
                   1606:                            pointeur_caractere_courant++;
                   1607: 
                   1608:                            while((*pointeur_caractere_courant != '"') &&
                   1609:                                    ((*pointeur_caractere_courant) !=
                   1610:                                    d_code_fin_chaine))
                   1611:                            {
                   1612:                                if (*pointeur_caractere_courant == '\\')
                   1613:                                {
                   1614:                                    pointeur_caractere_courant++;
                   1615: 
                   1616:                                    switch(*pointeur_caractere_courant)
                   1617:                                    {
                   1618:                                        case '\\' :
                   1619:                                        case '"' :
                   1620:                                        {
                   1621:                                            pointeur_caractere_courant++;
                   1622:                                            break;
                   1623:                                        }
                   1624:                                    }
                   1625:                                }
                   1626:                                else
                   1627:                                {
                   1628:                                    pointeur_caractere_courant++;
                   1629:                                }
                   1630:                            }
                   1631:                        }
                   1632: 
                   1633:                        pointeur_caractere_courant++;
                   1634:                    }
                   1635: 
                   1636:                    if (niveau != 0)
                   1637:                    {
                   1638:                        erreur_analyse = d_ex_syntaxe;
                   1639:                    }
                   1640: 
                   1641:                    drapeau_fin_objet = d_vrai;
                   1642:                }
                   1643:                else if ((*pointeur_caractere_courant) == '[')
                   1644:                {
                   1645:                    if (pointeur_debut_instruction !=
                   1646:                            (pointeur_caractere_courant - 1))
                   1647:                    {
                   1648:                        erreur_format = d_ex_syntaxe;
                   1649:                    }
                   1650: 
                   1651:                    pointeur_caractere_courant++;
                   1652:                    drapeau_fin_objet = d_faux;
                   1653: 
                   1654:                    while(((*pointeur_caractere_courant) != d_code_fin_chaine)
                   1655:                            && (erreur_format == d_absence_erreur))
                   1656:                    {
                   1657:                        while((*pointeur_caractere_courant) == d_code_espace)
                   1658:                        {
                   1659:                            pointeur_caractere_courant++;
                   1660:                        }
                   1661: 
                   1662:                        if ((*pointeur_caractere_courant) == ']')
                   1663:                        {
                   1664:                            if ((*(++pointeur_caractere_courant)) == '>')
                   1665:                            {
                   1666:                                drapeau_fin_objet = d_vrai;
                   1667:                            }
                   1668:                            else
                   1669:                            {
                   1670:                                erreur_analyse = d_ex_syntaxe;
                   1671:                            }
                   1672: 
                   1673:                            pointeur_caractere_courant++;
                   1674:                            break;
                   1675:                        }
                   1676: 
                   1677:                        if ((erreur_format == d_absence_erreur) &&
                   1678:                                (drapeau_fin_objet == d_faux))
                   1679:                        {
                   1680:                            (*s_etat_processus).position_courante =
                   1681:                                    pointeur_caractere_courant
                   1682:                                    - (*s_etat_processus).definitions_chainees;
                   1683: 
                   1684:                            if ((erreur = recherche_instruction_suivante(
                   1685:                                    s_etat_processus)) != d_absence_erreur)
                   1686:                            {
                   1687:                                if ((*s_etat_processus).instruction_courante
                   1688:                                        != NULL)
                   1689:                                {
                   1690:                                    free((*s_etat_processus)
                   1691:                                            .instruction_courante);
                   1692:                                }
                   1693: 
                   1694:                                return(d_erreur);
                   1695:                            }
                   1696: 
                   1697:                            pointeur_caractere_courant = (*s_etat_processus)
                   1698:                                    .definitions_chainees + (*s_etat_processus)
                   1699:                                    .position_courante;
                   1700: 
                   1701:                            free((*s_etat_processus).instruction_courante);
                   1702:                        }
                   1703:                    }
                   1704: 
                   1705:                    if (drapeau_fin_objet == d_faux)
                   1706:                    {
                   1707:                        erreur_analyse = d_ex_syntaxe;
                   1708:                        drapeau_fin_objet = d_vrai;
                   1709:                    }
                   1710:                }
                   1711: 
                   1712:                break;
                   1713:            }
                   1714:        }
                   1715:    }
                   1716: 
                   1717:    pointeur_fin_instruction = pointeur_caractere_courant;
                   1718: 
                   1719:    (*s_etat_processus).instruction_courante = (unsigned char *)
                   1720:                malloc(((pointeur_fin_instruction - pointeur_debut_instruction)
                   1721:                + 1) * sizeof(unsigned char));
                   1722: 
                   1723:    if ((*s_etat_processus).instruction_courante == NULL)
                   1724:    {
                   1725:        erreur = d_erreur;
                   1726:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   1727:    }
                   1728:    else if (pointeur_fin_instruction != pointeur_debut_instruction)
                   1729:    {
                   1730:        pointeur_caractere_courant = pointeur_debut_instruction;
                   1731:        pointeur_caractere_destination =
                   1732:                (*s_etat_processus).instruction_courante;
                   1733: 
                   1734:        do
                   1735:        {
                   1736:            *pointeur_caractere_destination++ = *pointeur_caractere_courant++;
                   1737:        } while(pointeur_caractere_courant < pointeur_fin_instruction);
                   1738: 
                   1739:        (*pointeur_caractere_destination) = d_code_fin_chaine;
                   1740: 
                   1741:        erreur = ((erreur_analyse == d_ex) && (erreur_format == d_ex))
                   1742:                ? d_absence_erreur : d_erreur;
                   1743:        (*s_etat_processus).erreur_execution = erreur_analyse;
                   1744:    }
                   1745:    else
                   1746:    {
                   1747:        (*(*s_etat_processus).instruction_courante) = d_code_fin_chaine;
                   1748:    }
                   1749: 
                   1750:    (*s_etat_processus).position_courante = pointeur_fin_instruction
                   1751:            - (*s_etat_processus).definitions_chainees;
                   1752: 
                   1753:    return(erreur);
                   1754: }
                   1755: 
                   1756: 
                   1757: /*
                   1758: ================================================================================
                   1759:   Routine mettant la chaine d'entrée en majuscule
                   1760: ================================================================================
                   1761:   Entrée : pointeur sur une chaine en minuscules.
                   1762: --------------------------------------------------------------------------------
                   1763:   Sortie : pointeur sur la chaine en majuscules. Si le pointeur retourné
                   1764:    est nul, il s'est produit une erreur. L'allocation est faite dans la
                   1765:    routine.
                   1766: --------------------------------------------------------------------------------
                   1767:   Effets de bord : néant.
                   1768: ================================================================================
                   1769: */
                   1770: 
                   1771: unsigned char *
                   1772: conversion_majuscule(unsigned char *chaine)
                   1773: {
                   1774:    register unsigned char      *caractere_courant;
                   1775:    register unsigned char      *caractere_courant_converti;
                   1776:    register unsigned char      *chaine_convertie;
                   1777: 
                   1778:    unsigned long               longueur_chaine_plus_terminaison;
                   1779: 
                   1780:    longueur_chaine_plus_terminaison = 0;
                   1781:    caractere_courant = chaine;
                   1782: 
                   1783:    while((*caractere_courant) != d_code_fin_chaine)
                   1784:    {
                   1785:        caractere_courant++;
                   1786:        longueur_chaine_plus_terminaison++;
                   1787:    }
                   1788: 
                   1789:    caractere_courant = chaine;
                   1790:    caractere_courant_converti = chaine_convertie = (unsigned char *) malloc(
                   1791:            (longueur_chaine_plus_terminaison + 1) * sizeof(unsigned char));
                   1792: 
                   1793:    if (chaine_convertie != NULL)
                   1794:    {
                   1795:        while((*caractere_courant) != d_code_fin_chaine)
                   1796:        {
                   1797:            if (isalpha((*caractere_courant)))
                   1798:            {
                   1799:                (*caractere_courant_converti) = (unsigned char)
                   1800:                        toupper((*caractere_courant));
                   1801:            }
                   1802:            else
                   1803:            {
                   1804:                (*caractere_courant_converti) = (*caractere_courant);
                   1805:            }
                   1806: 
                   1807:            caractere_courant++;
                   1808:            caractere_courant_converti++;
                   1809:        }
                   1810: 
                   1811:        (*caractere_courant_converti) = d_code_fin_chaine;
                   1812:    }
                   1813: 
                   1814:    return(chaine_convertie);
                   1815: }
                   1816: 
1.9       bertrand 1817: void
                   1818: conversion_majuscule_limitee(unsigned char *chaine_entree,
                   1819:        unsigned char *chaine_sortie, unsigned long longueur)
                   1820: {
                   1821:    unsigned long           i;
                   1822: 
                   1823:    for(i = 0; i < longueur; i++)
                   1824:    {
                   1825:        if (isalpha((*chaine_entree)))
                   1826:        {
                   1827:            (*chaine_sortie) = (unsigned char) toupper((*chaine_entree));
                   1828:        }
                   1829:        else
                   1830:        {
                   1831:            (*chaine_sortie) = (*chaine_entree);
                   1832:        }
                   1833: 
                   1834:        if ((*chaine_entree) == d_code_fin_chaine)
                   1835:        {
                   1836:            break;
                   1837:        }
                   1838: 
                   1839:        chaine_entree++;
                   1840:        chaine_sortie++;
                   1841:    }
                   1842: 
                   1843:    return;
                   1844: }
                   1845: 
1.1       bertrand 1846: 
                   1847: /*
                   1848: ================================================================================
                   1849:   Initialisation de l'état du calculateur
                   1850:    Configuration par défaut d'un calculateur HP-28S
                   1851: ================================================================================
                   1852:   Entrée : pointeur sur la structure struct_processus
                   1853: --------------------------------------------------------------------------------
                   1854:   Sortie : néant
                   1855: --------------------------------------------------------------------------------
                   1856:   Effets de bord : néant
                   1857: ================================================================================
                   1858: */
                   1859: 
                   1860: void
                   1861: initialisation_drapeaux(struct_processus *s_etat_processus)
                   1862: {
                   1863:    unsigned long                   i;
                   1864: 
                   1865:    for(i = 0; i < 31; cf(s_etat_processus, i++));
                   1866: 
                   1867:    if ((*s_etat_processus).lancement_interactif == d_vrai)
                   1868:    {
                   1869:        sf(s_etat_processus, 31);
                   1870:                                /* LAST autorisé                            */
                   1871:    }
                   1872:    else
                   1873:    {
                   1874:        cf(s_etat_processus, 31);
                   1875:                                /* LAST invalidé                            */
                   1876:    }
                   1877: 
                   1878:    cf(s_etat_processus, 32);   /* Impression automatique                   */
                   1879:    cf(s_etat_processus, 33);   /* CR automatique (disp)                    */
1.23      bertrand 1880:    sf(s_etat_processus, 34);   /* Évaluation des caractères de contrôle    */
                   1881:    sf(s_etat_processus, 35);   /* Évaluation symbolique des constantes     */
                   1882:    sf(s_etat_processus, 36);   /* Évaluation symbolique des fonctions      */
1.1       bertrand 1883:    sf(s_etat_processus, 37);   /* Taille de mot pour les entiers binaires  */
                   1884:    sf(s_etat_processus, 38);   /* Taille de mot pour les entiers binaires  */
                   1885:    sf(s_etat_processus, 39);   /* Taille de mot pour les entiers binaires  */
                   1886:    sf(s_etat_processus, 40);   /* Taille de mot pour les entiers binaires  */
                   1887:    sf(s_etat_processus, 41);   /* Taille de mot pour les entiers binaires  */
                   1888:    sf(s_etat_processus, 42);   /* Taille de mot pour les entiers binaires  */
                   1889: /*
                   1890: 37 : bit de poids faible
                   1891: 42 : bit de poids fort
                   1892: Les six drapeaux peuvent être nuls. Dans ce cas, la longueur des mots
                   1893: binaires reste de un bit.
                   1894: */
                   1895:    cf(s_etat_processus, 43);   /* Base de numération binaire               */
                   1896:    cf(s_etat_processus, 44);   /* Base de numération binaire               */
                   1897: /*
                   1898: 43 44 = 00 => décimal
                   1899: 43 44 = 01 => binaire
                   1900: 43 44 = 10 => octal
                   1901: 43 44 = 11 => hexadécimal
                   1902: */
                   1903:    sf(s_etat_processus, 45);   /* Affichage multiligne du niveau 1         */
                   1904:    cf(s_etat_processus, 46);   /* Réservé                                  */
                   1905:    cf(s_etat_processus, 47);   /* Réservé                                  */
                   1906: /*
                   1907: 46 et 47 réservés sur le calculateur HP28S
                   1908: 46 47 = 00 => système rectangulaire
                   1909: 46 47 = 01 => système cylindrique
                   1910: 46 47 = 10 => système sphérique
                   1911: */
                   1912:    cf(s_etat_processus, 48);   /* Séparateur décimal                       */
                   1913:    cf(s_etat_processus, 49);   /* Format des nombres réels                 */
                   1914:    cf(s_etat_processus, 50);   /* Format des nombres réels                 */
                   1915: /*
                   1916: 49 50 = 00 => standard
                   1917: 49 50 = 01 => scientifique
                   1918: 49 50 = 10 => virgule fixe
                   1919: 49 50 = 11 => ingénieur
                   1920: */
                   1921:    cf(s_etat_processus, 51);   /* Tonalité                                 */
                   1922:    cf(s_etat_processus, 52);   /* REDRAW automatique                       */
                   1923:    cf(s_etat_processus, 53);   /* Nombre de chiffres décimaux              */
                   1924:    cf(s_etat_processus, 54);   /* Nombre de chiffres décimaux              */
                   1925:    cf(s_etat_processus, 55);   /* Nombre de chiffres décimaux              */
                   1926:    cf(s_etat_processus, 56);   /* Nombre de chiffres décimaux              */
                   1927: /*
                   1928: 53 : bit de poids faible
                   1929: 56 : bit de poids fort
                   1930: */
                   1931:    cf(s_etat_processus, 57);   /* Underflow traité normalement             */
                   1932:    cf(s_etat_processus, 58);   /* Overflow traité normalement              */
                   1933:    sf(s_etat_processus, 59);   /* Infinite result traité normalement       */
                   1934:    sf(s_etat_processus, 60);   /* Angles                                   */
                   1935: /*
                   1936: 60 = 0 => degrés
                   1937: 60 = 1 => radians
                   1938: */
                   1939:    cf(s_etat_processus, 61);   /* Underflow- traité en exception           */
                   1940:    cf(s_etat_processus, 62);   /* Underflow+ traité en exception           */
                   1941:    cf(s_etat_processus, 63);   /* Overflow traité en exception             */
                   1942:    cf(s_etat_processus, 64);   /* Infinite result traité en exception      */
                   1943: }
                   1944: 
                   1945: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>