views:

16

answers:

1

I'm writing an interpreter. The interpreter accepts arguments that it itself uses, including a file to interpret. The interpreted program should not see the interpreter arguments when it queries for arguments and should see arguments meant for the interpreted program. But that's not difficult to do. Instead, I'm interested in styles on how to pass arguments to the program.

For example, the following scenarios could work:

  • interpreter [interpreter args] file [file args]

  • interpreter [interpreter args] Where [interpreter args] include the file and --prog-args n arg1 arg2 ... argn

One could be as clever as he likes with this, but I'm interested in the conventional ways of doing this.

+1  A: 

Are you asking about how to parse command line arguments or styles of them?

Look at Perl and Python manpages:

$ man perl
$ man python

They follow a pattern: interpreter [interpreter args] file [file args] interpreter -- file [file args] interpreter -e code

The -- is used to end the interpreter argument list, for example, interpreter -a -b -c -- -d is same as interpreter -a -b -c

For power users, they will run one-liner scripts, so you should add the -e CODE flags and also, read code from STDIN when no arguments are persent.

SHiNKiROU