Re: Do people create parsers for command line arguments?

gah4 <gah4@u.washington.edu>
Tue, 23 Aug 2022 15:07:12 -0700 (PDT)

          From comp.compilers

Related articles
Do people create parsers for command line arguments? costello@mitre.org (Roger L Costello) (2022-07-28)
Re: Do people create parsers for command line arguments? 480-992-1380@kylheku.com (Kaz Kylheku) (2022-07-29)
Re: Do people create parsers for command line arguments? gah4@u.washington.edu (gah4) (2022-07-29)
Re: Do people create parsers for command line arguments? gciofono@gmail.com (Giacinto Cifelli) (2022-08-08)
Re: Do people create parsers for command line arguments? gah4@u.washington.edu (gah4) (2022-08-08)
Re: Do people create parsers for command line arguments? gah4@u.washington.edu (gah4) (2022-08-23)
| List of all articles for this month |

From: gah4 <gah4@u.washington.edu>
Newsgroups: comp.compilers
Date: Tue, 23 Aug 2022 15:07:12 -0700 (PDT)
Organization: Compilers Central
References: <AdiicpvzhWv6ZobPSqqIxS+5l4SpAw==> 22-07-054
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="53661"; mail-complaints-to="abuse@iecc.com"
Keywords: parse, history
Posted-Date: 23 Aug 2022 19:09:29 EDT
In-Reply-To: 22-07-054

On Friday, July 29, 2022 at 1:36:47 PM UTC-7, Roger L Costello wrote:


> I've seen some tools with pretty complicated arguments. The argument list is a
> language unto itself.


No more discussion of this for weeks now, so this is what it looks like for DCL.


DCL is Digital Command Language, which DEC used for some systems,
such as VAX/VMS. (And later VMS ports.)


DCL allows for command options following a slash, and those options
can have arguments of various types. There is a language for describing
those called Command Definition Language, with file extension CLD.


As it was the first one I found, here is the one for GAWK, or GNU Awk:


! Gawk.Cld -- command defintion for GAWK
! Pat Rankin, Nov'89
! [ revised for 2.12, May'91 ]
! [ revised for 4.0.0, Feb'11 ]
!
! This command definition is compiled into an object module which is
! linked into all three programs, GAWK, DGAWK, and PGAWK, and it is
! not able to use syntax-switching qualifers to invoke the different
! images gawk.exe, dgawk.exe, and pgawk.exe. To use dgawk or pgawk
! when this command definition is installed as a native command, use
! $ define gawk location:dgawk.exe
! or $ define gawk location:pgawk.exe
!
    module Gawk_Cmd
define verb GAWK
        synonym AWK
! image gawk !usage $ DEFINE GAWK disk:[directory]GAWK
        parameter p1, value(required,list), label=gawk_p1, prompt="data file(s)"
        qualifier input, value(required,list,type=$infile), label=progfile
        qualifier commands, value(required), label=program
        qualifier extra_commands, value(required), label=moreprog
        qualifier field_separator, value(required), label=field_sep
        qualifier variables, value(required,list)
        qualifier usage
        qualifier copyright
        qualifier version
        qualifier lint, value(list,type=lint_keywords)
        qualifier posix
        qualifier strict, negatable !synonym for /traditional
        qualifier traditional, negatable
        qualifier re_interval, negatable !only used with /traditional
        qualifier sandbox
        qualifier debug, negatable !obsolete; debug via separate DGAWK program
        qualifier output, value(type=$outfile,default="SYS$OUTPUT")
        qualifier optimize, negatable !actually on always; negation is ignored
        qualifier profile, value(type=$outfile,default="awkprof.out")
        qualifier dump_variables, value(type=$outfile,default="awkvars.out")
        qualifier non_decimal_data
        qualifier characters_as_bytes
        qualifier use_lc_numeric
        qualifier gen_pot
        qualifier reg_expr, value(type=reg_expr_keywords) !(OBSOLETE)
        disallow progfile and program !or not progfile and not program
        !disallow lint.warn and (lint.fatal or lint.invalid)
define type lint_keywords
        keyword warn, default
        keyword fatal !lint warnings terminate execution
        keyword invalid !warn about invalid constructs but not extensions
        keyword old !warn about constructs not available in original awk
define type reg_expr_keywords
        keyword awk
        keyword egrep, default !synonym for 'posix'
        keyword posix !equivalent to 'egrep'
!
! p1 = data file list (possibly including 'var=value' contructs)
!note: parameter required; use 'sys$input:' to read data from 'stdin'
! /input = program source file ('-f progfile')
! /commands = program source text ('program')
!note: either input or commands, but not both; if neither, usage message given
! /extra_commands = additional program source text; may be combined with /input
! /field_separator = character(s) delimiting record fields; default is "[ \t]"
! /reg_expr = obsolete
! /variables = list of 'var=value' items for assignment prior to BEGIN
! /posix = force POSIX compatability mode operation
! /sandbox = disable I/O redirection and use of system() to execute commands
! /strict = synonym for /traditional
! /traditional = force compatability mode operation (UN*X SYS V, Release 4)
! /re_interval = for /traditional, regular expressions allow interval ranges
! /output = destination for print,printf (default is sys$output: ie, 'stdout')
! /lint = scan the awk program for possible problems and warn about them
! /optimize = parse-time evaluation of constant [sub-]expressions only
! /debug = debugging mode; no-op unless program built using `#define DEBUG'
! /dump_var = at program termination, write out final values for all variables
! /profile = collect all parts of the parsed awk program into awkprof.out
!note: use separate pgawk program to collect run-time execution profiling
! /usage = display 'usage' reminder [describing this VMS command syntax]
! /version = show program version and quit; also shows copyright notice
! /copyright = show abbreviated edition of FSF's copyright notice and quit
!


Two things then have to happen. This file is compiled into an object file that is
linked into the executable (EXE) file itself. But also DCL needs to know
about it. The file is compiled into a binary form, that is loaded by the DCL
command parser. There is a system copy, for commands available to all users,
and a separate one for each individual user.


Among others, DCL allows for abbreviation of command names and
options to the shortest unique prefix. I suspect that the compiled CLD
file generates the tables needed to do that. So, all the command line
parsing is done by DCL before it even starts running the program, and
then the parsed command options are passed in (presumably) a convenient
form for the program to use.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.