Skip to content

Commit f358adb

Browse files
committed
ajout des solutions des TPs de STL
1 parent eae96db commit f358adb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+4789
-0
lines changed

stl-sols/stl-tp4-sol/BLOC.syn

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Syntaxe du langage BLOC
2+
=======================
3+
4+
PROG -> ident BLOC
5+
BLOC -> aco INSTS acf
6+
TYPE -> bool
7+
TYPE -> int
8+
TYPE -> inf TYPE v TYPE sup
9+
INSTS ->
10+
INSTS -> INST INSTS
11+
INST -> TYPE ident aff TERME pv
12+
INST -> ident aff TERME pv
13+
INST -> si po TERME pf BLOC sinon BLOC
14+
INST -> while po TERME pf BLOC
15+
INST -> print po TERME pf pv
16+
TERME -> FACTEUR
17+
FACTEUR -> ident
18+
FACTEUR -> vrai
19+
FACTEUR -> entier
20+
FACTEUR -> faux
21+
FACTEUR -> inf TEMRE v TEMRE sup
22+
FACTEUR -> fst FACTEUR
23+
FACTEUR -> snd FACTEUR
24+
FACTEUR -> po TERME pf

stl-sols/stl-tp4-sol/Makefile

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#--------------------------------------------------------
2+
# la grammaire (voir src)
3+
XLANG=BLOC
4+
#--------------------------------------------------------
5+
# repertoires contenant egg
6+
#EDIR=/usr/local/gen6/egg502
7+
EDIR=.
8+
# les jars associes
9+
GJAR=$(EDIR)/eggc.jar:.
10+
#--------------------------------------------------------
11+
# java, javac, jar
12+
#JDIR=/usr/local/jdk1.6/bin
13+
JDIR=/usr/bin
14+
#--------------------------------------------------------
15+
all : src att class
16+
17+
src :
18+
(cd bloc ; $(JDIR)/java -cp ../$(GJAR) mg.egg.eggc.internal.compiler.builder.EGGC $(XLANG).egg)
19+
20+
att :
21+
$(JDIR)/javac -classpath $(GJAR) bloc/lib/*.java
22+
$(JDIR)/javac -classpath $(GJAR) bloc/compiler/*.java
23+
24+
class :
25+
$(JDIR)/javac -classpath $(GJAR) bloc/egg/*.java
26+
27+
clean :
28+
rm -rf $(PACKAGE)
29+
rm -f bloc/lib/*.class
30+
rm -f bloc/compiler/*.class
31+
rm -rf bloc/egg
32+

stl-sols/stl-tp4-sol/bloc/BLOC-pq.egg

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
-----------------------------------------------
2+
-- BLOC
3+
-----------------------------------------------
4+
option auto= true;
5+
option version = 0.0.1 ;
6+
option k=1;
7+
8+
9+
inh source : BLOCSourceFile for PROG ;
10+
inh niveau : INTEGER for BLOC, INSTS, INST ;
11+
syn affectations : INTEGER for BLOC, INSTS, INST;
12+
inh lvar : ListeVar for BLOC, INST, INSTS, TERME, FACTEUR;
13+
14+
space separateur is "[\n\r\t ]+";
15+
space comments is "\/\/.*\n";
16+
sugar aco is "\{";
17+
sugar acf is "\}";
18+
sugar paro is "\(";
19+
sugar parf is "\)";
20+
sugar inf is "\<";
21+
sugar sup is "\>";
22+
sugar pv is ";";
23+
sugar v is ",";
24+
sugar aff is "=";
25+
sugar vrai is "true";
26+
sugar faux is "false";
27+
sugar si is "if";
28+
sugar sinon is "else";
29+
sugar print is "print";
30+
sugar tantque is "while";
31+
sugar fst is "fst";
32+
sugar snd is "snd";
33+
sugar int is "int";
34+
sugar bool is "bool";
35+
term entier is "[0-9]+";
36+
term ident is "[a-z_]+";
37+
38+
39+
PROG -> ident #info BLOC #afficher;
40+
#info {
41+
local
42+
do
43+
write "Compilation du fichier " + PROG^source.getFileName() + "\n" ;
44+
BLOC^niveau := 0;
45+
BLOC^lvar := nil;
46+
end
47+
}
48+
49+
#afficher {
50+
local
51+
do
52+
write "Affectations : " + BLOC^affectations + "\n" ;
53+
end
54+
}
55+
56+
BLOC -> aco #lv #descendre INSTS acf #afficher #aff;
57+
global
58+
lv : ListeVar;
59+
60+
#lv {
61+
do
62+
lv := new ListeVar();
63+
INSTS^lvar := lv;
64+
end
65+
}
66+
67+
#descendre {
68+
local
69+
do
70+
INSTS^niveau := BLOC^niveau +1 ;
71+
end
72+
}
73+
74+
#afficher {
75+
local
76+
do
77+
write "Niveau du bloc : " + BLOC^niveau + "\n";
78+
write "Liste des Variables : " + lv + "\n" ;
79+
end
80+
}
81+
82+
#aff {
83+
local
84+
do
85+
BLOC^affectations := INSTS^affectations;
86+
end
87+
}
88+
89+
TYPE -> bool ;
90+
91+
TYPE -> int ;
92+
93+
TYPE -> inf TYPE v TYPE sup ;
94+
95+
INSTS -> #aff ;
96+
#aff {
97+
local
98+
do
99+
INSTS^affectations := 0;
100+
end
101+
}
102+
103+
104+
INSTS -> INST INSTS #aff ;
105+
106+
#aff {
107+
local
108+
do
109+
INSTS^affectations := INST^affectations + INSTS1^affectations;
110+
end
111+
}
112+
113+
114+
INST -> TYPE ident aff TERME pv #aff ;
115+
#aff {
116+
local
117+
do
118+
INST^affectations := 1;
119+
if ~INST^lvar.contient(ident^txt) then
120+
call INST^lvar.inserer(ident^txt);
121+
else
122+
error(B_00, ident^txt);
123+
end
124+
end
125+
}
126+
127+
128+
INST -> ident aff TERME pv #aff ;
129+
#aff {
130+
local
131+
do
132+
INST^affectations := 1;
133+
if ~INST^lvar.contient(ident^txt) then
134+
error(B_01, ident^txt);
135+
end
136+
end
137+
}
138+
139+
140+
INST -> si paro TERME parf BLOC sinon BLOC #aff ;
141+
#aff {
142+
local
143+
do
144+
INST^affectations := BLOC^affectations + BLOC1^affectations;
145+
end
146+
}
147+
148+
INST -> tantque paro TERME parf BLOC #aff ;
149+
#aff {
150+
local
151+
do
152+
INST^affectations := BLOC^affectations;
153+
end
154+
}
155+
156+
157+
INST -> print paro TERME parf pv #aff ;
158+
#aff {
159+
local
160+
do
161+
INST^affectations := 0;
162+
end
163+
}
164+
165+
166+
TERME -> FACTEUR ;
167+
168+
FACTEUR -> ident #verif ;
169+
#verif {
170+
local
171+
do
172+
173+
if ~FACTEUR^lvar.contient(ident^txt) then
174+
error(B_01, ident^txt);
175+
end
176+
end
177+
}
178+
179+
FACTEUR -> entier ;
180+
181+
FACTEUR -> vrai ;
182+
183+
FACTEUR -> faux ;
184+
185+
FACTEUR -> paro TERME parf ;
186+
187+
FACTEUR -> inf TERME v TERME sup ;
188+
189+
FACTEUR -> fst FACTEUR ;
190+
191+
FACTEUR -> snd FACTEUR ;
192+
193+
end

stl-sols/stl-tp4-sol/bloc/BLOC.ecf

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Config file for EGG Grammar -->
3+
4+
<egg
5+
module="false"
6+
lang="java"
7+
scanner="jlex"
8+
gen="egg"
9+
prefix="bloc"
10+
typage="false"
11+
so="false"
12+
dst="false"
13+
main="true"
14+
>
15+
<import lib="bloc.compiler.*"/>
16+
<import lib="bloc.lib.*"/>
17+
</egg>

0 commit comments

Comments
 (0)