forked from hakimel/reveal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathll1.html
505 lines (478 loc) · 20.4 KB
/
ll1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>reveal.js – The HTML Presentation Framework</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<link rel="stylesheet" href="dist/theme/white.css" id="theme">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="plugin/highlight/monokai.css">
</head>
<style>
[src*="https://mermaid.ink/svg/"],
.invert {
filter: invert(100%);
}
.cols {
display: grid;
grid-auto-flow: row;
grid-template-columns: 1fr 1fr;
}
.cols-60-40 {
grid-template-columns: 60% 40%;
}
.cols-50-50 {
grid-template-columns: 50% 50%;
}
.cols>* {
align-self: center;
place-self: center;
}
.cols>img {
margin: 0
}
.cols3 {
display: grid;
grid-auto-flow: row;
grid-template-columns: 1fr 1fr 1fr;
}
.cols3>* {
align-self: center;
place-self: center;
}
.cols-left>* {
align-self: left;
place-self: 0px;
}
.cols3>img {
margin: 0
}
.slide pre {
box-shadow: none;
margin-top: 2px;
margin-bottom: 2px;
}
.reveal pre {
width: 100%;
margin-left: 0;
margin-right: 0;
}
.li-my li{
margin-bottom: 2rem;
margin-top: 2rem;
}
.reveal .big-code{
max-height: 800px;
}
</style>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Sintaxis y Parsers LL1</h1>
<div class="cols" style="font-size: 0.8em;">
<div>
<p>Temas:
<ol>
<li>Gramáticas </li>
<li>Gramáticas LL1</li>
<li>Ejercicio interactivo gramáticas LL1</li>
<li>Parser LL1</li>
<li>Ejercicio interactivo parsing LL1</li>
</ol>
</p>
</div>
<div>
<p>Bibliografía:
<ol>
<li>Louden 4.2, 3.2.</li>
<li>Ullman 4.2.1.</li>
<li>Apuntes de la teórica.</li>
</ol>
</p>
</div>
</div>
</section>
<section>
<h2>Qué es una Gramática</h2>
<p>$G=(V,T,P,S)$</p>
<ul style="font-size: 0.7em;">
<li>Conjunto de símbolos terminales $T$ (<code>if</code>, <code>int</code>, <code>{</code> ... )
</li>
<li>Conjunto de símbolos <b>no</b> terminales $V$ (<code>IfStmt</code>, <code>VarDecl</code>,
<code>BlockExpr</code>)</li>
<li>Conjunto de producciones $P$ (<code>BlockExpr -> { CompoundStmt }</code>)</li>
<li>Un símbolo inicial $S$</li>
</ul>
<p><small><a
href="https://clang.llvm.org/doxygen/group__CINDEX.html#gaaccc432245b4cd9f2d470913f9ef0013">Referencia
de tokens no terminales de C.</a></small></p>
</section>
<section>
<h2>Cómo escribimos una gramática</h2>
<ul style="font-size: 0.7em;">
<li><code><simbolo_no_terminal></code></li>
<li><code>simbolo_terminal</code></li>
<li>Producción: <code><un_no_terminal> ::= <simbolos> generados</code></li>
</ul>
<p>Derivación: aplicar producciones sucesivamente</p>
</section>
<section>
<h2>Gramática de Familang</h2>
<pre><code data-trim data-noescape>
<r> ::= <r> hijo_de <r>
<r> ::= <r> hermano_de <r>
<r> ::= nombre
</code></pre>
</section>
<section>
<h3>Ejemplo 1</h3>
<pre><code data-trim data-noescape>
Bart hijo_de Homero hermano_de Lisa
</code></pre>
<div class="cols cols-60-40" style="font-size: 0.5em;">
<table>
<thead>
<tr>
<th>Estado</th>
<th>Producción</th>
<th>¿Cuál?</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre><r></pre>
</td>
<td>
<pre><r> ::= <r> hijo_de <r></pre>
</td>
<td>1</td>
</tr>
<tr class="fragment">
<td>
<pre><r> hijo_de <r></pre>
</td>
<td>
<pre><r> ::= <r> hermano_de <r></pre>
</td>
<td>2</td>
</tr>
<tr class="fragment">
<td>
<pre><r> hijo_de <r> hermano_de <r></pre>
</td>
<td>
<pre><r> ::= nombre</pre>
</td>
<td>1</td>
</tr>
<tr class="fragment">
<td>
<pre>nombre hijo_de <r> hermano_de <r></pre>
</td>
<td>
<pre><r> ::= nombre</pre>
</td>
<td>1</td>
</tr>
<tr class="fragment">
<td>
<pre>nombre hijo_de nombre hermano_de <r></pre>
</td>
<td>
<pre><r> ::= nombre</pre>
</td>
<td>1</td>
</tr>
<tr class="fragment">
<td>
<pre>nombre hijo_de nombre hermano_de nombre</pre>
</td>
</tr>
</tbody>
</table>
<img class="fragment" src="./assets/sintactico1.drawio.png"/>
</div>
</section>
<section>
<h3>Ejemplo 2</h3>
<pre><code data-trim data-noescape>
Bart hijo_de Homero hermano_de Lisa
</code></pre>
<div class="cols cols-60-40" style="font-size: 0.5em;">
<table>
<thead>
<tr>
<th>Estado</th>
<th>Producción</th>
<th>¿Cuál?</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<pre><r></pre>
</td>
<td>
<pre><r> ::= <r> hermano_de <r></pre>
</td>
<td>1</td>
</tr>
<tr>
<td>
<pre><r> hermano_de <r></pre>
</td>
<td>
<pre><r> ::= <r> hijo_de <r></pre>
</td>
<td>1</td>
</tr>
<tr>
<td>
<pre><r> hijo_de <r> hermano_de <r></pre>
</td>
<td>
<pre><r> ::= nombre</pre>
</td>
<td>1</td>
</tr>
<tr>
<td>
<pre>nombre hijo_de <r> hermano_de <r></pre>
</td>
<td>
<pre><r> ::= nombre</pre>
</td>
<td>1</td>
</tr>
<tr>
<td>
<pre>nombre hijo_de nombre hermano_de <r></pre>
</td>
<td>
<pre><r> ::= nombre</pre>
</td>
<td>1</td>
</tr>
<tr>
<td>
<pre>nombre hijo_de nombre hermano_de nombre</pre>
</td>
</tr>
</tbody>
</table>
<img src="./assets/sintactico2.drawio.png"/>
</div>
</section>
<section style="font-size:0.7em">
<h2>Gramáticas LL1</h2>
<ul>
<li>No recursivas por izquierda</li>
<li>No ambíguas</li>
</ul>
<div class="cols3">
<div>
<p>familang original</p>
<pre>
<r> ::= <r> hijo_de <r>
<r> ::= <r> hermano_de <r>
<r> ::= nombre
</pre>
</div>
<div>
<p>No ambígua:</p>
<pre>
<r> ::= nombre hijo_de <r>
<r> ::= <r> hermano_de nombre
<r> ::= nombre
</pre>
</div>
<div>
<p>LL1 (no recursiva por izquierda):</p>
<pre>
<r> ::= nombre <r0>
<r0> ::=
<r0> ::= hijo_de <r>
<r0> ::= hermano_de <r>
</pre>
</div>
</div>
</section>
<section style="font-size:0.7em">
<h2>Ejercicio interactivo familang v2</h2>
<pre><code data-trim data-noescape data-line-numbers>
<r> ::= nombre <r0>
<r0> ::=
<r0> ::= hijo_de <r>
<r0> ::= hermano_de <r>
</code></pre>
<ol class="li-my">
<li>Ejemplo: <code>Maggie hermano_de : Lisa hijo_de : Homero y_de Marge y_de Bart hermano_de Maggie</code></li>
<li><code>Maggie hermano_de Lisa hermano_de Bart hijo_de: Homero hijo_de Abraham y_de Marge hermano_de Patty</code></li>
<li><code>Maggie hijo_de : Homero hijo de Abraham y_de Marge hermano_de : Patty y_de Selma</code></li>
<li><code>Luke hermano_de : Alex y_de Haley hijo_de : Phil hijo_de Frank y_de Claire hermano_de Mitchell hijo_de : Dede y_de Jay</code></li>
</ol>
</section>
<section>
<h2>¿Qué es un parser LL1?</h2>
<section>
<p>Parser descendiente recursivo con <b>stack explícito</b>.</p>
<table>
<thead>
<tr>
<th>Desc rec</th>
<th>LL1</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Funciones
</td>
<td>
Derivaciones
</td>
</tr>
<tr>
<td>cola de tokens</td>
<td>cola de tokens</td>
</tr>
<tr>
<td>callstack</td>
<td>Stack de estado</td>
</tr>
<tr>
<td><code>if</code> ó <code>switch</code></td>
<td>Tabla <b>M</b> $M \in V \times T \rightarrow P$</td>
</tr>
</tbody>
</table>
</section>
<section data-auto-animate>
<div class="cols cols-50-50">
<pre data-id="code-animation"><code data-trim data-noescape data-line-numbers data class="hljs language-python big-code" style="font-size:0.8em">
stack_estado=[símbolo_inicial]
cola=listado_de_tokens
while len(cola) > 0:
if cola[0]==stack_estado[0]:
cola.pop()
stack_estado.pop()
else:
produccion = M[
stack_estado[0],
cola[0]
]
stack_estado.push(
*produccion.lado_derecho
)
</code></pre>
<img src="./assets/algoritmo.drawio.png"/>
</div>
</section>
<section data-auto-animate>
<div class="cols cols-50-50" >
<pre data-id="code-animation"><code data-trim data-noescape data-line-numbers data class="hljs language-python big-code" style="font-size:0.8em">
stack_estado=[símbolo_inicial]
cola=listado_de_tokens
def match():
cola.pop()
stack_estado.pop()
def apply(produccion):
stack_estado.push(
*produccion.lado_derecho
)
while len(cola) > 0:
if cola[0]==stack_estado[0]:
cola.pop()
stack_estado.pop()
else:
produccion = M[
stack_estado[0],
cola[0]
]
stack_estado.push(
*produccion.lado_derecho
)
</code></pre>
<img src="./assets/algoritmo.drawio.png"/>
</div>
</section>
<section data-auto-animate>
<div class="cols cols-50-50" >
<pre data-id="code-animation"><code data-trim data-noescape data-line-numbers data class="hljs language-python big-code" style="font-size:0.8em">
stack_estado=[símbolo_inicial]
cola=listado_de_tokens
def match():
cola.pop()
stack_estado.pop()
def apply(produccion):
stack_estado.push(
*produccion.lado_derecho
)
while len(cola) > 0:
if cola[0]==stack_estado[0]:
match()
else:
apply(M[
stack_estado[0],
cola[0]
])
</code></pre>
<img src="./assets/algoritmo.drawio.png"/>
</div>
</section>
</section>
<section style="font-size:0.7em">
<h2>Ejercicio de <b>parsing</b> interactivo familang v2</h2>
<pre><code data-trim data-noescape data-line-numbers>
<r> ::= nombre <r0>
<r0> ::=
<r0> ::= hijo_de <r>
<r0> ::= hermano_de <r>
</code></pre>
<ol class="li-my">
<li>Ejemplo: <code>Maggie hermano_de : Lisa hijo_de : Homero y_de Marge y_de Bart hermano_de Maggie</code></li>
<li><code>Maggie hermano_de Lisa hermano_de Bart hijo_de: Homero hijo_de Abraham y_de Marge hermano_de Patty</code></li>
<li><code>Maggie hijo_de : Homero hijo de Abraham y_de Marge hermano_de : Patty y_de Selma</code></li>
<li><code>Luke hermano_de : Alex y_de Haley hijo_de : Phil hijo_de Frank y_de Claire hermano_de Mitchell hijo_de : Dede y_de Jay</code></li>
</ol>
</section>
<section style="font-size: 0.8em;">
<h1>¿Preguntas?</h1>
<p>A continuación, intervalo y laboratorio.</p>
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/zoom/zoom.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/search/search.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script src="plugin/math/math.js"></script>
<script>
// Also available as an ES module, see:
// https://revealjs.com/initialization/
Reveal.initialize({
controls: true,
progress: true,
center: true,
hash: true,
navigationMode: "linear",
katex: {
trust: true
},
// Learn about plugins: https://revealjs.com/plugins/
plugins: [RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight, RevealMath.KaTeX]
});
</script>
</body>
</html>