comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Usefulness of Formal Notions in Programming (was: Verified compilers?)
Date: Thu, 08 Mar 2012 00:28:37 +0100
Date: 2012-03-08T00:28:37+01:00	[thread overview]
Message-ID: <4f57ef25$0$6582$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <1psd0g0womgxi.1sle7ol12x3d5.dlg@40tude.net>

On 07.03.12 21:17, Dmitry A. Kazakov wrote:

>>> This is a great example of making a "science" out
>>> of nothing and for nothing.

Nothing seems inherent in knowing grammars that prevents good use
of this knowledge. Uses in general system design, or in programming,
or in talking about programs, and all these activities need not have
to do with string processing. Granted, for the knowledge to be useful,
the programmer need not have specialized in grammars.

Two examples:

1. Suppose someone knows what a regular language is.

Let a regular language be taught together with finite automata,
Knowing some of the latter can instruct the design of a system whose
structure (processes, their interactions, ...) is easier to understand
because there is, in fact, a state machine that describes it.

Knowing that general regular expressions, of the CS kind, are made
by obeying simple rules will help writing REs of any variety, and
correctly at that. (I'll claim this.)

2. Suppose someone remembers some things about brackets and CFGs.

A system might have a nested structure. Things in the system first
begin and then end by first taking, and then releasing, resources, say.
Later, depending on an instance of I/O at some point, the program will
choose from a alternative nested structures.
When explaining the program's structure to someone knowing a scheme
such as a CFG, the analogy paves the way towards an understanding
of the structure of the system.

The useful relation between grammars and programming in these cases
is this:

If a person knows one simplified, abstract notion well (grammar),
the he or she will more easily understand a different notion, provided
there is an analogy, or correspondence. I'd give a similar argument
for writing programs.

It seems somewhat like knowing math. If you know it, and know how to
put math to good use, it helps understanding programs, and writing
programs,


>> The various types of grammars and the corresponding parsing procedures
>> help us understand which parsing methods work for which kinds of
>> grammars.
>
> Maybe, but they are totally irrelevant for the grammars of real programming
> languages. On one hand these classes do not capture real differences
> between syntaxes of programming languages. On the other hand, the classes
> they do describe have no other practical interest than torturing students
> of CS classes.

Counting, as you suggest for ab, aabb, aaabbb, ... turns out to be a
delusive solution. It is slippery, at least for use in programming
languages' syntaxes.

For example, Lisp interpreters would be counting brackets that match.
((())). When they have found N left brackets, they'd need to find N
right brackets, too.  Or, really, at least N right brackets, a relation
to which the makers of Lisp had submitted. For, if a programmer had
forgotten to write some right bracket in the middle of a program, the
remaining lists would pile up, the remainder of the program's text
would be added to the most recently opened list.  The dreadful
consequence is that the parser will report nothing but a "syntax error
at end of file". An error not easy to spot, and, therefore, not easy
to fix.  You would hope to be helped by a Lisp system or a pretty
printing editor.  Thus, placement and counting of embedded ((()))s
will require extreme care on the part of the programmer.  But! It is
possible to amend the grammar, and it has been done, see below. This
change cannot, however, be performed if we just focus on counting,
I think.

Consequently, reflecting the fact that programmers do not emit from
productions, but make mistakes, Lisp allows any number of right
brackets to be written in certain places to help with () matching.
For example, when closing a DEFUN list.


A less ()y solution is found in some programming languages.
Their grammars use indexed pairs of brackets, such as occur in

  "begin" ... "end"

or

  [�L�:] loop" ... "end loop [�L�]"

or

  "package �L� is" ... "end [�L�]"

Don't know whether or not a van Wijngaarden grammar can produce the
last sentences. The Ada LRM uses natural language statements such as
"a name) at the end of the right bracket must match the index at the
corresponding left bracket."

In any case, I'll bet knowing grammar at all will help one produce(!)
program designs that are easier to understand if a known scheme is
used, as outlined above.

The word marked (!) in the last sentence points out the recursive
nature of the subject. ;-)




  reply	other threads:[~2012-03-07 23:28 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-21 15:42 Verified compilers? Yannick Duchêne (Hibou57)
2012-02-24  1:41 ` Shark8
2012-02-24  8:52   ` Georg Bauhaus
2012-02-24 17:36   ` Peter C. Chapin
2012-03-06  1:27 ` Randy Brukardt
2012-03-06 17:24   ` Shark8
2012-03-06 17:43     ` Dmitry A. Kazakov
2012-03-06 19:03       ` Shark8
2012-03-07  5:33       ` Yannick Duchêne (Hibou57)
2012-03-07  9:12         ` Dmitry A. Kazakov
2012-03-07 17:49           ` Niklas Holsti
2012-03-07 20:17             ` Dmitry A. Kazakov
2012-03-07 23:28               ` Georg Bauhaus [this message]
2012-03-08  9:24                 ` Usefulness of Formal Notions in Programming Dmitry A. Kazakov
2012-03-08 10:30                   ` Nasser M. Abbasi
2012-03-08 12:37                     ` Dmitry A. Kazakov
2012-03-08  0:42               ` Verified compilers? Randy Brukardt
2012-03-08  9:25                 ` Dmitry A. Kazakov
2012-03-08 18:10                   ` Niklas Holsti
2012-03-08 20:41                     ` Dmitry A. Kazakov
2012-03-08 18:02               ` Niklas Holsti
2012-03-08 20:40                 ` Dmitry A. Kazakov
2012-03-09  0:44                   ` Georg Bauhaus
2012-03-09 22:13                   ` Niklas Holsti
2012-03-10 10:36                     ` Dmitry A. Kazakov
2012-03-10 20:35                       ` Niklas Holsti
2012-03-11  9:47                         ` Dmitry A. Kazakov
2012-03-11 22:22                           ` Niklas Holsti
2012-03-12  5:12                             ` Niklas Holsti
2012-03-12  9:43                             ` Dmitry A. Kazakov
2012-03-14  8:36                               ` Niklas Holsti
2012-03-14  9:24                                 ` Georg Bauhaus
2012-03-14 11:14                                   ` REAL (was: Verified compilers?) stefan-lucks
2012-03-14 12:59                                     ` REAL Dmitry A. Kazakov
2012-03-14 13:30                                       ` REAL Georg Bauhaus
2012-03-14 13:51                                         ` REAL Dmitry A. Kazakov
2012-03-14 20:37                                           ` REAL Brian Drummond
2012-03-14 21:52                                             ` REAL Dmitry A. Kazakov
2012-03-14 13:52                                         ` REAL georg bauhaus
2012-03-14 17:42                                         ` REAL Jeffrey Carter
2012-03-14 10:14                                 ` Verified compilers? Dmitry A. Kazakov
2012-03-14 20:13                                   ` Niklas Holsti
2012-03-11 10:55                         ` Georg Bauhaus
2012-03-10 13:46                     ` Brian Drummond
2012-03-07  1:00     ` Randy Brukardt
2012-03-07 12:42   ` Stuart
2012-03-08  1:06     ` Randy Brukardt
2012-03-08  9:04       ` Jacob Sparre Andersen
2012-03-08  9:37         ` Dmitry A. Kazakov
2012-03-08 11:23           ` Simon Wright
2012-03-08 12:27             ` Dmitry A. Kazakov
2012-03-08 10:23         ` Brian Drummond
2012-03-08 23:38           ` Bill Findlay
2012-03-09 13:56             ` Brian Drummond
2012-03-09 14:43               ` Shark8
2012-03-09 21:51                 ` Brian Drummond
2012-03-09 15:49               ` Bill Findlay
2012-03-09 20:34                 ` Brian Drummond
2012-03-09 19:40               ` Jeffrey Carter
2012-03-09 20:39                 ` Brian Drummond
2012-03-09 23:59               ` phil.clayton
2012-03-08 15:23         ` Peter C. Chapin
2012-03-09  2:04         ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox