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


Groups > comp.compilers > #3152

Re: Do people create parsers for command line arguments?

From gah4 <gah4@u.washington.edu>
Newsgroups comp.compilers
Subject Re: Do people create parsers for command line arguments?
Date 2022-08-23 15:07 -0700
Organization Compilers Central
Message-ID <22-08-003@comp.compilers> (permalink)
References <AdiicpvzhWv6ZobPSqqIxS+5l4SpAw==> <22-07-054@comp.compilers>

Show all headers | View raw


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.

Back to comp.compilers | Previous | NextPrevious 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