This is a homework question. I would like to write a simple parser for Unix command line options.
First, I would like to define grammar with BNF.
Options = Option | Options, space, Option;
Option = OptionName | OptionName, OptionArguments;
OptionName = '--', any character excluding '-' | OptionName, any character;
OptionArguments = OptionArgument | OptionArguments, space, OptionArgument;
OptionArgument = any character excluding '-' | OptionArgument, any character;
("any character" here is any alphanumeric character).
Does it make sense? The next question is how to add the “old” Unix parameters that start with a single hyphen and can be grouped together (for example, ls -lht)
source
share