|
| 1 | +\documentclass[a4paper]{article} |
| 2 | + |
| 3 | +\usepackage{ucs} |
| 4 | +\usepackage[utf8x]{inputenc} |
| 5 | +\usepackage[T1]{fontenc} |
| 6 | + |
| 7 | +\usepackage[french]{babel} |
| 8 | + |
| 9 | +\usepackage{graphicx} |
| 10 | +\usepackage{subfigure} |
| 11 | + |
| 12 | +\usepackage{listings} |
| 13 | +\usepackage{color} |
| 14 | +%%\usepackage{listingsutf8} |
| 15 | +\usepackage{mathtools} |
| 16 | +%% \usepackage{pst-tree} |
| 17 | +%% \usepackage{pdftricks} |
| 18 | +%% \begin{psinputs} |
| 19 | +%% \usepackage{pstricks} |
| 20 | +%% \usepackage{multido} |
| 21 | +%% \end{psinputs} |
| 22 | +%%\usepackage{qtree} |
| 23 | + |
| 24 | +\lstset{ |
| 25 | + mathescape=true, |
| 26 | + breaklines=true, |
| 27 | + language=Caml |
| 28 | +} |
| 29 | + |
| 30 | + |
| 31 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 32 | + |
| 33 | +\author{ |
| 34 | + Damien \textsc{Crémilleux}, Tom \textsc{Demulier--Chevret} \\ \\ |
| 35 | + INSA de Rennes \\ |
| 36 | + 4INFO, LSR-B |
| 37 | +} |
| 38 | + |
| 39 | +\title{TP3 Compilation \\ Analyse syntaxique ascendante, ocamllex et ocamlyacc} |
| 40 | +\date{} |
| 41 | + |
| 42 | +\begin{document} |
| 43 | +\maketitle |
| 44 | + |
| 45 | +\section{Compte-rendu} |
| 46 | + |
| 47 | +\subsection{Table SLR} |
| 48 | +\begin{center} |
| 49 | + \begin{tabular}{| c || c | c | c | c | c | c | c || c | c |} |
| 50 | + \hline |
| 51 | + État & + & < & and & ( & ) & <- & Ident & Inst & Expr \\ \hline |
| 52 | + 0 & & & & & & & d1 & & \\ \hline |
| 53 | + 1 & & & & & & d2 & & & \\ \hline |
| 54 | + 2 & & & & d4& & & d5 & & 3 \\ \hline |
| 55 | + 3 & d6& d7& d8 & & & & & & \\ \hline |
| 56 | + 4 & & & & d4& & & d5 & & 9 \\ \hline |
| 57 | + 5 &r14&r14&r14 & &r14& & & & \\ \hline |
| 58 | + 6 & & & & d4& & & d5 & & 10 \\ \hline |
| 59 | + 7 & & & & d4& & & d5 & & 11 \\ \hline |
| 60 | + 8 & & & & d4& & & d5 & & 12 \\ \hline |
| 61 | + 9 & d6& d7& d8& &d13& & & & \\ \hline |
| 62 | + 10 &d6/r10 &d7/r10 &d8/r10 & &r10& & & & \\ \hline |
| 63 | + 11 &d6/r11 &d7/r11 &d8/r11 & &r11& & & & \\ \hline |
| 64 | + 12 &d6/r12 &d7/r12 &d8/r12 & &r12& & & & \\ \hline |
| 65 | + 13 &r13&r13&r13 & &r13& & & & \\ \hline |
| 66 | + \end{tabular} |
| 67 | +\end{center} |
| 68 | + |
| 69 | +\subsubsection{Résolutions pour les éventuels conflits} |
| 70 | +On trouve 9 conflits dans la table SLR générés par 3 tokens : 6 pour les conflits de prédominance entre deux tokens différents (ex : a and b inf c) et 3 pour les conflits de réductions entre même tokens (ex : a + b + c). |
| 71 | +L'ordre de préfominance gardé correspond à celui donné par la grammaire : AND > INF > PLUS. |
| 72 | +De plus nous avons choisis un décalage à droite pour les conflits entre même tokens. |
| 73 | + |
| 74 | +\subsection{Questions de compréhension du TP} |
| 75 | + |
| 76 | +\paragraph{Question 3.1} |
| 77 | +Un crible filtre la suite des lexèmes et génère les identifiants. En utilisant ocamllex, on peut générer une hashtable pour stocker les identifiants et limiter ainsi le nombre de transitions (en effet ocamllex est limité à 32767 transitions). |
| 78 | + |
| 79 | +\paragraph{Question 3.2} |
| 80 | +Écrire une grammaire sous forme LR plutôt qur LL comporte plusieurs avantage : |
| 81 | +\begin{itemize} |
| 82 | + \item La classe de grammaire couverte par LR est plus large. |
| 83 | + \item La détection d'erreur est faire au plus tôt. |
| 84 | + \item On peut traiter des grammaires ambiguës. |
| 85 | +\end{itemize} |
| 86 | + |
| 87 | +\paragraph{Question 3.3} |
| 88 | +Une colone vide dans une table SLR correspond à un token inutilisé. |
| 89 | + |
| 90 | +\section{Sources} |
| 91 | + |
| 92 | +Cf dossier source. |
| 93 | + |
| 94 | +\section{Tests} |
| 95 | + |
| 96 | +\subsection{Tests Positifs} |
| 97 | + |
| 98 | +\begin{lstlisting} |
| 99 | + |
| 100 | +begin int a,bool b, int c; b <- a < c end |
| 101 | + |
| 102 | +Anasynt.arbre_bloc = |
| 103 | +Anasynt.Node_bloc |
| 104 | + ([Anasynt.Node_decl_int "a"; Anasynt.Node_decl_bool "b"; |
| 105 | + Anasynt.Node_decl_int "c"], |
| 106 | + [Anasynt.Node_inst ("b", |
| 107 | + Anasynt.Node_inf (Anasynt.Leaf_ident "a", Anasynt.Leaf_ident "c"))]) |
| 108 | + |
| 109 | + |
| 110 | +begin |
| 111 | +int a, |
| 112 | +int c; |
| 113 | +a <- c; |
| 114 | +c <- a + c |
| 115 | +end |
| 116 | + |
| 117 | +Anasynt.arbre_bloc = |
| 118 | +Anasynt.Node_bloc ([Anasynt.Node_decl_int "a"; Anasynt.Node_decl_int "c"], |
| 119 | + [Anasynt.Node_inst ("a", Anasynt.Leaf_ident "c"); |
| 120 | + Anasynt.Node_inst ("c", |
| 121 | + Anasynt.Node_plus (Anasynt.Leaf_ident "a", Anasynt.Leaf_ident "c"))]) |
| 122 | + |
| 123 | +begin |
| 124 | +int a, |
| 125 | +int c; |
| 126 | +a <- c; |
| 127 | +c <- a + c; |
| 128 | +begin |
| 129 | +bool b; |
| 130 | +b <- b and b |
| 131 | +end |
| 132 | +end |
| 133 | + |
| 134 | +Anasynt.arbre_bloc = |
| 135 | +Anasynt.Node_bloc ([Anasynt.Node_decl_int "a"; Anasynt.Node_decl_int "c"], |
| 136 | + [Anasynt.Node_inst ("a", Anasynt.Leaf_ident "c"); |
| 137 | + Anasynt.Node_inst ("c", |
| 138 | + Anasynt.Node_plus (Anasynt.Leaf_ident "a", Anasynt.Leaf_ident "c")); |
| 139 | + Anasynt.Node_inst_bloc |
| 140 | + (Anasynt.Node_bloc ([Anasynt.Node_decl_bool "b"], |
| 141 | + [Anasynt.Node_inst ("b", |
| 142 | + Anasynt.Node_and (Anasynt.Leaf_ident "b", Anasynt.Leaf_ident "b"))]))]) |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +\end{lstlisting} |
| 147 | + |
| 148 | +\subsection{Tests Negatifs} |
| 149 | + |
| 150 | +\begin{lstlisting} |
| 151 | + |
| 152 | +begin int a ; |
| 153 | + a <- 654b + c |
| 154 | + end |
| 155 | + |
| 156 | +Fatal error: exception Failure("lexing: empty token") |
| 157 | + |
| 158 | + |
| 159 | +begin ; |
| 160 | + a <- b + c |
| 161 | + end |
| 162 | + |
| 163 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 1, caractere 6") |
| 164 | + |
| 165 | + |
| 166 | +begin |
| 167 | + int a, |
| 168 | + bool b; |
| 169 | + int c; |
| 170 | + |
| 171 | + a <- a + c; |
| 172 | + b and (a < c) |
| 173 | + end |
| 174 | + |
| 175 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 4, caractere 1") |
| 176 | + |
| 177 | + |
| 178 | +begin |
| 179 | + int a, |
| 180 | + bool b; |
| 181 | + |
| 182 | + a <- a <- b |
| 183 | + end |
| 184 | + |
| 185 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 5, caractere 8") |
| 186 | + |
| 187 | + |
| 188 | +begin |
| 189 | + bool b; |
| 190 | + b and and b and |
| 191 | + end |
| 192 | + |
| 193 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 3, caractere 3") |
| 194 | + |
| 195 | + |
| 196 | +begin |
| 197 | + int a, |
| 198 | + bool b; |
| 199 | + int c; |
| 200 | + |
| 201 | + a <- a + c, |
| 202 | + b and (a < c) |
| 203 | + end |
| 204 | + |
| 205 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 4, caractere 1") |
| 206 | + |
| 207 | + |
| 208 | +begin |
| 209 | + int a, |
| 210 | + b, |
| 211 | + int c; |
| 212 | + |
| 213 | + a <- a + c; |
| 214 | + b and (a < c) |
| 215 | + end |
| 216 | + |
| 217 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 3, caractere 1") |
| 218 | + |
| 219 | + |
| 220 | +begin |
| 221 | + int a; |
| 222 | + a <- a + c |
| 223 | + |
| 224 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 4, caractere 0") |
| 225 | + |
| 226 | + |
| 227 | +begin |
| 228 | + int a, |
| 229 | + int c; |
| 230 | + |
| 231 | + a <- c; |
| 232 | + begin |
| 233 | + int b, |
| 234 | + int c; |
| 235 | + b <- c |
| 236 | + |
| 237 | + end |
| 238 | + |
| 239 | +Fatal error: exception Failure("Erreur dans le fichier , a la ligne 12, caractere 0") |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | +\end{lstlisting} |
| 244 | + |
| 245 | +\end{document} |
0 commit comments