How to correctly formalize the command line usage of GNU/Linux commands?

Posted by Francesco Turco on Stack Overflow See other posts from Stack Overflow or by Francesco Turco
Published on 2010-04-08T12:11:26Z Indexed on 2010/04/08 12:13 UTC
Read the original article Hit count: 424

Filed under:
|

I'd like to write down a BNF-like formal grammar for describing the command line usage of some GNU/Linux tools. For example I can describe the usage of the cat command as:

(cat-command) : 'cat' (arguments-list)
(arguments-list) : (argument)
(arguments-list) : (arguments-list) (argument)
(argument) : (file)

The problem is I can't write down a precise grammar for some commands such as md5sum. My first attempt at that would be the following:

(md5sum-command) : 'md5sum' (arguments-list)
(arguments-list) : (argument)
(arguments-list) : (arguments-list) (argument)
(argument) : (file)
(argument) : '--check'

But as you can see this grammar allows you to specify the --check argument as many times as you wish, which is incorrect as you should use it at most one time.

How can I fix that? Also, what kind of formal grammars I should study for better treating this kind of problems?

Thanks.

© Stack Overflow or respective owner

Related posts about bnf

Related posts about grammar