xiiregexbuilder

FPGA-Accelerated Regular Expression Matching Engine
commit 67bde232f6840495b986c67fdc1cb629471e7803
parent e298cda282f22b28115114d4c1aabc3c0b2572fb
Author: RahulSannapureddy <rahul.sannapureddy@gmail.com>
Date:   Fri, 27 Mar 2026 09:04:36 +0530

Week 2: Add golden C++ reference regex engine (Part 2: Core logic)

Diffstat:
Msrc/golden.cpp | 41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/golden.cpp b/src/golden.cpp @@ -29,3 +29,44 @@ int main(int argc, char* argv[]) { return 1; } + std::vector<std::string> regexes; + std::string line; + while (std::getline(regexFile, line)) { + std::string trimmed = trim(line); + if (trimmed.empty() || trimmed[0] == '#') continue; + regexes.push_back(trimmed); + } + regexFile.close(); + + std::ifstream testFile(testFilename); + if (!testFile.is_open()) { + std::cerr << "Failed to open " << testFilename << std::endl; + return 1; + } + + std::vector<std::string> testStrings; + while (std::getline(testFile, line)) { + // Remove trailing \r\n + size_t last = line.find_last_not_of("\r\n"); + std::string s = (last != std::string::npos) ? line.substr(0, last + 1) : (line.empty() ? "" : line); + + // Skip comments and blank lines if desired, but spec says "Each line is one test string" + // Let's at least skip the comment headers if they start with # + if (!s.empty() && s[0] == '#') continue; + if (s.empty()) { + // Check if it's truly a blank line (might be intentional empty string test) + // For safety, let's only skip if the raw line was empty or just whitespace + if (trim(line).empty()) continue; + } + + testStrings.push_back(s); + } + testFile.close(); + + std::ofstream outFile(outputFilename); + if (!outFile.is_open()) { + std::cerr << "Failed to open " << outputFilename << " for writing." << std::endl; + return 1; + } + + for (const auto& testStr : testStrings) {