🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Larry Cipriani Thu, 11 Dec 1986 19:36
C expression syntax in other languages?
#4464
Author: Larry Cipriani
Date: Thu, 11 Dec 1986 19:36
8 lines
791 bytes
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 ?

-- 

Larry Cipriani	AT&T Network Systems
cbosgd!{danews,cbsck}!lvc
Re: C expression syntax in other languages?
#4465
Author: rbutterworth
Date: Tue, 16 Dec 1986 21:13
45 lines
2323 bytes
> 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.

B is typeless (or rather the type is determined by the context
in which it is used), so in x=5, x(), x[2], x=2.3, x="xxx",
"goto x", the compiler treats "x" as an integer, a function,
a word array pointer, a float, a character string, or a label.

New operators are needed for floating point operations since
"x+y" adds "x" and "y" as if they were integers.  "x#+y" adds
them as if they were floats.  "#x" is the float value of the
int "x", while "##x" is the integer value of the float "x" (used
like casts in C).  This gets rather ugly, but there is seldom any
need to use the floating point operators.

There is no double precision since "x" and all expressions are
always exactly one word.  (36 bits on this Honeywell DPS-8).

ASCII is the normal character set, but grave-accent-quotes `xxx`
can be used to define up to 6 bcd characters, the same way as
apostrophe-quotes 'xxx' can be used to define up to 4 ASCII
characters.

There is an additional "@expression" operator.  It causes the
hardware indirection bit to be turned on in the last generated
instruction for the expression.  It is seldom used, even by
those that understand what this means.

  [LR]  name const primary[expr] primary(arglist) (expr)
  [RL]  ++ -- * & - ! ~ #- # ## (unary)
  [LR]  >> <<
  [LR]  &
  [LR]  ^
  [LR]  |
  [LR]  * / % #* #/ (binary)
  [LR]  + - #- #+
  [LR]  == != > < <= >= #== #!= #> #< #<= #>=
  [LR]  &&
  [LR]  ||
  [RL]  ?:
  [RL]  =  +=  -=  etc.  (all assignment operators)
Re: C expression syntax in other languages?
#4466
Author: Robert Firth
Date: Wed, 17 Dec 1986 13:58
79 lines
3296 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads