Introducci贸n al desarrollo de int茅rpretes y lenguajes de programaci贸n

1

Aprende a desarrollar lenguajes de programaci贸n con int茅rpretes

2

Desarrolla LPP o Lenguaje de Programaci贸n Platzi

Construcci贸n del lexer o tokenizador

3

驴Qu茅 es an谩lisis l茅xico? Funcionamiento del lexer y tokens

4

Estructura y definici贸n de tokens en Python

5

Lectura de caracteres y tokens

6

Tokens ilegales, operadores de un solo car谩cter y delimitadores

7

Reconocimiento y diferenciaci贸n entre letras y n煤meros

8

Declaraci贸n y ejecuci贸n de funciones

9

Extensi贸n del lexer: condicionales, operaciones y booleanos

10

Operadores de dos caracteres

11

Primera versi贸n del REPL con tokens

Construcci贸n del parser o analizador sint谩ctico

12

驴Qu茅 es un parser y AST?

13

Estructura y definici贸n de nodos del AST en Python

14

Parseo del programa o nodo principal

15

Parseo de assignment statements

16

Parseo de let statements

17

Parseo de errores

18

Parseo del return statement

19

T茅cnicas de parsing y pratt parsing

20

Pruebas del AST

21

Implementaci贸n del pratt parser

22

Parseo de Identifiers: testing

23

Parseo de Identifiers: implementaci贸n

24

Parseo de enteros

25

Prefix operators: negaci贸n y negativos

26

Infix operators y orden de las operaciones: testing

27

Infix operators y orden de las operaciones: implementaci贸n

28

Parseo de booleanos

29

Desaf铆o: testing de infix operators y booleanos

30

Parseo de expresiones agrupadas

31

Parseo de condicionales: testing y AST

32

Parseo de condicionales: implementaci贸n

33

Parseo de declaraci贸n de funciones: testing

34

Parseo de declaraci贸n de funciones: AST e implementaci贸n

35

Parseo de llamadas a funciones: testing y AST

36

Parseo de llamadas a funciones: implementaci贸n

37

Completando los TODOs o pendientes del lexer

38

Segunda versi贸n del REPL con AST

Evaluaci贸n o an谩lisis sem谩ntico

39

Significado de s铆mbolos

40

Estrategias de evaluaci贸n para int茅rpretes de software

41

Representaci贸n de objetos

42

Evaluaci贸n de expresiones: enteros

43

Evaluaci贸n de expresiones: booleanos y nulos

44

Evaluaci贸n de expresiones: prefix

45

Evaluaci贸n de expresiones: infix

46

Evaluaci贸n de condicionales

47

Evaluaci贸n del return statement

48

Manejo de errores

49

Ambiente

50

Bindings

51

Evaluaci贸n de funciones

52

Llamadas a funciones

Mejora del int茅rprete

53

Implementaci贸n de strings

54

Operaciones con strings

55

Built-in functions: objeto y tests

56

Built-in functions: evaluaci贸n

Siguientes pasos

57

Retos para expandir tu int茅rprete

58

Contin煤a con el Curso de Creaci贸n de Compiladores de Software

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

1 D铆as
1 Hrs
5 Min
3 Seg

Parseo de Identifiers: implementaci贸n

23/58
Resources

How to parse expression statements in a parser?

Parsing expression statements is a crucial step when developing a parser, especially when trying to implement an efficient programming language. To begin with, it is fundamental to understand how a parser must interpret and transform source code into intermediate representations that can be executed or parsed later. Let's break down how to accomplish this task by making certain modifications to the parser, ensuring that expression statements are correctly identified and parsed.

What is an expression statement?

In the context of the Platzi programming language, an expression statement represents a string of code that performs an operation without assigning a value to a given variable. These can include mathematical operations, function calls, among others. Expression statements are classified, like other elements, in the Abstract Syntax Tree (AST), allowing the program to understand their internal structure.

How to modify the parser to include expression statements?

  1. Definition of parseExpressionStatement: Inside the parser, a function called parseExpressionStatement must be added. It takes no parameters and returns an expressionStatement. First, we check that the currentToken is not None. This is done to ensure that we are working with valid data when generating our expressionStatement.

  2. Generate expressionStatement: This element is initialized by passing the self.currentToken as a reference. This allows the expressionStatement to be aware of the current token, ensuring correct interpretation within the syntax tree.

  3. Precedence implementation: Language statements follow a set of precedence rules that determine the order of operations to be performed. These precedences are defined by means of an Enum, where each type of operation has an associated value that indicates its hierarchical level in the evaluation order.

How are precedences handled?

Precedence dictates the order in which operations within an expression statement should be resolved. For example, in mathematical operations, multiplication and division often take precedence over addition and subtraction. By defining precedence correctly, a parser can properly interpret the desired order of execution in the source code.

How to integrate functions to identify?

  1. Parse and register functions: When developing an efficient parser, specific functions can be used to determine and register different types of identifiers or tokens. In our context, parseIdentifier is a function that focuses on identifying tokens of type identifier. It is responsible for verifying that the current token is not non and returning an identifier object with the token and its literal value.

  2. Registration in prefixParseFunctions: To link tokens to their respective functions, a dictionary called prefixParseFunctions is used. Here, each token type has an associated function that dictates how it should be interpreted in the parsing process. This is a powerful strategy for modularizing parsing operations, allowing both extensibility and clarity in the code.

Practical and motivational recommendations

As you move forward in building a functional parser, remember that each piece of code contributes to the stability and functionality of the project. Implementing consistent testing and performing controlled refactoring ensures that changes do not introduce bugs, improving confidence in the developed software.

Don't be discouraged if certain aspects prove challenging; even the most experienced developers face complexities when creating a complete environment for a programming language. Stay motivated and focused on the ultimate goal: the satisfaction of seeing a complete, well-structured project work. Feel free to explore further and share your experiences, as every lesson learned enriches the collective learning.

Contributions 2

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Para el tema de Enums, por si a alguien le sirve, encontr茅 este video que lo explica bien:

P.E.M.D.A.S.
Parentesis
Exponentes
Multiplicaci贸n - Divisi贸n
Adici贸n - Sustracci贸n (suma - resta)