How miguelamato/compiladorpl works
Main Components
• Compiler Driver (DomJudge.java): Acts as the starting point that reads the input source code and coordinates the process.
• Lexical Analyzer: Implements token generation. Note that there are several versions (located under directories like “implementacion_cup”, “implementacion_jflex”, “implementacion_manual”, and “implementacion_semantica”). Each comes with its own lexer (e.g., AnalizadorLexico.java) and its specification (.jflex or corresponding Cup spec).
• Syntactic Analyzer: Handles parsing based on the input tokens. Again, multiple implementations exist (e.g., “AnalizadorSintacticoEval”, “AnalizadorSintacticoTiny”, “ASTS_A” and “ASTS_D” for ascendant and descendant parsing). These are generated by tools like JavaCC, CUP, or even manually.
• Semantic Analyzer / Processing: Found in directories like “implementacion_semantica” and “procesamiento” within “implementacion_final” that handle the semantic checking (e.g., ClaseSemanticaEval, Procesamiento, Tipado, Vinculacion).
• Error Management: Dedicated modules for error reporting and handling (for example, GestionErroresEval in various parts of the project).
• Test Cases and Input Files: Multiple directories such as “pruebas_tiny”, “pruebas_tiny_0”, and “casos_prueba_correctos”/“casos_errores” to simulate inputs to the overall compiler.
Relationships and Interactions
– The driver, DomJudge.java, first reads the input source code (often provided in input.txt files or test files from “pruebas_tiny”).
– It then passes the input to the Lexical Analyzer which, using the specifications from JFlex, Cup, or JavaCC, tokenizes the code.
– The tokens are then passed to the Syntactic Analyzer, which could be implemented as a parser generated by JavaCC (using spec.jj) or CUP (using spec.cup) or manually.
– Post parsing, control is transferred to semantic analysis and other processing modules responsible for type-checking, memory management (like GestorPilaActivaciones or GestorMemoriaDinamica), and code generation steps (if any).
– Error management components are invoked at various stages (both lexical and syntactic scanning) to log or output error files, as reflected in the “casos_errores” directories.
Architectural Patterns and Design Principles
– The project is structured into clearly separated phases (lexer, parser, semantic analyzer), reflecting a typical multi-stage compiler architecture.
– The use of separate directories for different implementations (Cup, JavaCC, JFlex, manual, semantic) suggests an experimental or modular approach – allowing interchangeable components based on technology.
– Both dependency injection (via the use of external jars like java-cup-11b-runtime.jar and javacc.jar) and layered design (input -> lexical analysis -> syntactic analysis -> semantic processing) are apparent.
Relevant Technologies, Frameworks, and Libraries
– Parser generators: JavaCC, CUP, and JFlex.
– External libraries: java-cup-11b-runtime.jar and javacc.jar for parser runtime support.
– Standard Java libraries (given the .java files and the project structure).
Elements
– Nodes for each major component (Driver, Lexical Analyzer, Syntactic Analyzer, Semantic Analyzer, Error Manager, and Test Cases).
• From “Input (Source Code)” ➔ “Driver (DomJudge.java)”
• From “Driver” ➔ “Lexical Analyzer”
• Then “Lexical Analyzer” ➔ “Syntactic Analyzer”
• Next “Syntactic Analyzer” ➔ “Semantic Analyzer/Processing”
• And feedback connections from “Error Manager” back to each stage.
– Use clear labels for alternate implementations (e.g., internal modules labeled “Cup-based”, “JavaCC-based”, “JFlex-based”, “Manual”).
– Include technology notes as annotations next to the components (e.g., “spec.jflex”, “spec.cup”, “spec.jj”).
Final Advice
– Don’t shy away from splitting the system into as many components as possible (each implementation variant should be visible).
– Emphasize the modular and interchangeable nature of the different analysis implementations.