Skip to content

Commit 144fefe

Browse files
author
Damien CREMILLEUX
committed
ajout du TP3 de compilation
1 parent 15cc1ac commit 144fefe

39 files changed

+4336
-0
lines changed

Compilation/TP3/Rapport/rapport.pdf

81.5 KB
Binary file not shown.

Compilation/TP3/Rapport/rapport.tex

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
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}

Compilation/TP3/Sources/.depend

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
lexer.cmo: parser.cmi
2+
lexer.cmx: parser.cmx
3+
anasynt.cmo:
4+
anasynt.cmx:
5+
parser.cmo: anasynt.cmo parser.cmi
6+
parser.cmx: anasynt.cmx parser.cmi
7+
main.cmo: parser.cmi lexer.cmo
8+
main.cmx: parser.cmx lexer.cmx
9+
parser.cmi: anasynt.cmo

Compilation/TP3/Sources/Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# TP3. Analyse lexicale et syntaxique
2+
# ascendante, ocamllex et ocamlyacc
3+
#
4+
# Makefile donne a titre d'exemple
5+
#
6+
#
7+
# Historique:
8+
# 17 Nov. 08 Par : Laurent Hubert
9+
# 03 Oct. 08 Par : Benoit Boyer
10+
#
11+
12+
13+
GEN_MLI= $(subst .mly,.mli, $(wildcard *.mly))
14+
GEN_ML= $(subst .mll,.ml, $(subst .mly,.ml, $(wildcard *.mll *.mly)))
15+
16+
ML= $(wildcard *.ml) $(GEN_ML)
17+
MLI= $(wildcard *.mli) $(GEN_MLI)
18+
19+
CMO= $(subst .ml,.cmo, $(ML))
20+
21+
# Nom de l'executable produit (vous pouvez le changer a votre guise)
22+
OUT=tp3
23+
24+
25+
CFLAGS=-dtypes
26+
CC=ocamlc $(CFLAGS)
27+
RM=rm -rf
28+
29+
.PHONY: clean all
30+
31+
# Pour compiler
32+
all: $(OUT)
33+
34+
$(OUT): $(CMO)
35+
$(CC) $^ -o $@
36+
@echo "===> $@ est compile avec succes!!!"
37+
38+
-include .depend
39+
40+
%.cmi: %.mli
41+
$(CC) -c $<
42+
43+
%.cmo : %.ml
44+
$(CC) -c $<
45+
46+
%.ml : %.mll
47+
ocamllex $<
48+
49+
%.ml %.mli : %.mly
50+
ocamlyacc -v $< # l'option -v genere %.output qui contient la table SLR
51+
52+
53+
clean:
54+
$(RM) $(OUT) *~ .depend $(GEN_MLI) $(GEN_ML) *.{annot,output,cmi,cmo}
55+
56+
.depend: $(ML) $(MLI)
57+
ocamldep $^ > .depend

Compilation/TP3/Sources/anasynt.annot

Whitespace-only changes.

Compilation/TP3/Sources/anasynt.cmi

621 Bytes
Binary file not shown.

Compilation/TP3/Sources/anasynt.cmo

129 Bytes
Binary file not shown.

Compilation/TP3/Sources/anasynt.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(* Arbre syntaxique abstrait *)
2+
3+
4+
type decl =
5+
| Node_decl_int of string
6+
| Node_decl_bool of string
7+
8+
type expr =
9+
| Node_plus of expr * expr
10+
| Node_inf of expr * expr
11+
| Node_and of expr * expr
12+
| Leaf_ident of string
13+
14+
type arbre_bloc =
15+
| Node_bloc of decl list * inst list
16+
and
17+
inst =
18+
| Node_inst of string * expr
19+
| Node_inst_bloc of arbre_bloc
20+

Compilation/TP3/Sources/anasynt.ml~

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(* Arbre syntaxique abstrait *)
2+

0 commit comments

Comments
 (0)