le sujet du partiel de mars 2013 - Verimag
le sujet du partiel de mars 2013 - Verimag
le sujet du partiel de mars 2013 - Verimag
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Licence Sciences et Technologie UJF<br />
Parcours Informatique UE INF246<br />
Durée : 1h30 - Tous documents autorisés<br />
Intro<strong>du</strong>ction<br />
Devoir Surveillé <strong>du</strong> 8 <strong>mars</strong> <strong>2013</strong><br />
On s’intéresse à un langage <strong>de</strong> <strong>de</strong>scription <strong>de</strong> document, où un document est une séquence <strong>de</strong> chapitre et<br />
chaque chapitre est une séquence <strong>de</strong> paragraphe. Ce langage sera appelé <strong>le</strong> langage Doc dans la suite. On donne<br />
ci-<strong>de</strong>ssous un exemp<strong>le</strong> <strong>de</strong> document D décrit dans ce langage :<br />
chap "intro<strong>du</strong>ction" (par "objectif"; par "approche";);<br />
chap "<strong>le</strong> prob<strong>le</strong>me" ();<br />
chap "solution" (par "<strong>de</strong>scription"; par "formalisation";);<br />
chap "conclusion" ();<br />
On constate sur cet exemp<strong>le</strong> que ce langage est formé à partir <strong>de</strong> <strong>de</strong>ux opérateurs :<br />
– l’opérateur chap, qui a pour opéran<strong>de</strong>s <strong>le</strong> titre <strong>du</strong> chapitre et une séquence <strong>de</strong> paragraphe (entre parenthèses) ;<br />
– l’opérateur par qui a pour opéran<strong>de</strong> <strong>le</strong> titre <strong>du</strong> paragraphe.<br />
L’objectif <strong>de</strong> ce travail est d’écrire un programme sur <strong>le</strong> même modè<strong>le</strong> que ce qui a été fait en TD. Ce programme<br />
prendra donc en entrée une expression lue au clavier décrivant un document et effectuera :<br />
– une analyse <strong>le</strong>xica<strong>le</strong> <strong>du</strong> langage : question 1 ;<br />
– une analyse syntaxique, avec construction d’un arbre abstrait : questions 2 et 3 ;<br />
– un traitement effectué sur l’arbre abstrait : question 4.<br />
Seu<strong>le</strong>s <strong>le</strong>s questions 2 et 3 sont liées entre-el<strong>le</strong>s, et peuvent être résolues simultanément si vous <strong>le</strong> souhaitez. Les<br />
autres questions sont indépendantes et peuvent être traités dans n’importe quel ordre.<br />
Question 1 : analyse <strong>le</strong>xica<strong>le</strong><br />
Les <strong>le</strong>xèmes <strong>du</strong> langage sont <strong>le</strong>s suivants :<br />
– CHAP, représente <strong>le</strong> mot-clé chap ;<br />
– PAR, représente <strong>le</strong> mot-clé par ;<br />
– PVIRG, représente <strong>le</strong> caractère ; (un point-virgu<strong>le</strong>) ;<br />
– PARO, représente <strong>le</strong> caractère ( ;<br />
– PARF, représente <strong>le</strong> caractère ) ;<br />
– TITRE, représente une chaîne <strong>de</strong> caractères entre guil<strong>le</strong>mets (par exemp<strong>le</strong> "intro<strong>du</strong>ction") ;<br />
– FIN_SEQ, représente la fin <strong>de</strong> la séquence lue au clavier.<br />
Dessinez un automate <strong>de</strong> reconnaissance <strong>de</strong> ces <strong>le</strong>xèmes. Cet automate lit en entrée une séquence <strong>de</strong> caractères<br />
et il atteint un état final lorsqu’un <strong>le</strong>xème a été reconnu. Les transitions seront étiquetées uniquement par <strong>le</strong><br />
caractère courant et par l’indication Av si et seu<strong>le</strong>ment si on doit lire <strong>le</strong> caractère suivant lors <strong>de</strong> l’exécution <strong>de</strong><br />
cette transition.<br />
Les caractères séparateurs sont “espace” et “fin ligne”, et on ne fera pas apparaitre <strong>le</strong> traitement <strong>de</strong>s erreurs<br />
<strong>le</strong>xica<strong>le</strong>s.<br />
1
Question 2 : analyse syntaxique<br />
La grammaire (sous forme LL(1)) <strong>du</strong> langage Doc est la suivante :<br />
Doc → SeqChap FIN_SEQ<br />
SeqChap → CHAP TITRE PARO SeqP ar PARF PVIRG SeqChap<br />
SeqChap → ε<br />
SeqP ar → PAR TITRE PVIRG SeqP ar<br />
SeqP ar → ε<br />
En utilisant <strong>le</strong>s primitives <strong>de</strong> machine_<strong>le</strong>xemes.ads, fournies en Annexe A, écrivez <strong>le</strong> corps <strong>de</strong> la procé<strong>du</strong>re<br />
analyser spécifiée ci-<strong>de</strong>ssous. Vous pouvez écrire <strong>de</strong>s procé<strong>du</strong>res auxilliaires (comme Req_Doc, Req_SeqChap et<br />
Req_SeqPar).<br />
proce<strong>du</strong>re analyser ;<br />
-- e.i. : indifferent<br />
-- e.f. : une sequence <strong>de</strong> <strong>le</strong>xemes a ete lue, l’exception Erreur_Syntaxique<br />
-- est <strong>le</strong>vee si el<strong>le</strong> ne respecte pas la grammaire Doc<br />
Question 3 : construction d’un arbre abstrait<br />
(la réponse à cette question peut être groupée avec cel<strong>le</strong> <strong>de</strong> la question 2)<br />
On donne à titre d’exemp<strong>le</strong> sur la Figure 1 l’arbre abstrait correspondant à l’expression D donnée en intro<strong>du</strong>ction<br />
:<br />
CHAP<br />
TITRE PVIRG<br />
"intro<strong>du</strong>ction"<br />
TITRE<br />
PAR<br />
PVIRG<br />
PVIRG<br />
PAR<br />
TITRE<br />
"approche"<br />
CHAP<br />
TITRE<br />
"objectifs" "<strong>le</strong> prob<strong>le</strong>me"<br />
PVIRG<br />
CHAP<br />
PVIRG<br />
TITRE PVIRG<br />
"solution"<br />
TITRE<br />
PAR<br />
"<strong>de</strong>scription"<br />
PAR<br />
TITRE<br />
"formalisation"<br />
Figure 1 – Arbre abstrait <strong>de</strong> l’expression D<br />
PVIRG<br />
PVIRG<br />
CHAP<br />
TITRE<br />
"conclusion"<br />
Complétez <strong>le</strong> co<strong>de</strong> ADA <strong>de</strong> la question 2 pour que la procé<strong>du</strong>re analyser fournisse en paramètre résultat l’arbre<br />
abstrait correspondant à l’expression lue (lorsque cette expresion ne contient pas d’erreurs) comme spécifié ciaprès<br />
:<br />
2
proce<strong>du</strong>re analyser (A : out Ast) ;<br />
-- e.i. : indifferent<br />
-- e.f. : une sequence <strong>de</strong> <strong>le</strong>xemes a ete lue, l’exception Erreur_Syntaxique<br />
-- est <strong>le</strong>vee si el<strong>le</strong> ne respecte pas la grammaire Doc, sinon A<br />
-- contient l’arbre abstrait <strong>de</strong> l’expression correspondante<br />
On pourra utiliser 1 <strong>le</strong>s types et primitives <strong>de</strong>s paquetages arbre_abstrait.ads et arbre_abstrait-construction.ads<br />
fournis en Annexes B et C.<br />
Question 4 : création d’une tab<strong>le</strong> <strong>de</strong>s matières<br />
En effectuant un parcours <strong>de</strong> l’arbre abstrait d’une expression <strong>du</strong> langage Doc, écrivez <strong>le</strong> corps <strong>de</strong> la procé<strong>du</strong>re<br />
tab<strong>le</strong>_matieres spécifiée ci-<strong>de</strong>ssous. On pourra écrire une procé<strong>du</strong>re récursive, et on pourra utiliser <strong>le</strong>s procé<strong>du</strong>res<br />
Put pour écrire <strong>de</strong>s entiers et <strong>de</strong>s caractères, et Put_Line pour écrire <strong>de</strong>s chaînes <strong>de</strong> caractères terminées<br />
par un fin-<strong>de</strong>-ligne. On supposera que <strong>le</strong> type Ast n’est pas “privé” dans cette fonction.<br />
proce<strong>du</strong>re tab<strong>le</strong>_matieres (A : in Ast) ;<br />
-- e.i. : indifferent<br />
-- e.f. : la tab<strong>le</strong> <strong>de</strong>s matieres correspondant a l’arbre abstrait A est affichee.<br />
On donne à titre d’exemp<strong>le</strong> la tab<strong>le</strong> <strong>de</strong>s matières <strong>de</strong> l’expression D correspondant à l’arbre abstrait <strong>de</strong> la Figure 1.<br />
1. "intro<strong>du</strong>ction"<br />
1.1 "objectif"<br />
1.2 "approche"<br />
2. "prob<strong>le</strong>me"<br />
3. "solution"<br />
3.1 <strong>de</strong>scription"<br />
3.2 "formalisation"<br />
4. "conclusion"<br />
Annexe A : <strong>le</strong> paquetage machine_<strong>le</strong>xemes.ads<br />
package machine_<strong>le</strong>xemes is<br />
Erreur_Lexica<strong>le</strong> : exception ;<br />
type Nature_Lexeme is (<br />
CHAP, -- <strong>le</strong> mot-c<strong>le</strong> chap<br />
PAR, -- <strong>le</strong> mot-c<strong>le</strong> par<br />
PVIRG, -- ;<br />
PARO, -- (<br />
PARF, -- )<br />
TITRE, -- chaine <strong>de</strong> caracteres entre guil<strong>le</strong>mets<br />
FIN_SEQ -- <strong>le</strong>xeme <strong>de</strong> fin <strong>de</strong> sequence<br />
);<br />
type Pointeur_Chaine is access String;<br />
1. sans <strong>le</strong>s écrire<br />
3
type Lexeme is record<br />
nature : Nature_Lexeme; -- nature <strong>du</strong> <strong>le</strong>xeme<br />
chaine : Pointeur_Chaine; -- chaine <strong>de</strong> caracteres<br />
end record;<br />
proce<strong>du</strong>re <strong>de</strong>marrer;<br />
-- e.i. : indifferent<br />
-- e.f. : la sequence <strong>de</strong> <strong>le</strong>xemes est lue au clavier<br />
-- fin_<strong>de</strong>_sequence <strong>le</strong>xeme_courant.nature = FIN_SEQ<br />
-- (non fin_<strong>de</strong>_sequence) => <strong>le</strong>xeme courant est <strong>le</strong> premier<br />
-- <strong>le</strong>xeme <strong>de</strong> la sequence<br />
proce<strong>du</strong>re <strong>de</strong>marrer(nom_fichier : String);<br />
-- e.i. : indifferent<br />
-- e.f. : la sequence <strong>de</strong> <strong>le</strong>xemes est lue dans <strong>le</strong> fichier <strong>de</strong>signe par<br />
-- nom_fichier<br />
-- fin_<strong>de</strong>_sequence <strong>le</strong>xeme_courant.nature = FIN_SEQ<br />
-- (non fin_<strong>de</strong>_sequence) => <strong>le</strong>xeme courant est <strong>le</strong> premier<br />
-- <strong>le</strong>xeme <strong>de</strong> la sequence<br />
-- l’exception Erreur_Lexica<strong>le</strong> est <strong>le</strong>vee en cas d’erreur<br />
proce<strong>du</strong>re avancer;<br />
-- pre-condition : la machine sequentiel<strong>le</strong> est <strong>de</strong>marree<br />
-- e.i. : on pose i = rang <strong>du</strong> <strong>le</strong>xeme_courant :<br />
-- (non fin_<strong>de</strong>_sequence)<br />
-- et (non <strong>le</strong>xeme_courant.nature = FIN_SEQ)<br />
-- e.f. : fin_<strong>de</strong>_sequence <strong>le</strong>xeme_courant.nature = FIN_SEQ<br />
-- (non fin_<strong>de</strong>_sequence) => <strong>le</strong>xeme_courant est <strong>le</strong> <strong>le</strong>xeme i+1<br />
-- l’exception Erreur_Lexica<strong>le</strong> est <strong>le</strong>vee en cas d’erreur<br />
function <strong>le</strong>xeme_courant return Lexeme;<br />
-- pre-condition : la machine sequentiel<strong>le</strong> est <strong>de</strong>marree<br />
-- <strong>le</strong>xeme_courant est :<br />
-- . <strong>le</strong> pseudo <strong>le</strong>xeme FIN_SEQ si fin_<strong>de</strong>_sequence<br />
-- . <strong>le</strong> <strong>le</strong>xeme <strong>de</strong> rang i sinon<br />
function fin_<strong>de</strong>_sequence return Boo<strong>le</strong>an;<br />
-- pre-condition : la machine sequentiel<strong>le</strong> est <strong>de</strong>marree<br />
-- fin_<strong>de</strong>_sequence vaut :<br />
-- . vrai si tous <strong>le</strong>s <strong>le</strong>xemes <strong>de</strong> la sequence ont ete reconnus<br />
-- . faux sinon<br />
proce<strong>du</strong>re arreter;<br />
-- e.i. : la machine sequentiel<strong>le</strong> est <strong>de</strong>marree<br />
-- e.f. : la machine sequentiel<strong>le</strong> est arretee<br />
end machine_<strong>le</strong>xemes;<br />
4
Annexe B : <strong>le</strong> paquetage arbre_abstrait.ads<br />
package Arbre_Abstrait is<br />
type Ast is private;<br />
type TypeAst is (PVIRG, CHAP, PAR, TITRE);<br />
private<br />
type NoeudAst;<br />
type Ast is access NoeudAst;<br />
type NoeudAst is record<br />
nature : TypeAst;<br />
gauche, droite : Ast;<br />
chaine : Pointeur_Chaine; -- lorsque la nature est TITRE<br />
end record;<br />
end Arbre_Abstrait;<br />
Annexe C : <strong>le</strong> paquetage arbre_abstrait-construction.ads<br />
package Arbre_Abstrait.Construction is<br />
--------------------------------------------------------------------proce<strong>du</strong>re<br />
creer_PVIRG (fils_gauche, fils_droit : Ast; A : out Ast);<br />
-- cree un noeud PVIRG<br />
---------------------------------------------------------------------<br />
--------------------------------------------------------------------proce<strong>du</strong>re<br />
creer_CHAP (fils_gauche, fils_droit : Ast; A : out Ast);<br />
-- cree un noeud CHAP<br />
---------------------------------------------------------------------<br />
--------------------------------------------------------------------proce<strong>du</strong>re<br />
creer_PAR (fils_gauche : Ast; A : out Ast);<br />
-- cree un noeud PAR<br />
---------------------------------------------------------------------<br />
--------------------------------------------------------------------proce<strong>du</strong>re<br />
creer_TITRE (chaine_titre : Pointeur_Chaine ; A : out Ast);<br />
-- cree une feuil<strong>le</strong> <strong>de</strong> nature TITRE et <strong>de</strong> chaine chaine_titre<br />
---------------------------------------------------------------------<br />
end Arbre_Abstrait.Construction;<br />
5