Para el tema de Enums, por si a alguien le sirve, encontr茅 este video que lo explica bien:
Introducci贸n al desarrollo de int茅rpretes y lenguajes de programaci贸n
Aprende a desarrollar lenguajes de programaci贸n con int茅rpretes
Desarrolla LPP o Lenguaje de Programaci贸n Platzi
Construcci贸n del lexer o tokenizador
驴Qu茅 es an谩lisis l茅xico? Funcionamiento del lexer y tokens
Estructura y definici贸n de tokens en Python
Lectura de caracteres y tokens
Tokens ilegales, operadores de un solo car谩cter y delimitadores
Reconocimiento y diferenciaci贸n entre letras y n煤meros
Declaraci贸n y ejecuci贸n de funciones
Extensi贸n del lexer: condicionales, operaciones y booleanos
Operadores de dos caracteres
Primera versi贸n del REPL con tokens
Construcci贸n del parser o analizador sint谩ctico
驴Qu茅 es un parser y AST?
Estructura y definici贸n de nodos del AST en Python
Parseo del programa o nodo principal
Parseo de assignment statements
Parseo de let statements
Parseo de errores
Parseo del return statement
T茅cnicas de parsing y pratt parsing
Pruebas del AST
Implementaci贸n del pratt parser
Parseo de Identifiers: testing
Parseo de Identifiers: implementaci贸n
Parseo de enteros
Prefix operators: negaci贸n y negativos
Infix operators y orden de las operaciones: testing
Infix operators y orden de las operaciones: implementaci贸n
Parseo de booleanos
Desaf铆o: testing de infix operators y booleanos
Parseo de expresiones agrupadas
Parseo de condicionales: testing y AST
Parseo de condicionales: implementaci贸n
Parseo de declaraci贸n de funciones: testing
Parseo de declaraci贸n de funciones: AST e implementaci贸n
Parseo de llamadas a funciones: testing y AST
Parseo de llamadas a funciones: implementaci贸n
Completando los TODOs o pendientes del lexer
Segunda versi贸n del REPL con AST
Evaluaci贸n o an谩lisis sem谩ntico
Significado de s铆mbolos
Estrategias de evaluaci贸n para int茅rpretes de software
Representaci贸n de objetos
Evaluaci贸n de expresiones: enteros
Evaluaci贸n de expresiones: booleanos y nulos
Evaluaci贸n de expresiones: prefix
Evaluaci贸n de expresiones: infix
Evaluaci贸n de condicionales
Evaluaci贸n del return statement
Manejo de errores
Ambiente
Bindings
Evaluaci贸n de funciones
Llamadas a funciones
Mejora del int茅rprete
Implementaci贸n de strings
Operaciones con strings
Built-in functions: objeto y tests
Built-in functions: evaluaci贸n
Siguientes pasos
Retos para expandir tu int茅rprete
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
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.
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.
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.
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.
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.
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.
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.
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.
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
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)
Want to see more contributions, questions and answers from the community?