3 A Flex/Bison-based CSV parser that can handle various CSV formats including quoted fields, empty fields, and escaped characters.
9 ├── .gitignore # Ignore build artifacts and temporary files
10 ├── build.sh # Build script for easy compilation
11 ├── meson.build # Meson build configuration
12 ├── README.md # This file
13 ├── src/ # Source code directory
14 │ ├── csv.l # Flex lexer specification
15 │ └── csv.y # Bison parser specification
16 └── tests/ # Test files and documentation
17 ├── README.md # Test documentation
18 ├── test.csv # Basic test case
19 ├── complex.csv # Complex field content test
20 ├── quotes.csv # Quote handling test
21 ├── empty_fields.csv # Empty field handling test
22 ├── header_only.csv # Header-only file test
23 └── empty.csv # Empty file test
28 - **RFC 4180 CSV Parsing**: Handles standard CSV format
29 - **Quoted Field Support**: Properly processes quoted fields with commas and quotes
30 - **Empty Field Handling**: Correctly parses empty fields in any position
31 - **Memory Safe**: Conservative memory management with proper error handling
32 - **Robust Error Reporting**: Line number and context information for parse errors
36 ### Quick Build (Recommended)
44 yacc -d csv.y # Generate parser
45 flex csv.l # Generate lexer
46 gcc -o csv_parser y.tab.c lex.yy.c -ll
52 meson compile -C builddir
59 ./src/csv_parser < tests/test.csv
63 John,25,Boston" | ./src/csv_parser
65 # Test various formats
66 ./src/csv_parser < tests/complex.csv
67 ./src/csv_parser < tests/empty_fields.csv
72 The parser outputs structured information about the CSV content:
75 Header: [field1], [field2], [field3]
76 Record 1: [value1], [value2], [value3]
77 Record 2: [value4], [value5], [value6]
82 See `tests/README.md` for detailed information about test cases and expected behavior.
84 ## Implementation Notes
86 - Built with Flex 2.6+ and Bison 3.0+
87 - Uses conservative memory management approach
88 - Handles both CRLF and LF line endings
89 - Supports files with or without headers
90 - Gracefully handles malformed input with informative error messages
92 ## Recent Improvements
94 - Fixed buffer overflow vulnerabilities in lexer
95 - Added proper memory allocation failure handling
96 - Enhanced error checking in semantic actions
97 - Improved memory leak prevention
98 - Added comprehensive test suite