This repository contains a series of compiler construction assignments completed during my Bachelor's degree in Computer Science. The project builds a complete compiler for a simple programming language incrementally across multiple phases.
The project is organized into several phases, each building upon the previous one:
- Language: Java
- Components:
AnalizadorLexico.java: Lexical analyzer implementationAnalizadorSintacticoDR.java: Recursive descent syntactic analyzerToken.java: Token definitionsplp1.java: Main compiler driver
- Features: Token recognition, syntax parsing using recursive descent
- Testing: Includes autocorrector scripts and test cases
- Language: Java
- Components:
TablaSimbolos.java: Symbol table with scope managementSimbolo.java: Symbol representationTraductorDR.java: Translator integrating analysis with symbol table
- Features: Scoped symbol tables, symbol lookup and insertion
- Language: C++
- Tools: Flex (lexical analyzer), Bison (parser generator)
- Components:
p4/autocorrector-plp4/: Testing infrastructure with autocorrector scriptsplp4/: Main implementation directory with compiled executableplp4.l: Lexical specificationplp4.y: Grammar specificationTablaSimbolos.h/.cc: Symbol table implementationcomun.h: Common definitions
- Features: LALR parser, integrated symbol table management
- Build: Use
makeinplp4/directory
- Language: C++
- Tools: Flex, Bison
- Components:
plp5.l/.y: Lexical and grammar specificationsTablaSimbolos.h/.cc: Enhanced symbol tableTablaTipos.h/.cc: Type system implementationm2rc.c: Interpreter for generated code
- Features: Type checking, intermediate code generation, code execution
The compiler targets a simple imperative language with:
- Basic data types (integer, real)
- Variables and arrays
- Control structures (if, while, for)
- Functions
- Input/output operations (printf, scanf style)
- Arithmetic and logical operations
Each phase includes autocorrector scripts that compile and test the implementation:
cd p1/autocorrector-plp1/
./autocorrector-plp1.shcd p3/autocorrector-plp3/
./autocorrector-plp3.sh# Test with autocorrector
cd p4/autocorrector-plp4/
./autocorrector-plp4.sh
# Build and run manually
cd plp4/
make
./plp4 < input_filecd p5/autocorrector-plp5/
./autocorrector-plp5.sh- Java phases (1, 3): Java Development Kit (JDK)
- C++ phases (4, 5): GCC, Flex, Bison
- Testing: Bash shell for autocorrector scripts
This project was developed as part of the "Procesamiento de Lenguajes" (Language Processing) course, implementing fundamental compiler construction concepts:
- Lexical Analysis: Regular language recognition
- Syntactic Analysis: Context-free grammar parsing
- Semantic Analysis: Symbol table management and type checking
- Code Generation: Intermediate representation and target code
Each phase directory contains:
- Source code files
autocorrector-*/directories with testing infrastructure- Some phases have separate main implementation directories (e.g.,
plp4/for phase 4) fuentes/directories with test input filessalida-esperada/directories with expected outputssalida-obtenida/directories for generated outputs
- The project demonstrates progressive enhancement of compiler capabilities
- Each phase builds upon concepts from previous phases
- Autocorrector scripts provide automated testing and validation
- The final phase includes a working interpreter for the generated intermediate code /home/edu/pl/pl/README.md