Re: language design implications for variant records in a pascal-like language

Martin Ward <martin@gkc.org.uk>
Mon, 24 Jan 2011 12:05:03 +0000

          From comp.compilers

Related articles
[55 earlier articles]
Re: language design implications for variant records in a pascal-like torbenm@diku.dk (2011-01-17)
Re: language design implications for variant records in a pascal-like dot@dotat.at (Tony Finch) (2011-01-17)
Re: language design implications for variant records in a pascal-like genew@ocis.net (Gene Wirchenko) (2011-01-17)
Re: language design implications for variant records in a pascal-like mcr@wildcard.demon.co.uk (Martin Rodgers) (2011-01-18)
Re: language design implications for variant records in a pascal-like robin51@dodo.com.au (robin) (2011-01-19)
Re: language design implications for variant records in a pascal-like 9cn6w6402@sneakemail.com (Peter Canning) (2011-01-18)
Re: language design implications for variant records in a pascal-like martin@gkc.org.uk (Martin Ward) (2011-01-24)
| List of all articles for this month |
From: Martin Ward <martin@gkc.org.uk>
Newsgroups: comp.compilers
Date: Mon, 24 Jan 2011 12:05:03 +0000
Organization: Compilers Central
References: 10-12-040 11-01-025 11-01-044
Keywords: design, syntax
Posted-Date: 26 Jan 2011 12:16:36 EST

On Thursday 13 Jan 2011 at 18:09, noitalmost <noitalmost@cox.net> wrote:
> My language solution addresses this sort of compromise. I'm providing
> traditional While, infinite Loop, and Break statements. If you have a
> Break, you only need one loop construct to provide pre-, post-, and
> mid-test loops. The While is provided simply for programmer convenience.


My language (WSL) has WHILE loops, FOR loops and loops with
multi-level EXITs. A loop of the form DO ...statements... OD can only
be terminated by an EXIT(n) statement, where n is an integer, not a
variable or expression. EXIT(n) will terminate the "n" enclosing
nested DO...OD loops.


WSL also includes a restricted type of GOTO in the form of an action
system and action calls. Roughly speaking, labels can only appear at
the top level of the program structure. CALLs (i.e. GOTOs) can only
appear within IF statements and DO...OD loops, not any other kind of
loop. This means that whenever you see a WHILE loop in WSL you can
guarantee that: (a) the condition is true at the top of the loop body,
and (b) the condition is false on termination of the loop. A REPEAT
loop ensures (b) but cannot ensure (a) since any conditions are
possible on the first iteration of the loop.


One major application of WSL is for transforming unstructured code
(translated from assembler code) to structured code, with the minimal
reduction in efficiency and while preserving any existing structure
where possible. In this context the multi-level EXITs provide a very
useful intermediate stage between unstructured spaghetti code and
fully structured code.


The FermaT program transformation system
http://www.gkc.org.uk/fermat.html is implemented almost entirely in
WSL and I have tried to use either a WHILE loop or a DO...OD loop,
depending on which seemed most natural for the code in question. WSL
also has two types of FOR loops: FOR v := start TO end STEP step DO --
the usual "counted repetition" and FOR v IN list DO -- iterate over
the elements of a list or set. WSL also has FOREACH and ATEACH loops
which iterate over the components of the current program which is
being transformed.


Out of a total of 73,713 lines of WSL code there are currently:


849 FOREACH loops
174 ATEACH loops
705 FOR ... IN ... loops
102 FOR ... STEP ... loops
727 WHILE loops
578 DO...OD loops (approx)
921 EXIT(1) statements
30 EXIT(2) statements
0 EXIT(3) or higher statements


Conclusions:


(1) Domain-specific looping constructs are very useful: at least
for the program transformation domain!


(2) Iterating over a list or set is used (in this system) much more
that iterating over a sequence of integers


(3) WHILE loops are used more often than loops with EXITs from the middle
(recall that a WSL WHILE loop cannot be terminated from the middle):
the extra "analysability" of a WHILE loop versus the convenience of an exit
from the middle suggests that it is useful to have both in a language.


(4) It is sometimes useful to EXIT directly from a double-nested loop,
but higher levels of EXITs do not occur in my code at least.


--
Martin


STRL Reader in Software Engineering and Royal Society Industry Fellow
martin@gkc.org.uk http://www.cse.dmu.ac.uk/~mward/ Erdos number: 4
G.K.Chesterton web site: http://www.cse.dmu.ac.uk/~mward/gkc/


Post a followup to this message

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