Implementation of grep following course from: https://app.codecrafters.io/courses/grep/overview.
This project implements a C++ program with various components for matching and tokenizing input. The core logic is implemented in different modules that interact with each other through a well-defined API.
.
├── include/
│ ├── Matcher.hpp
│ ├── tokenizer.hpp
│ ├── tokens.hpp
│ └── utils.hpp
├── src/
│ ├── Matcher.cpp
│ ├── Server.cpp
│ ├── tokenizer.cpp
│ └── tokens.cpp
├── build/
├── test_grep.sh
├── Makefile
└── README.md
-
include/: Header files defining classes and methods.
Matcher.hpp: Handles the matching logic.tokenizer.hpp: Responsible for tokenizing input.tokens.hpp: Defines the different token types.utils.hpp: Utility functions used across the project.
-
src/: C++ source files implementing the functionality.
Matcher.cpp: Implements the matching logic.Server.cpp: Entry point for the server, includesMatcher.hpp.tokenizer.cpp: Implements tokenization logic.tokens.cpp: Implements token types and behaviors.
-
build/: Directory where object files (
.o) are generated after compilation. -
test_grep.sh: Test script for validating the program’s functionality.
- C++20 or newer
- g++ (or compatible compiler)
To compile the project, run the following command in the root directory:
makeThis will compile the source files and generate the server binary.
After compiling, you can run the program using:
./serverThe project includes a test_grep.sh script for testing the functionality of the program. This script runs a set of tests to verify that the program behaves correctly for different input scenarios.
These tests were adapted from Codecrafters GREP Tester, a testing suite that evaluates GREP-like implementations. You can run the tests using the following command:
./test_grep.shThe script will automatically run the test cases and output the results, indicating whether the program passed or failed each test.
To clean up the build files (object files and binary), run:
make cleanThis will remove the build/ directory and the server binary.