-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffdd4cf
commit c62ef06
Showing
9 changed files
with
321 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# IF688 - Teoria e Implementação de Linguagens Computacionais | ||
|
||
## _Recursive-Descent Parsing_ (Análise Sintática) e _Abstract Syntax Trees_ (Análise Semântica) | ||
|
||
### Objetivo | ||
|
||
O objetivo desta aula é apresentar os conceitos fundamentais relacionados à técnica _recursive-descent parsing_, que permite implementar análise sintática manualmente. Adicionalmente, também implementamos árvores sintáticas abstratas em código, que serão utilizadas para a análise semântica. | ||
|
||
### Questões para Discussão | ||
|
||
- Quais as vantagens e limitações de _recursive descent parsing_ como técnica de construção de _parsers_? | ||
- Qual a diferença entre árvores sintáticas concretas e abstratas? | ||
|
||
### Material usado em aula | ||
|
||
- Código desenvolvido em sala de aula | ||
- [versão para o início da aula (.zip com código incompleto)](https://drive.google.com/file/d/1x8KCmJhsKPX6aF5L5RwEcx_XpFL8LMvR/view?usp=sharing) | ||
- [versão do código ao final da aula (.zip com código escrito durante a aula)](https://drive.google.com/file/d/1O0T0RHE_cARV9xzzdSGTOJj7jK-GCcfN/view?usp=sharing) | ||
|
||
### Vídeos | ||
|
||
- [Análise Sintática - Recursive-descent parsing](https://www.youtube.com/watch?v=-7B39_U6ZL4) | ||
- [Análise Semântica - Introdução a ASTs](https://www.youtube.com/watch?v=Wz4TSKOrBrM) | ||
|
||
### Links Relacionados | ||
|
||
- [Recursive descent parser](https://en.wikipedia.org/wiki/Recursive_descent_parser) | ||
- [Abstract Syntax Tree](https://en.wikipedia.org/wiki/Abstract_syntax_tree) | ||
- [Abstract Syntax Tree Implementation Idioms, by Joel Jones](http://www.hillside.net/plop/plop2003/Papers/Jones-ImplementingASTs.pdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class Expr(object): | ||
pass | ||
|
||
class NumExpr(Expr): | ||
def __init__(self, valor): | ||
self.valor = valor | ||
def __str__(self) -> str: | ||
return "NumExpr("+str(self.valor)+")" | ||
|
||
class IdExpr(Expr): | ||
def __init__(self, nome): | ||
self.nome = nome | ||
def __str__(self) -> str: | ||
return "IdExpr("+self.nome+")" | ||
|
||
class SumExpr(Expr): | ||
def __init__(self, l_esq, l_dir): | ||
self.esq = l_esq | ||
self.dir = l_dir | ||
def __str__(self) -> str: | ||
return "SumExpr("+str(self.esq)+", "+str(self.dir)+")" | ||
|
||
class MulExpr(Expr): | ||
def __init__(self, l_esq, l_dir): | ||
self.esq = l_esq | ||
self.dir = l_dir | ||
def __str__(self) -> str: | ||
return "MulExpr("+str(self.esq)+", "+str(self.dir)+")" | ||
class DivExpr(Expr): | ||
def __init__(self, l_esq, l_dir): | ||
self.esq = l_esq | ||
self.dir = l_dir | ||
def __str__(self) -> str: | ||
return "DivExpr("+str(self.esq)+", "+str(self.dir)+")" | ||
class SubExpr(Expr): | ||
def __init__(self, l_esq, l_dir): | ||
self.esq = l_esq | ||
self.dir = l_dir | ||
def __str__(self) -> str: | ||
return "SubExpr("+str(self.esq)+", "+str(self.dir)+")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
1 - 2 + 3232 | ||
2+2; | ||
1/2/3; | ||
2+3+(4/0); | ||
((((2 * 3232)))); | ||
1+2*(3+y); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.