help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make awk more friendly to multiline function declaration


From: Nelson H. F. Beebe
Subject: Re: Make awk more friendly to multiline function declaration
Date: Wed, 30 Mar 2022 06:30:39 -0600

Peng Yu <pengyu.ut@gmail.com> has asked about changing gawk's grammar
to permit newlines between parameter names and commas.

It is important to remember that gawk is just one of several
implementations of the Awk programming language, and Awk itself was
first defined in a public forum in the 1988 book ``The AWK Programming
Language'' (ISBN 0-201-07981-X), and then more formally in successive
IEEE POSIX Standards.

It is a great strength of the Awk language that it is both
standardized, widely available, and independently implemented.  Awk
programs enjoy a high degree of portability across all modern
operating systems.

By contrast, several other widely used scripting languages appear to
have only a single implementation, and vague grammars.  The current
chaos caused by introduction of incompatible syntax between Python
versions 2 and 3, and Perl versions 5 and 6, should be a strong lesson
that language stability matters for users of the languages, who are
far more numerous than the authors of interpreters and compilers, and
who have academic / corporate / industrial / governmental
responsibilities of writing and maintaining software over long
periods, and for applications that may have huge financial /
institutional / career importance.

I am aware of at least one commercial symbolic algebra system where
program meaning has changed with successive releases, because there
was no formal public grammar specification.  That misfeature thwarted
an important project of translating software in that language into
equivalent code in another algebra system.

The gawk team has chosen to experiment with carefully specified
language extensions that offer useful new features, but gawk can still
operate in POSIX Standard mode, and Awk programmers can choose to use
gawk extensions or not.  I personally have written about a half
million lines of code in the language, and have only rarely needed any
of gawk's extensions.  It is far more important to me that my code be
portable across awk implementations, and across operating systems.

The POSIX Standards define a rigorous grammar for the Awk language,
and in the 2001 standard, I find in the Shell and Utilities volume on
page 171 this grammar snippet:

6555     param_list : NAME
6556                | param_list ',' NAME
6557                ;

Elsewhere in the grammar, optional newlines are expressly indicated,
as in this snippet:

6563     action  : '{' newline_opt                              '}'
6564             | '{' newline_opt terminated_statement_list    '}'
6565             | '{' newline_opt unterminated_statement_list  '}'
6566             ;

Thus, Peng's request for permitting newlines before the comma in line
6556 violates the grammar.

Having such extensions in particular implementations would be
detrimental to software portability, and I suggest that further
discussion on this list of Peng's proposal be dropped.


-------------------------------------------------------------------------------
- Nelson H. F. Beebe                    Tel: +1 801 581 5254                  -
- University of Utah                    FAX: +1 801 581 4148                  -
- Department of Mathematics, 110 LCB    Internet e-mail: beebe@math.utah.edu  -
- 155 S 1400 E RM 233                       beebe@acm.org  beebe@computer.org -
- Salt Lake City, UT 84112-0090, USA    URL: http://www.math.utah.edu/~beebe/ -
-------------------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]