Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Kaz Kylheku <480-992-1380@kylheku.com> Newsgroups: comp.compilers Subject: Re: Do people create parsers for command line arguments? Date: Fri, 29 Jul 2022 20:52:04 -0000 (UTC) Organization: A noiseless patient Spider Lines: 39 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <22-07-057@comp.compilers> References: <22-07-054@comp.compilers> Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="51767"; mail-complaints-to="abuse@iecc.com" Keywords: parse Posted-Date: 29 Jul 2022 17:49:35 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:3144 On 2022-07-28, Roger L Costello 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