Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #3144

Re: Do people create parsers for command line arguments?

From Kaz Kylheku <480-992-1380@kylheku.com>
Newsgroups comp.compilers
Subject Re: Do people create parsers for command line arguments?
Date 2022-07-29 20:52 +0000
Organization A noiseless patient Spider
Message-ID <22-07-057@comp.compilers> (permalink)
References <22-07-054@comp.compilers>

Show all headers | View raw


On 2022-07-28, Roger L Costello <costello@mitre.org> wrote:
> Hi Folks,
>
> I've seen some tools with pretty complicated arguments. The argument list is a
> language unto itself.
>
> Do people create parsers for command line arguments? Or is a parser overkill?

It happens.

You probably know these examples.

The find utility has an expression syntax whose tokens are command line
arguments. Parentheses are used for overriding precedence; they must be
escaped in common shell languages, so they are passed through to find
verbatim:

  find /etc \( -name '*.conf' -o -name '*.xml \) -exec command {} \:

The [ command also parses expressions that are individual arguments:

  if [ $foo = $bar -o $n1 -gt $n2 ] ; then ...

The tcpdump utility uses command line arguments as the tokens for
pcap filter expressions. (Sort of). Example from man page:

       To print traffic between helios and either hot or ace:

              tcpdump host helios and \( hot or ace \)

However, tcpdump can do its own splitting; the expression can be
quoted as one argument.

All of these programs must be parsing. They have phrase structures
and operator precedence with parentheses right the command line.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Do people create parsers for command line arguments? Roger L Costello <costello@mitre.org> - 2022-07-28 11:14 +0000
  Re: Do people create parsers for command line arguments? Kaz Kylheku <480-992-1380@kylheku.com> - 2022-07-29 20:52 +0000
    Re: Do people create parsers for command line arguments? gah4 <gah4@u.washington.edu> - 2022-07-29 15:30 -0700
      Re: Do people create parsers for command line arguments? Giacinto Cifelli <gciofono@gmail.com> - 2022-08-08 18:25 +0200
        Re: Do people create parsers for command line arguments? gah4 <gah4@u.washington.edu> - 2022-08-08 22:01 -0700
        Re: Do people create parsers for command line arguments? Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2022-09-29 13:16 -0400
  Re: Do people create parsers for command line arguments? gah4 <gah4@u.washington.edu> - 2022-08-23 15:07 -0700

csiph-web