This document provides instructions on how to build and run the project using Docker and Make. The setup involves integrating Flex and Bison inside a Docker container for lexical and syntactic analysis.
Ensure you have the following tools installed on your system:
-
Docker
Installation Guide -
Make (Optional)
Installation Guide
You can use raw Docker commands outside the docker environment instead of Make if you prefer.
.
├── build
│ ├── grammar-out.tab.c
│ ├── grammar-out.tab.h
│ └── rules-out.yy.c
├── Dockerfile
├── Makefile
├── README.md
└── src
├── grammar.y
└── rules.l
make build-up
This command builds the Docker image using the Dockerfile and starts the container with the current directory mounted inside.
make run
This command will:
- Generate the necessary files using Bison and Flex.
- Compile the output into an executable.
- Run the program inside the container.
If you don’t want to install Make, you can build and run the Docker container manually using these commands:
docker build -t lexy .
docker run -it --rm -v "$(pwd)":/workspace lexy bash
- Explanation:
-it
: Runs the container in interactive mode.--rm
: Automatically removes the container when it exits.-v "$(pwd)":/workspace
: Mounts the current directory into the container at/workspace
.
Once inside the container, run the following commands manually:
Command | Description |
---|---|
make run |
Compiles and runs the project inside the container. |
make flex-run |
Compiles and runs the lexical definitions only. |
make clean |
Cleans up the generated files and build artifacts. |
- Note:
- Inside the container Make is installed, therefore using raw commands is unnecessary.
-
Building the Image:
- The Dockerfile installs the necessary tools (Bison, Flex, GCC, Make, etc.).
- The current directory is mounted into the container, allowing you to edit files outside the container while compiling them inside.
-
Running the Project:
- Inside the container, the Makefile handles the sequence of commands to run Bison, Flex, and GCC.
- The lexer and parser work together to process your input files.
-
Edit Source Files:
Modify thegrammar.y
(Bison grammar) andrules.l
(Flex rules) files located in thesrc/
directory using your preferred text editor or IDE.Example changes:
- grammar.y: Define grammar rules and associated actions.
- rules.l: Specify regular expressions for lexical analysis.
-
Save Changes:
Ensure all changes are saved in thesrc/
directory. Since the current directory is mounted into the container, any changes you make will be immediately available inside the container.
To remove any generated files or clean up the build
directory, run:
make clean
Or, if you prefer Docker:
docker run -it --rm -v "$(pwd)":/workspace lexy bash -c "rm -rf build"
- Dockerfile ensures a consistent environment, reducing dependency issues.
- The Makefile provides a simplified interface to run complex commands, making the build process easier.
- Manual Docker commands provide an alternative for users who prefer not to install Make.