Grammar for Unix command line options

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)

+3
source share
1 answer

, - , , , .

( "" unix), , - :

option -> optionGroup | (anything that was there before);
optionGroup -> '-', flags;
flags -> flag | flag, flags;
flag -> single letter;
+1

Source: https://habr.com/ru/post/1779738/


All Articles