[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: syntax across languages




   From: Pixel <pixel@mandrakesoft.com>
   Date: 13 Dec 2001 02:31:07 +0100
   ...
   http://merd.net/pixel/language-study/syntax-across-languages.html
   ...
   
   This is of course incomplete. I welcome contributions!
   
Here are some: I gae myself 20 minutes to gather some things
together.  This is very interesting; keep up the good work.
Do look further into some of the older languages (Ada, Modula-2,
Smalltalk, Fortran, PL/I, Joss, MAD, Focal, etc.).  The diversity
of notations before 1980 will astound you.

--Guy


commenting
    until end of line
	C in column 1		Fortran
	!			Fortran 90

function call
	(f a b ...)		Lisp
	a b ... f		PostScript, Forth

sequence
	,			C (comma operator)
	.			Smalltalk
	(progn x y ...)		Lisp (also "implicit progn" in the bodies
				of such constructs as lambda, let, and cond)
	end-of-line		Fortran

block
	(progn x y ...)		Lisp (also "implicit progn" in the bodies
				of such constructs as lambda, let, and cond)
	[ x. y. ... ]		Smalltalk
	{ ... }			Ruby
	foo ... end		Modula-2 (foo = if, do, ...)
	foo ... end foo		Fortran 90, Ada (foo = if, do, ...)

record selector
	.			Java, Ada, Modula-2
	%			Fortran 90
	'			Ada attribute selector

equality/inequality
    shallow
	.EQ. .NE.		Fortran
	= /=			Ada, Fortran 90
	eq functions		Lisp
	eq, eql functions	Common Lisp
	=, <>, #		Modula-2 (# and <> are synonyms)

    deep
	equal function		Lisp
	equal, equalp functions	Common Lisp

comparison
	.LT. .GT. .LE. .GE.	Fortran

if_then_else
	IF c1 THEN a* ELSIF c2 THEN b* ELSE d* END	Modula-2
	if c1 then a* elsif c2 then b* else d* end if	Ada
	(cond (c1 a*) (c2 b*) (t d*))			Lisp
	if (c1) a else if (c2) b else d			C

(I suggest that the examples illustrate a chain of if statements,
since many languages have a special keyword for such chaining
I also suggest that you distinguish between an if-then-else syntax
permitting a sequence of statements and permitting only a single
statement in various positions.  I have used "*" to indicate a
statement sequence.  In contrast, C does not permit statement
sequences; one must use a block.)

How about a category for switch/case statements?

cleanup: code executed before leaving
	unwind-protect		Common Lisp

logical or/and
    short circuit
	&, AND, OR		Modula-2 (note: no symbol equivalent for OR!)