Article View: comp.lang.misc
Article #6775Re: Anyone want to design a language?
From: Chris Gray
Date: Wed, 21 Feb 1990 21:28
Date: Wed, 21 Feb 1990 21:28
160 lines
5806 bytes
5806 bytes
In article <22569:05:10:24@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes:
>So what do you want in a compiled, imperative, perhaps object-oriented
>language? Take C as a starting point for good ideas and feel free to
>use parts of any other language. Remember: This isn't Ada. If it gets
>too complicated, trash it. Simple is beautiful. Modular design is
>beautiful. And above all, remember that this is going to be a language
>people can actually like.
The first thing to decide is a bit more detail on what kind of language you
are after - many of the decisions about features are affected by that. Your
hope that one language will satisfy most programmers is pretty well doomed
to failure - programmers are much too particular. For example, the
description posted by Joseph H Allen represents a language I would be very
uncomfortable with.
One goal for ANY language is that it be quickly readable by anyone, whether
they are familiar with that class of language or not. Another goal for a
compilable language is that it be reasonably compilable. C's main problem
with compilation is that the syntax is so ambiguous that a single error
(try putting a semicolon after a function header in gcc!) can lead to
hundreds of error messages. Some of Mr. Allen's ideas would be even worse
in terms of error recovery (and, in my opinion, in terms of readability).
So as to contribute a different viewpoint to this discussion, let me try to
summarize my language. It has some problems, but I and others have found it
to be quite usable. The language is called "Draco" and it currently exists
only for prehistoric CP/M computers and for the Commodore Amiga. Its syntax
is somewhat like that of Algol68, but with much less overloading. Its
semantics is somewhat like C's, but it is much more strongly typed.
Draco is a very "dull" language - it uses regular rules for identifiers, has
pretty standard syntax and semantics, is only slightly extendible, and has
no especially interesting new ideas. It is very easy to parse, and fairly
simple to generate good code for. Most people have no trouble at all reading
it for the first time (given experience in C, Pascal, Algol, whatever).
Rather than try to given a grammar, I'll just type in a mishmash program
that tries to use most of the features.
#drinc:dos/libraries.g /* include a system header */
extern fred(int i; short j; long k; char c; bool flag)float;
uint MAX_DISKS = 10;
proc hanoi(unsigned MAX_DISKS n; *char left, middle, right)void:
if n ~= 0 then
hanoi(n - 1, left, right, middle);
writeln("Move disk ", n, " from ", left, " peg to ", right, " peg.");
hanoi(n - 1, middle, left, right);
fi;
corp;
proc doit()void:
hanoi(5, "left", "right", "center");
corp;
proc matmult([*,*] float a; [*,*] float b; [*,*] float c)bool:
register uint i, j, k;
float sum;
if dim(a, 2) ~= dim(b, 1) or dim(a, 1) ~= dim(c, 1) or
dim(b, 2) ~= dim(c, 2) /* did I get this right???? */
then
false
else
for i from 0 upto dim(a, 1) - 1 do
for j from 0 upto dim(b, 2) - 1 do
sum := 0;
...
od;
od;
true
fi
corp;
/* actually all declarations have to be inside functions or before all
functions, but this is only an example */
type
array_t = [MAX_DISKS * 3, MAX_DISKS + 17] uint,
element_t = unknown 100, /* 100 bytes long */
list_t = struct {
*list_t l_next;
element_t l_this;
},
thingType_t = enum {red, blue, green}, /* NOT just ints */
otherThingType_t = union {
*char ott_name;
long ott_counter;
*somethingorothertype ott_default;
};
/* I won't try to do a user extendible type here - the compiler comes with
a complex number package that I can use like: */
complex I = (0.,1.);
complex a, b, c;
*list_t BaseList;
[0b101] struct {
*char name;
thingType_t colour;
} words := {
{"red", red}, {"blue", blue}, {"green", green}, {"white", red}, {"", red}
};
proc insert(element_t e)void:
register *list_t l;
l := new(list_t); /* language construct */
l*.l_next := BaseList;
l*.l_this := e;
BaseList := l;
corp;
proc constructs(**[2,3,4][5,6]*float youGottaBeKidding)void:
thingType_t tt;
*list_t l;
ulong n;
a := b + c;
if re(a) < 0.0 then
writeln("a = ", a);
elif a = complex(1.1, 1.1) then
readln(a, b, c);
fi;
l := BaseList;
while l ~= nil do
...
l := l*.l_next;
od;
case tt
incase red:
writeln("It was red");
incase green:
writeln("It was green");
incase blue:
writeln("It was blue");
default:
writeln("Somebody boobooed!\(BEL)\(0x07)\(0x06+2)");
esac;
l := if tt = red then nil else l*.l_next fi;
if tt = blue then return fi;
while
write("This is a prompt. Enter two integers: ");
readln(i, j)
do
writeln("You entered ", i, '(', i:x:8, ':', i:b:32, ':', i:o:7, ")");
od;
n := (0xfdecba98 & 0o237458 >< 0b100000001) << ~n;
l := pretend(128, *list_t) + 6 * sizeof(list_t);
corp;
Anyone who wants to try out the language and compiler is invited to go out
and buy an Amiga - the compiler, etc. are available freely.
--
Chris Gray Myrias Research, Edmonton +1 403 428 1616
cg@myrias.COM {uunet,alberta}!myrias!cg
Technical Details
Message-ID:
<635635738.28255@myrias.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!van-bc!ubc-cs!alberta!myrias!cgReferences:
<22569:05:10:24@stealth.acf.nyu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!van-bc!ubc-cs!alberta!myrias!cg From: cg@myrias.com (Chris Gray) Newsgroups: comp.lang.misc Subject: Re: Anyone want to design a language? Summary: I did, it works Message-ID: <635635738.28255@myrias.com> Date: 21 Feb 90 21:28:56 GMT References: <22569:05:10:24@stealth.acf.nyu.edu> Organization: Myrias Research Corporation Lines: 160