cfgrep - Context Free egrep Variant

cfgrep is a simplified, context-free version of egrep.

When the command "java -jar cfgrep.jar cfg-exp file" is applied to a text "file", all lines in the file which match the context free grammatical expression "cfg-exp" are printed to standard output. For example, to print out all palindromic lines consisting purely of a's and b's one would use the command:

cfgrep -jar 'S:aSa|bSb|a|b|aa|bb' file
where the cfg-expression 'S:aSa|bSb|a|b|aa|bb' represents the grammar rules:
SaSa | bSb | a | b | aa | bb

I use cfgrep in my Computer Science Theory course to teach students about regular expressions. I found that standard context-free parsing tools such as yacc were too heavyweight and disqualified too many grammar types to be integrated efficiently into a course emphasizing the theory of context free grammars.

If you would like to try out cfgrep you will need to have Java on your system. Then:

  1. download the cfgrep jar file into the directory that you'll want to run it from (right click and save directly to your hard drive)
  2. follow the usage instructions
  3. try out the following cfgrep search exercises

Last modified: Fri Oct 15 16:35:09 2004