Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!pt.cs.cmu.edu!sei.cmu.edu!firth From: firth@sei.cmu.edu (Robert Firth) Newsgroups: comp.lang.misc,comp.lang.c Subject: Re: C expression syntax in other languages? Message-ID: <491@aw.sei.cmu.edu.sei.cmu.edu> Date: Wed, 17-Dec-86 08:58:10 EST Article-I.D.: aw.491 Posted: Wed Dec 17 08:58:10 1986 Date-Received: Thu, 18-Dec-86 01:42:26 EST References: <358@danews.ATT.COM> <3971@watmath.UUCP> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (PUT YOUR NAME HERE) Organization: Carnegie-Mellon University, SEI, Pgh, Pa Lines: 79 Keywords: C,syntax Xref: mnetor comp.lang.misc:55 comp.lang.c:450 In article <3971@watmath.UUCP> rbutterworth@watmath.UUCP (Ray Butterworth) writes: >> One of the reasons I enjoy programming in C so much is its >> expression syntax. Are there any other languages that have >> a similar expression syntax? Do BCPL and B have it ? > >B has a very similar syntax. If written carefully. some simple >programs will compile and run correctly under either language. > ... Thanks, Ray; I found that a useful summary of B. In return, I'll submit a page on BCPL. BCPL is the ancestor of B. It is typeless, admitting only one physical data type, basically the contents of a machine word. There are various operations on this, eg arithmetic: + - * / REM comparison: = ~= > < >= <= logical: ~ /\ \/ EQV NEQV << >> indirection: ! application: () The ! operator is like C's "*", it defererences; the () calls the preceding expression as a function. The operator "@" takes the BCPL address of any variable; this has the property that the addresses of adjacent "words" differ by 1. On byte addressed machines, we have to scale the machine address to get the "word" address. The syntax is much closer to Algol than that of B or C: IF condition THEN statement ELSE statement FOR variable = expression TO expression BY constant DO statement and so on. The assignment symbol is ":=". BCPL has the McCarthy conditional (C's "?") in a form illustrated by q := p=NIL -> NIL, p!next In addition, the logical and ("/\" or "&") and or ("\/" or "|") are automatically short-circuit in control expressions IF p=NIL \/ p!next = NIL THEN ... avoiding the need for "&&". The language is not an expression language; a statement delivers no value. However, the construct VALOF { block } is an expression; within the enclosed block the statement RESULTIS expression terminates execution and exits the block. Here's a piece of BCPL: || Lookup ( v : ARRAY OF Item, x : Item ) : Index || || Find the index of X in V and return it. If X does not || occur in V, return 0. V!0 is the length of the vector LET lookup(v,x) = VALOF { FOR i=1 TO v!0 DO IF v!i=x RESULTIS i RESULTIS 0 } Note that the keywords DO and THEN can be elided before another keyword. I find BCPL very easy to use, very readable (unlike, dare I say it, C!) and sufficiently powerful for most systems programming tasks. It is also small enough to be readily implementable (the portable front end is about 1200 lines code and a typical back end is a bit less), and has a very precise defining document. Thank you for your attention.