The template/problem statement for the Dev Summer School(CodeCraft) mini-project
This is a C++ program that reads a file, processes its lines based on specified patterns and actions, and outputs the results. The program supports a variety of operations, including comparisons and logical operations on the parsed tokens.
The Pattern-based File Processor reads lines from a file, applies user-defined patterns to each line, and performs specified actions if the patterns match. The patterns can include logical conditions and comparisons. Actions define how the matched lines are processed and output.
- Pattern Matching: Supports complex patterns using logical operators.
- Comparison Operators: Supports
<,>,<=,>=,==, and!=for comparing fields. - Logical Operators: Supports
ANDandORlogical operations between multiple patterns. - Field Access: Supports accessing specific fields within a line using
$notation. - Print Statements: Allows printing specific fields or entire lines.
./pattern_processor "<pattern { action }>" <filename><pattern { action }>: A string that specifies the pattern and action to be applied.<filename>: The name of the file to process.
Patterns specify the conditions that each line must meet for the actions to be executed. Patterns can include logical and comparison operators.
- Logical Operators:
&: Logical AND (default)|: Logical OR
- Comparison Operators:
>: Greater than<: Less than>=: Greater than or equal to<=: Less than or equal to==: Equal to!=: Not equal to
- Special Patterns:
1: Always true0: Always false/regex/: Checks if any token contains the substringregex(only supports // and /./)NR>x: Line number is greater thanxNR<x: Line number is less thanxNR=x: Line number is equal tox
- Field Access:
$n: Accesses the nth field (1-based index)
Note that the logical operations are very basic, and do not support complex chaining.
Actions define what to do with lines that match the patterns. Currently, only print statements are supported.
- Print Statement:
print $n: Prints the nth field.print $0: Prints the entire line.
Test cases will be similar to the examples, and you will have to generate the correct output.
./pattern_processor "$1>5 { print $0 }" example.txt./pattern_processor "$2==hello||NR>10 { print $0 }" example.txt./pattern_processor "NR<4 && NR >1 { print $5, $6 }" example.txt./pattern_processor "/hello/ { print $3 }" example.txt./pattern_processor "NF>5 { print $0 }" example.txtTo pass, your code must run at least 50% of the test cases correctly.
Note that the patterns will only be upto 2 (a && b or a || b), and not more complex.
Submit the completed template.cpp file to this link
Your details should be specified in the format mentioned in sample.cpp
The deadline is:
To build the project, use the following commands:
g++ -o pattern_processor main.cppThis will compile the source code and produce an executable named pattern_processor.
Credit for building the project goes to Advik, Tushar and Nandha
The code is stored in this repository and will be made public after the submission deadline