%% Package algorithme.tex (version 2.4) %% Envoyer toutes remarques a Nicolas.Delestre@insa-rouen.fr % Modifications depuis la version 2.3.8 % * Ajout de la commande \tadOperationAvecPreconditions % * Ajout des environnement tadPreconditions et des commandes % \motclefTADPreconditions et \tadPrecondition % * Ajout de la commande \champ % Modifications depuis la version 2.3.7 % * Ajout des types de base naturelNonNul, reelPositif, reelPositifNonNul (resp Negatif) % * Elimination d'accents dans les mots cles lies à l'algorithmique % * ajout de la commande \commentaire % Modification depuis la version 2.3.6 % * Ajout des commandes \fonctionAvecPreconditions % \signatureFonctionAvecPreconditions, \procedureAvecPreconditions % et \signatureProcedureAvecPreconditions % * remplacement de structure et champStructure par enregistrement et champEnregistrement % Modification depuis la version 2.3.5 % * Suppression de la commande \programme % Modification depuis la version 2.3.4 % * Dans les commandes fonction et procedure, modification du test pour savoir si les variables locales sont presentes ou pas. % * Suppresion de l'erreur de compilation du a la redefinition de l'environnement structure % Modification depuis la version 2.3.2 % * structure est maintenant un environnement qui s'integre dans l'environnement algorithme % * \champStructure a pris une majuscule % * Apparition de \tadSemantiquesAxiomatiques % * Apparition de l'environnement \tadAxiomes et et commande \tadAxiome % * Apparition de \typePointeur, \pointeur, \pointeurNULL, \champPointee, \allouer, \desallouer % * Elimination de l'erreur de compilation lie a la defintion de la commande \structure \NeedsTeXFormat{LaTeX2e}[1994/12/01] \ProvidesPackage{algorithme}[2002/12/22 package algorithme] \RequirePackage{calc} \RequirePackage{amssymb} %% Definition des mots clefs %% peuvent être redéfini à l'aide de la commande \renewcommand % \newcommand{\motclefAffectation}[0]{$\leftarrow$} % \newcommand{\motclefAlgoNom}[0]{Nom} \newcommand{\motclefAlgoRole}[0]{Role} \newcommand{\motclefAlgoEntree}[0]{Entrée} \newcommand{\motclefAlgoSortie}[0]{Sortie} \newcommand{\motclefAlgoEntreeSortie}[0]{Entrée/Sortie} \newcommand{\motclefAlgoDeclaration}[0]{Déclaration} % \newcommand{\motclefAlgoDebut}[0]{debut} \newcommand{\motclefAlgoFin}[0]{fin} % \newcommand{\motclefEntier}[0]{Entier} \newcommand{\motclefNaturel}[0]{Naturel} \newcommand{\motclefNaturelNonNul}[0]{NaturelNonNul} \newcommand{\motclefReel}[0]{Reel} \newcommand{\motclefReelPositif}[0]{ReelPositif} \newcommand{\motclefReelPositifNonNul}[0]{ReelPositifNonNul} \newcommand{\motclefReelNegatif}[0]{ReelNegatif} \newcommand{\motclefReelNegatifNonNul}[0]{ReelNegatifNonNul} \newcommand{\motclefBooleen}[0]{Booleen} \newcommand{\motclefCaractere}[0]{Caractere} \newcommand{\motclefChaine}[0]{Chaine de caracteres} % \newcommand{\motclefRemarque}[0]{Remarque} \newcommand{\motclefCommentaire}[0]{// } % \newcommand{\motclefType}[0]{Type} \newcommand{\motclefDeclaration}[0]{Déclaration} \newcommand{\motclefConstante}[0]{Constante} \newcommand{\motclefTableau}[0]{Tableau} \newcommand{\motclefStructure}[0]{Structure} \newcommand{\motclefFinstructure}[0]{finstructure} % \newcommand{\motclefSi}[0]{si} \newcommand{\motclefAlors}[0]{alors} \newcommand{\motclefSinon}[0]{sinon} \newcommand{\motclefFinsi}[0]{finsi} % \newcommand{\motclefCasou}[0]{cas où} \newcommand{\motclefCasouVaut}[0]{vaut} \newcommand{\motclefFincas}[0]{fincas} % \newcommand{\motclefTantque}[0]{tant que} \newcommand{\motclefTantqueFaire}[0]{faire} \newcommand{\motclefFintantque}[0]{fintantque} % \newcommand{\motclefRepeter}[0]{repeter} \newcommand{\motclefJusquaceque}[0]{jusqu'a ce que} % \newcommand{\motclefPour}[0]{pour} \newcommand{\motclefPourA}[0]{à} \newcommand{\motclefPourPas}[0]{pas de} \newcommand{\motclefPourFaire}[0]{faire} \newcommand{\motclefFinPour}[0]{finpour} % \newcommand{\motclefEcrire}[0]{ecrire} \newcommand{\motclefLire}[0]{lire} % \newcommand{\motclefPreconditions}[0]{précondition(s)} % \newcommand{\motclefFonction}[0]{fonction} \newcommand{\motclefRetourner}[0]{retourner} % \newcommand{\motclefProcedure}[0]{procédure} \newcommand{\motclefParamEntree}[0]{E} \newcommand{\motclefParamSortie}[0]{S} \newcommand{\motclefParamEntreeSortie}[0]{E/S} % \newcommand{\motclefTADNom}[0]{Nom} \newcommand{\motclefTADParametre}[0]{Paramètre} \newcommand{\motclefTADUtilise}[0]{Utilise} \newcommand{\motclefTADOperations}[0]{Opérations} \newcommand{\motclefTADSemantiques}[0]{Sémantiques} \newcommand{\motclefTADAxiomes}[0]{Axiomes} \newcommand{\motclefTADPreconditions}[0]{Préconditions} % \newcommand{\motclefPointeurNULL}[0]{null} \newcommand{\motclefAllouer}[0]{allouer} \newcommand{\motclefDesallouer}[0]{desallouer} %% ------------------------------------------------------------ %% Définitions privées %% Permet d'étendre le nombre de niveau maximale pour l'environnment list \csname @listdepth\endcsname=-10 %% L'environnement \algolist \newenvironment{algolist}[1] {\begin{list} {} {\setlength{\parsep}{0cm} \setlength{\leftmargin}{#1} \setlength{\itemsep}{0cm} \setlength{\topsep}{0cm} } } {\end{list}} %% Définition d'un bloc d'instructions \newcommand{\unbloc}[1]{ \begin{algolist}{0,5cm} #1 \end{algolist} } \newcommand{\entetealgo}[6]{ \instruction{\textbf{\motclefAlgoNom : }#1} \instruction{\textbf{\motclefAlgoRole : }#2} \instruction{\textbf{\motclefAlgoEntree : }#3} \instruction{\textbf{\motclefAlgoSortie : }#4} \instruction{\textbf{\motclefAlgoEntreeSortie : }#5} \instruction{\textbf{\motclefAlgoDeclaration : }#6} } \newcommand{\debutfin}[1]{ \instruction{\textbf{\motclefAlgoDebut}} \unbloc{#1} \instruction{\textbf{\motclefAlgoFin}} } %% Des listes alignees %% #1 : le mot de reference %% #2 : l'espace depuis le cote gauche %% #3 : le separateur \newenvironment{listeAlignee}[3]% {\begin{list}{} {\renewcommand{\makelabel}[1]{\textsf{##1#3}\hfil} \settowidth{\labelwidth}{\textsf{#1#3}}% \setlength{\leftmargin}{\labelwidth+\labelsep+#2} \setlength{\itemsep}{0cm} } }% {\end{list}} \newenvironment{listeAligneeSanssf}[3]% {\begin{list}{} {\renewcommand{\makelabel}[1]{##1#3\hfil} \settowidth{\labelwidth}{#1#3}% \setlength{\leftmargin}{\labelwidth+\labelsep+#2} \setlength{\itemsep}{0cm} } }% {\end{list}} %% ------------------------------------------------------------ %% Définitions des commandes et environnement publiques %% Commande \instruction %% #1 : L'instruction %% Remarque : Toute instruction doit utiliser cette commande \newcommand{\instruction}[1]{ \item #1 } %% Commande \remarque %% #1 : La remarque \newcommand{\remarque}[1]{ \instruction{\textit{\textbf{Remarque : }#1}} } %% Commande \commentaire %% #1 : Le commentaire \newcommand{\commentaire}[1]{ \instruction{\textit{// #1}} } %% Les types de bases \newcommand{\entier}{\textbf{\motclefEntier}} \newcommand{\naturel}{\textbf{\motclefNaturel}} \newcommand{\naturelNonNul}{\textbf{\motclefNaturelNonNul}} \newcommand{\reel}{\textbf{\motclefReel}} \newcommand{\reelPositif}{\textbf{\motclefReelPositif}} \newcommand{\reelPositifNonNul}{\textbf{\motclefReelPositifNonNul}} \newcommand{\reelNegatif}{\textbf{\motclefReelNegatif}} \newcommand{\reelNegatifNonNul}{\textbf{\motclefReelNegatifNonNul}} \newcommand{\booleen}{\textbf{\motclefBooleen}} \newcommand{\caractere}{\textbf{\motclefCaractere}} \newcommand{\chaine}{\textbf{\motclefChaine}} %% Commande \type %% #1 : Nom du type %% #2 : Défintion du type \newcommand{\type}[2]{ \instruction{\textbf{\motclefType \ }#1\textbf{ = }#2} } %% Commande \variables %% #1 : Variable(s) a declarée(s) \newcommand{\variables}[1]{ % \instruction{\textbf{\motclefDeclaration \ }#1} \begin{listeAligneeSanssf}{\textbf{\motclefDeclaration \ }}{0.5cm}{} \item[\textbf{\motclefDeclaration \ }] #1 \end{listeAligneeSanssf} } %% Commande \constante %% #1 : Nom de la constante %% #2 : Valeur de la constante \newcommand{\constante}[2]{ \instruction{\textbf{\motclefConstante \ }#1\textbf{ = }#2} } %% Commande \tableauUneDimension %% #1 : Intervalle %% #2 : {de} ou {d'} %% #3 : Type \newcommand{\tableauUneDimension}[3]{ \textbf{\motclefTableau[}#1\textbf{] #2}#3 } %% Commande \tableauDeuxDimensions %% #1 : Intervalle 1ere dimension %% #2 : Intervalle 2eme dimension %% #3 : {de} ou {d'} %% #4 : Type \newcommand{\tableauDeuxDimensions}[4]{ \textbf{\motclefTableau[}#1\textbf{]}\textbf{[}#2\textbf{] #3} #4 } %% Environnement enregistrement %% #1 : Nom du type cree %\newenvironment{structure}[1]{\type{#1}{\textbf{\motclefStructure}}\begin{algolist}{0.5cm}}{\end{algolist}\instruction{\textbf{\motclefFinstructure}}} \newenvironment{enregistrement}[1] {\type{#1}{\textbf{\motclefStructure}}\begin{algolist}{0.5cm}} {\end{algolist}\instruction{\textbf{\motclefFinstructure}}} \newcommand{\champEnregistrement}[2]{ \instruction{#1 : #2} } \newcommand{\champ}[2]{ #1.#2 } %% Commande \affecter %% #1 : Nom de la variable %% #2 : Valeur \newcommand{\affecter}[2]{ \instruction{#1 \textbf{\motclefAffectation} #2} } %% Commande \sialors %% #1 : Condition %% #2 : Instruction(s) du alors \newcommand{\sialors}[2]{ \instruction{\textbf{\motclefSi} #1 \textbf{\motclefAlors}} \unbloc{#2} \instruction{\textbf{\motclefFinsi}} } %% Commande \sialorssinon %% #1 : Condition %% #2 : Instruction(s) du alors %% #3 : Instruction(s) du sinon \newcommand{\sialorssinon}[3]{ \instruction{\textbf{\motclefSi} #1 \textbf{\motclefAlors}} \unbloc{#2} \instruction{\textbf{\motclefSinon}} \unbloc{#3} \instruction{\textbf{\motclefFinsi}} } %% Commande \cas %% #1 : Nom de la variable %% #2 : Les cas \newcommand{\cas}[2]{ \instruction{\textbf{\motclefCasou} #1 \textbf{\motclefCasouVaut}} \unbloc{#2} \instruction{\textbf{\motclefFincas}} } \newcommand{\casclausegenerale}[2]{ \instruction{\textit{#1}: } \unbloc{#2} } \newcommand{\casclauseautre}[1]{ \instruction{\textit{autre} : } \unbloc{#1} } %% Commande \tantque %% #1 : Condition %% #2 : Instruction(s) \newcommand{\tantque}[2]{ \instruction{\textbf{\motclefTantque} #1 \textbf{\motclefTantqueFaire}} \unbloc{#2} \instruction{\textbf{\motclefFintantque}} } %% Commande \repeter %% #1 : Condition %% #2 : Instruction(s) \newcommand{\repeter}[2]{ \instruction{\textbf{\motclefRepeter}} \unbloc{#1} \instruction{\textbf{\motclefJusquaceque} #2} } %% Commande \pour %% #1 : Variable %% #2 : Borne inférieure %% #3 : Borne supérieure %% #4 : Pas (si {} alors de 1 par défaut et n'apparait pas) %% #5 : Instruction(s) \newcommand{\pour}[5]{ \instruction{\textbf{\motclefPour} #1 \motclefAffectation #2 \textbf{\motclefPourA} #3 \ifx#4\ \else \textbf{\motclefPourPas} #4 \fi\textbf{\motclefPourFaire}} \unbloc{#5} \instruction{\textbf{\motclefFinPour}} } %% Commande \lire %% #1 : Variables à lire (liste non controlée) \newcommand{\lire}[1]{ \instruction{\textbf{\motclefLire}(#1)} } %% Commande \ecrire %% #1 : Ce qui doit être affiché \newcommand{\ecrire}[1]{ \instruction{\textbf{\motclefEcrire}(#1)} } %% Commande \retourner %% #1 : Ce qui doit être retourné \newcommand{\retourner}[1]{ \instruction{\textbf{\motclefRetourner} #1} } %% Commande algo %% #1 : Taille de la police %% #2 : Nom de l'algo %% #3 : Signification de l'algo (rôle) %% #4 : Paramètre en entrée %% #5 : Paramètre en sortie %% #6 : Paramètre en entrée/sortie %% #7 : Déclaration variable locale %% #8 : Corps de l'algo \newcommand{\algo}[8]{ #1 \entetealgo{#2}{#3}{#4}{#5}{#6}{#7} \debutfin{#8} } %% Commande \fonction %% #1 : Nom de la fonction %% #2 : Paramètres %% #3 : Type de retour %% #4 : Variables locales %% #5 : Instructions \newcommand{\fonction}[5]{ \instruction{\textbf{\motclefFonction} #1 \textbf{(}#2\textbf{)} \textbf{:} #3} \ifx\empty#4\empty \else % \unbloc{\variables{#4}} \variables{#4} \fi \debutfin{#5} } %% Commande \preconditions %% #1 : les préconditions séparées par // \newcommand{\preconditions}[1]{ \ifx\empty#1\empty \else \begin{listeAligneeSanssf}{$\lfloor$\textbf{\motclefPreconditions \ }}{0.5cm}{} \item[$\lfloor$\textbf{\motclefPreconditions \ }] #1 \end{listeAligneeSanssf} \fi } %% Commande \fonctionAvecPreconditions %% #1 : Nom de la fonction %% #2 : Paramètres %% #3 : Type de retour %% #4 : Précondition(s) %% #5 : Variable(s) locale(s) %% #6 : Instructions \newcommand{\fonctionAvecPreconditions}[6]{ \instruction{\textbf{\motclefFonction} #1 \textbf{(}#2\textbf{)} \textbf{:} #3} \preconditions{#4} \ifx\empty#5\empty \else \variables{#5} \fi \debutfin{#6} } %% Commande : signaturefonction %% #1 : Nom de la fonction %% #2 : paramètres %% #3 : type de retour \newcommand{\signaturefonction}[3]{ \instruction{\textbf{\motclefFonction} #1 \textbf{(}#2\textbf{)} \textbf{:} #3} } \newcommand{\signatureFonction}[3]{ \signaturefonction{#1}{#2}{#3} } %% Commande : signatureFonctionAvecPreconditions %% #1 : Nom de la fonction %% #2 : paramètres %% #3 : type de retour %% #4 : préconditions \newcommand{\signatureFonctionAvecPreconditions}[4]{ \instruction{\textbf{\motclefFonction} #1 \textbf{(}#2\textbf{)} \textbf{:} #3} \preconditions{#4} } \newcommand{\paramEntree}[1]{ \textbf{\motclefParamEntree} #1 } \newcommand{\paramSortie}[1]{ \textbf{\motclefParamSortie} #1 } \newcommand{\paramEntreeSortie}[1]{ \textbf{\motclefParamEntreeSortie} #1 } %% Commande \procedure %% #1 : Nom de la procedure %% #2 : Paramètres %% #3 : Variables locales %% #4 : Corps de la procédure \newcommand{\procedure}[4]{ \instruction{\textbf{\motclefProcedure} #1 \textbf{(}#2\textbf{)}} \ifx\empty#3\empty \else % \unbloc{\variables{#3}} \variables{#3} \fi \debutfin{#4} } %% Commande \procedureAvecPreconditions %% #1 : Nom de la procedure %% #2 : Paramètres %% #3 : Précondition(s) %% #3 : Variables locales %% #4 : Corps de la procédure \newcommand{\procedureAvecPreconditions}[5]{ \instruction{\textbf{\motclefProcedure} #1 \textbf{(}#2\textbf{)}} \preconditions{#3} \ifx\empty#4\empty \else \variables{#4} \fi \debutfin{#5} } %% Commande signatureprocedure %% #1 : Nom de la procedure %% #2 : Paramètres \newcommand{\signatureprocedure}[2]{ \instruction{\textbf{\motclefProcedure} #1 \textbf{(}#2\textbf{)}} } \newcommand{\signatureProcedure}[2]{ \signatureprocedure{#1}{#2} } %% Commande procedure %% #1 : Nom de la procedure %% #2 : Paramètres %% #3 : Préconditions \newcommand{\signatureProcedureAvecPreconditions}[3]{ \instruction{\textbf{\motclefProcedure} #1 \textbf{(}#2\textbf{)}} \preconditions{#3} } %% Toutes ces commandes doivent être utilisées au sein de l'environnement algorithme \newenvironment{algorithme}{\begin{algolist}{0cm}}{\end{algolist}} %% Types abstraits de donnees (TAD ou aussi appele TDA) %% Commande \tadNom %% #1 : le nom du TAD \newcommand{\tadNom}[1]{\item[\textbf{\motclefTADNom}] #1} %% Commande \tadParametres %% #1 : parametres du TAD (permettant de creer des TAD generiques) \newcommand{\tadParametres}[1]{\item[\textbf{\motclefTADParametre}] #1} %% Commande \tadDependances %% #1 : Dependance du TAD vis à vis d'autre types \newcommand{\tadDependances}[1]{\item[\textbf{\motclefTADUtilise}] #1} %% Commande \tadOperation %% #1 : Nom de l'operation %% #2 : Parametres en entree de l'operation (utiliser \tadXXParam) %% #3 : Parametres en sortie de l'operation(utiliser \tadXXParam) \newcommand{\tadOperation}[3]{\item[#1] #2 $\rightarrow$ #3} %% Commande \tadOperationAvecPreconditions %% #1 : Nom de l'operation %% #2 : Parametres en entree de l'operation (utiliser \tadXXParam) %% #3 : Parametres en sortie de l'operation(utiliser \tadXXParam) \newcommand{\tadOperationAvecPreconditions}[3]{\item[#1] #2 $\nrightarrow$ #3} %% Commandes \tadXXParams %% Produit cartesien des types des parametres %% Plusieurs commande car pour l'instant impossible de créer une commande avec nombre d'arguement variable \newcommand{\tadUnParam}[1]{#1} \newcommand{\tadDeuxParams}[2]{#1 $\times$ #2} \newcommand{\tadTroisParams}[3]{#1 $\times$ #2 $\times$ #3} \newcommand{\tadQuatreParams}[4]{#1 $\times$ #2 $\times$ #3 $\times$ #4} \newcommand{\tadCinqParams}[5]{#1 $\times$ #2 $\times$ #3 $\times$ #4 $\times$ #5} \newcommand{\tadSixParams}[6]{#1 $\times$ #2 $\times$ #3 $\times$ #4 $\times$ #5 $\times$ #6} \newcommand{\tadSeptParams}[7]{#1 $\times$ #2 $\times$ #3 $\times$ #4 $\times$ #5 $\times$ #6 $\times$ #7} \newcommand{\tadHuitParams}[8]{#1 $\times$ #2 $\times$ #3 $\times$ #4 $\times$ #5 $\times$ #6 $\times$ #7 $\times$ #8} \newcommand{\tadNeufParams}[9]{#1 $\times$ #2 $\times$ #3 $\times$ #4 $\times$ #5 $\times$ #6 $\times$ #7 $\times$ #8 $\times$ #9} %% toutes les operations (tadOperation) doivent etre definies dans un environnement tadOperations \newenvironment{tadOperations}[1] {\item[\textbf{\motclefTADOperations}] \begin{listeAlignee}{#1}{0cm}{:} } {\end{listeAlignee}} %% Commande \tadSemantique %% #1 : Nom de l'operation %% #2 : rôle de l'operation \newcommand{\tadSemantique}[2]{\item[#1] #2} %% toutes les semantiques d'operations (\tadSemantique) doivent etre definies dans un environnement tadSemantiques \newenvironment{tadSemantiques}[1] {\item[\textbf{\motclefTADSemantiques}] \begin{listeAlignee}{#1}{0cm}{:} } {\end{listeAlignee}} % Semantique axiomatique %% Commande \tadSemantique %% #1 : Nom de l'operation %% #2 : rôle de l'operation %\newcommand{\tadSemantique}[2]{\item[#1] #2} % toutes les semantiques d'operations (\tadSemantique) doivent etre definies dans un environnement tadSemantiques \newenvironment{tadSemantiquesAxiomatiques}[1] {\item[\textbf{\motclefTADSemantiques}] \begin{listeAlignee}{#1}{0cm}{ =} } {\end{listeAlignee}} \newenvironment{axiomelist}[1] {\begin{list} {-} {\setlength{\parsep}{0cm} \setlength{\leftmargin}{#1} \setlength{\itemsep}{0cm} \setlength{\topsep}{0cm} } } {\end{list}} \newenvironment{tadAxiomes}[0] {\item[\textbf{\motclefTADAxiomes}] \begin{axiomelist}{0cm} } {\end{axiomelist}} \newcommand{\tadAxiome}[1]{\item #1} % préconditions %% toutes les préconditions d'operations (\tadPrecondition) doivent etre definies dans un environnement tadPreconditions \newenvironment{tadPreconditions}[1] {\item[\textbf{\motclefTADPreconditions}] \begin{listeAlignee}{#1}{0cm}{:} } {\end{listeAlignee}} %% Commande \tadPrecondition %% #1 : Nom de l'operation %% #2 : la précondition \newcommand{\tadPrecondition}[2]{\item[#1] #2} %% La définition d'un tad ce fait dans un environnement tad \newenvironment{tad}{\begin{listeAlignee}{\textbf{\motclefTADPreconditions}}{0cm}{:}}{\end{listeAlignee}} %% Commandes \algoset \newcommand{\algoset}[2]{\renewcommand{#1}[0]{#2}} %% Pour les pointeurs :\typePointeur, \pointeur, \pointeurNULL, \champPointe, \allouer, \desallouer \newcommand{\typePointeur}[1]{\^\ #1} \newcommand{\pointeur}[1]{#1\^\ } \newcommand{\pointeurNULL}[0]{\textbf{\motclefPointeurNULL}} \newcommand{\champPointeur}[2]{#1$\rightarrow$#2} \newcommand{\allouer}[1]{\textbf{\motclefAllouer}(#1)} \newcommand{\desallouer}[1]{\textbf{\motclefDesallouer}(#1)} \endinput