I would like to write a formal grammar similar to BNF to describe the use of the command line by some GNU / Linux tools. For example, I can describe the use of the cat as:
(cat-command) : 'cat' (arguments-list) (arguments-list) : (argument) (arguments-list) : (arguments-list) (argument) (argument) : (file)
The problem is that I cannot write the exact grammar for some commands, such as md5sum . My first attempt is as follows:
(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 --check many times as you want, which is incorrect since you should use it no more than once.
How can i fix this? Also, what formal grammars should I study to better treat such problems?
grammar bnf
Francesco turco
source share