/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        T A B U L A T I O N   D E S   P A R E N T H E S E S   D ' U N E   L I S T E  :                                             */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xcp/listes.02$K' :                                                                                             */
/*                                                                                                                                   */
/*                    Jean-Francois COLONNA (LACTAMME, 20221201162101).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        I N T E R F A C E   ' listG '  :                                                                                           */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        :Debut_listG:                                                                                                              */
/*        :Fin_listG:                                                                                                                */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        D I R E C T I V E S   S P E C I F I Q U E S   D E   C O M P I L A T I O N  :                                               */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        F I C H I E R S   D ' I N C L U D E S  :                                                                                   */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#include  INCLUDES_MINI

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        P A R A M E T R E S  :                                                                                                     */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#define   TABULATION                                                                                                                    \
                    CINQ                                                                                                                \
                                        /* "Unite" de tabulation...                                                                  */

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        M A C R O S   U T I L E S  :                                                                                               */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
#define   PAS_DE_TABULATION                                                                                                             \
                    ZERO
#define   TABULATION_ELEMENTAIRE                                                                                                        \
                    NEUT(tabulation)
#define   TABULATION_COURANTE                                                                                                           \
                    MUL2(compteur_des_parentheses,tabulation)

#define   CHANGEMENT_DE_LIGNE(changer_de_ligne,amplitude_de_la_tabulation)                                                              \
                    Bblock                                                                                                              \
                    Test(IL_FAUT(changer_de_ligne))                                                                                     \
                         Bblock                                                                                                         \
                         CALS(Putchar(K_LF));                                                                                           \
                         Eblock                                                                                                         \
                    ATes                                                                                                                \
                         Bblock                                                                                                         \
                         Eblock                                                                                                         \
                    ETes                                                                                                                \
                                                                                                                                        \
                    Repe(amplitude_de_la_tabulation)                                                                                    \
                         Bblock                                                                                                         \
                         CALS(Putchar(K_BLANC));                                                                                        \
                         Eblock                                                                                                         \
                    ERep                                                                                                                \
                    Eblock

/*===================================================================================================================================*/
/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        T A B U L A T I O N   D E S   P A R E N T H E S E S   D ' U N E   L I S T E  :                                             */
/*                                                                                                                                   */
/*************************************************************************************************************************************/
BCommande(nombre_d_arguments,arguments)
/*-----------------------------------------------------------------------------------------------------------------------------------*/
     Bblock
     DEFV(Int,INIT(tabulation,TABULATION));
                                        /* "Unite" de tabulation...                                                                  */

     DEFV(Int,INIT(compteur_des_parentheses,ZERO));
                                        /* Ce compteur est incremente d'une unite a la rencontre d'une parenthese ouvrante, et       */
                                        /* decremente d'une unite a la rencontre d'une parenthese fermante.                          */
     DEFV(Char,INIT(caractere_precedent,K_UNDEF));
     DEFV(Char,INIT(caractere_courant,K_UNDEF));
                                        /* Caracteres precedent et courant.                                                          */
     /*..............................................................................................................................*/
     GET_ARGUMENTS_(nombre_d_arguments
                   ,GET_ARGUMENT_I("tabulation=",tabulation);
                    );

     Tant(GetcharT(caractere_courant))
          Bblock
                                        /* Le caractere courant de l'entree courante est recupere ; et on boucle                     */
                                        /* sur cette recuperation tant que l'on n'est pas au bout du fichier.                        */
          Test(IFET(IFNE(caractere_courant,K_PG),IFNE(caractere_courant,K_PD)))
               Bblock
               CALS(Putchar(caractere_courant));
                                        /* Tous les caracteres sont a priori transmis sauf les parentheses...                        */
               Eblock
          ATes
               Bblock
               Eblock
          ETes

          Test(IFEQ(caractere_courant,K_PG))
               Bblock
               INCR(compteur_des_parentheses,I);
                                        /* Comptage des parentheses...                                                               */

               CHANGEMENT_DE_LIGNE(IFNE(caractere_precedent,K_PG)
                                  ,COND(IFNE(caractere_precedent,K_PG),TABULATION_COURANTE,TABULATION_ELEMENTAIRE)
                                   );

               CALS(Putchar(caractere_courant));
                                        /* Transmission des parentheses ouvrantes...                                                 */

               CHANGEMENT_DE_LIGNE(TOUJOURS_VRAI,TABULATION_COURANTE);
               Eblock
          ATes
               Bblock
               Eblock
          ETes

          Test(IFEQ(caractere_courant,K_PD))
               Bblock
               Test(IZGT(compteur_des_parentheses))
                    Bblock
                    CHANGEMENT_DE_LIGNE(IFNE(caractere_precedent,K_PD)
                                       ,COND(IFNE(caractere_precedent,K_PD),TABULATION_COURANTE,PAS_DE_TABULATION)
                                        );

                    CALS(Putchar(caractere_courant));
                                        /* Transmission des parentheses fermantes...                                                 */

                    DECR(compteur_des_parentheses,I);
                                        /* Decomptage des parentheses...                                                             */

                    CHANGEMENT_DE_LIGNE(TOUJOURS_VRAI,TABULATION_COURANTE);
                    Eblock
               ATes
                    Bblock
                    PRINT_ERREUR("les parentheses sont mal equilibrees : il a trop de parentheses '$K_PD')");
                    Eblock
               ETes
               Eblock
          ATes
               Bblock
               Eblock
          ETes

          EGAL(caractere_precedent,caractere_courant);
          Eblock
     ETan

     Test(IZNE(compteur_des_parentheses))
          Bblock
          PRINT_ERREUR("les parentheses sont mal equilibrees : il a trop de parentheses '$K_PG'");
          Eblock
     ATes
          Bblock
          Eblock
     ETes

     RETU_Commande;
     Eblock
ECommande



Copyright © Jean-François COLONNA, 2022-2024.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / École polytechnique, Institut Polytechnique de Paris, 2022-2024.