Skip to content

edudc/pl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler Construction Project

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.

Project Structure

The project is organized into several phases, each building upon the previous one:

Phase 1: Lexical and Syntactic Analysis (p1/)

  • Language: Java
  • Components:
    • AnalizadorLexico.java: Lexical analyzer implementation
    • AnalizadorSintacticoDR.java: Recursive descent syntactic analyzer
    • Token.java: Token definitions
    • plp1.java: Main compiler driver
  • Features: Token recognition, syntax parsing using recursive descent
  • Testing: Includes autocorrector scripts and test cases

Phase 3: Symbol Table Implementation (p3/)

  • Language: Java
  • Components:
    • TablaSimbolos.java: Symbol table with scope management
    • Simbolo.java: Symbol representation
    • TraductorDR.java: Translator integrating analysis with symbol table
  • Features: Scoped symbol tables, symbol lookup and insertion

Phase 4: Parser with Symbol Tables (p4/ and plp4/)

  • Language: C++
  • Tools: Flex (lexical analyzer), Bison (parser generator)
  • Components:
    • p4/autocorrector-plp4/: Testing infrastructure with autocorrector scripts
    • plp4/: Main implementation directory with compiled executable
    • plp4.l: Lexical specification
    • plp4.y: Grammar specification
    • TablaSimbolos.h/.cc: Symbol table implementation
    • comun.h: Common definitions
  • Features: LALR parser, integrated symbol table management
  • Build: Use make in plp4/ directory

Phase 5: Code Generation (p5/)

  • Language: C++
  • Tools: Flex, Bison
  • Components:
    • plp5.l/.y: Lexical and grammar specifications
    • TablaSimbolos.h/.cc: Enhanced symbol table
    • TablaTipos.h/.cc: Type system implementation
    • m2rc.c: Interpreter for generated code
  • Features: Type checking, intermediate code generation, code execution

Language Specification

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

Building and Running

Each phase includes autocorrector scripts that compile and test the implementation:

Phase 1

cd p1/autocorrector-plp1/
./autocorrector-plp1.sh

Phase 3

cd p3/autocorrector-plp3/
./autocorrector-plp3.sh

Phase 4

# Test with autocorrector
cd p4/autocorrector-plp4/
./autocorrector-plp4.sh

# Build and run manually
cd plp4/
make
./plp4 < input_file

Phase 5

cd p5/autocorrector-plp5/
./autocorrector-plp5.sh

Dependencies

  • Java phases (1, 3): Java Development Kit (JDK)
  • C++ phases (4, 5): GCC, Flex, Bison
  • Testing: Bash shell for autocorrector scripts

Academic Context

This project was developed as part of the "Procesamiento de Lenguajes" (Language Processing) course, implementing fundamental compiler construction concepts:

  1. Lexical Analysis: Regular language recognition
  2. Syntactic Analysis: Context-free grammar parsing
  3. Semantic Analysis: Symbol table management and type checking
  4. Code Generation: Intermediate representation and target code

File Organization

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 files
  • salida-esperada/ directories with expected outputs
  • salida-obtenida/ directories for generated outputs

Notes

  • 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

About

Compiler Construction Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors