Comparison of three imperative languages

imperative languages = procedural languages

Comparisons

All ALGOL code here is shown in all upper case, even though mixed case is legal.

feature BASIC FORTRAN ALGOL
name
origin
Beginner's All-purpose Symbolic
Instruction Code
FORmula TRANslation ALGOrithmic Language
version here,
computer
HP BASIC,
HP
FORTRAN IV = Fortran 66,
IBM
Algol-60,
Burroughs 6700
year
invented
1964 1954 1958
year
commerically released
1964 1957 1960
inventors John Kemeny,
Thomas Kurtz
John Backus committee
call by... reference reference value,
name
compilers
handle
recursion?
(yes in modern versions) no (except in Fortran 90) yes
SYNTAX
line
numbers
needed?
yes no no
line
numbers
example
10 INPUT "Your name: "; U$
20 PRINT "Hello "; U$
25 REM
30 INPUT "How many: "; N
35 S$ = ""
(none) (none)
unconventional
characters
used?
no no yes
unconventional
characters
(none) (none) up arrow
horizontal divide
identifier
maximum
recognition
length
2 6-7 unlimited
identifier
case
all upper case all upper case mixed case
identifier
examples
A
I
P1
N$
ALPHA
I
PI
NAME
ALPHA
I
PI
NAME
delimiter ; (only if on same line) (none) ;
comment REM
REM TIC-TAC-TOE
C
C TIC-TAC-TOE
COMMENT
COMMENT TIC-TAC-TOE
DATA TYPES
implicit
typing?
no yes no
implicit
typing
rules
(none) I-N integer,
otherwise real
(none)
pointers? no no no
DECLARATIONS
boolean
variable
declaration
(none) LOGICAL SWITCH
LOGICAL*1 SWITCH
LOGICAL*2 SWITCH
LOGICAL*4 SWITCH
BOOLEAN SWITCH;
integer
variable
declaration
(none) INTEGER COUNT
INTEGER*2 COUNT
INTEGER*4 COUNT
INTEGER COUNT;
real
variable
declaration
(none) REAL DISTANCE
REAL*4 DISTANCE
REAL*8 DISTANCE
REAL DISTANCE;
complex
variable
declaration
(none) COMPLEX ROOT1
COMPLEX*8 ROOT1
COMPLEX*16 ROOT1
(none)
array dimension
specifier
required?
yes
(due to lack of type declarations)
no
(due to implicit typing)
no
(due to required typing)
array bounds
specifiers exist?
no no yes
array bounds
specifiers
required?
no (don't exist) no (don't exist) yes
default first
subscript
0 1 (none--bounds required)
lower bound /
upper bound
1D dimension
semantics
(UB)
means index runs
0 through UB
(UB)
means index runs
1 through UB
[LB:UB]
means index runs
LB through UB
lower bound /
upper bound
2D dimension
semantics
(UB1, UB2)
means indices run
0 through UB1,
0 through UB2
(UB1, UB2)
means indices run
1 through UB1,
1 through UB2
[LB1:UB1, LB2:UB2]
means indices run
LB1 through UB1,
LB2 through UB2
maximum
number of
dimensions
? 3-7 ?
array
dimension
declaration
DIM P(10)
DIM A(3, 5)
DIM A(10), T(3, 5)
DIMENSION POPULATION(10)
DIMENSION A(3, 5)
DIMENSION ARRAY(10), T(3, 5)
(none)
array
type
declaration
(none--use DIM) REAL ARR1(10)
REAL T(3, 5)
INTEGER A(9)
INTEGER Q(7)
REAL ARRAY ARR1[1:10]
REAL ARRAY T[1:3, 1:5]
INTEGER ARRAY A[2:10]
INTEGER ARRAY Q[-7:-1]
string
declaration
(none) CHARACTER*64 filename STRING ...?
CONTROL
unconditional
go to
GOTO 30
.
.
.
.
GO TO 30
.
.
.
.
GOTO 30;
GOTO SLEEP;
GOTO JAIL;
GOTO HELL;
GO TO THERE;
assigned
go to
.
IF (J.EQ.1) ASSIGN 100 TO I
IF (J.EQ.2) ASSIGN 200 TO I
GOTO I
100 PRINT *, "100"
GOTO 300
200 PRINT *, "200"
300 PRINT *, "END"
.
.
.
.
.
.
.
IF J=1 THEN I := 1;
IF J=2 THEN I := 2;
SWITCH J := 100, 200;
GO TO J[I];
100:
200:

SWITCH SEASON := SPRING, SUMMER, AUTUMN, WINTER;
GO TO SEASON[I];
SPRING:
SUMMER:
AUTUMN:
WINTER:

computed
go to
. GO TO (101,102,103) K
C DEFAULT GOES HERE
...
GO TO 200
101 CONTINUE
C K = 1
...
GO TO 200
102 CONTINUE
C K = 2
...
GO TO 200
103 CONTINUE
C K = 3
...
200 CONTINUE
.
labels (none--use line numbers) 30
.
.
.
.
30:
SLEEP:
JAIL:
HELL:
THERE:
conditions
need
parentheses?
no
yes
no
if (none) IF (X.LT.0) X = -X
IF (A.GT.B) MAX = A
(none)
if-then IF X < 10 THEN
LET N = N + 1
END IF
IF (X.LT.10) THEN
N = N + 1
END IF
IF X<10 THEN
N := N+1;
if-then-else IF X <= 10 THEN
...
ELSE
...
IF X <= 10 THEN
...
ELSE
...
END IF
.
if-then-
elseif-else
IF X = 0 THEN
...
ELSEIF X <= 10 THEN
...
ELSEIF X <= 20 THEN
...
ELSE
...
END IF
IF (X.EQ.0) THEN
...
ELSE IF (X.LE.10) THEN
...
ELSE IF (X.LE.20) THEN
...
ELSE
...
END IF
IF X=0 THEN
...
ELSE IF X<=10 THEN
...
ELSE ...; ...
IF X=0 THEN
...
ELSE IF X<=10 THEN
...
ELSE IF X<=20 THEN
...;
for
loops
FOR I = 1 TO N
...
NEXT I

FOR I = 1 TO 10 STEP 2
...
NEXT I

DO 100 I = 1, N
...
100

DO 100 I = 1, 10, 2
...
100

FOR I:=1 STEP 1 UNTIL N DO ...
END

FOR I:=1 STEP 2 UNTIL 10 DO ...
END

do
loop
DO
...
LOOP UNTIL K = 32
DO WHILE (INPUT.NE.'N')
...
END DO
.
binary
operators
+
-
*
/
^
+
-
*
/
**
+
-
*
/
^
logical
operators
AND
OR
NOT
.
.
.
.AND.
.OR.
.NOT.
.EQV. (Fortran 77)
.NEQV. (Fortran 77)
.
AND
OR
NOT
EQV
.
IMP
boolean
values
. .TRUE.
.FALSE.
TRUE
FALSE
relational
operators
<
<=
=
<>
>
>=
.LT.
.LE.
.EQ.
.NE.
.GT.
.GE.
<
<=
=
<>
>
>=
ASSIGNMENT
scalar
assignment
LET R = 55
LET I = 5.5
LET A(1) = 0
LET A(K, K) = 1
LET E(I, J) = 4.5
RATE = 55
INTEREST = 5.5
A(1) = 0
A(K, K) = 1
EQUATION(I, J) = 4.5
RATE := 55;
INTEREST := 5.5;
A[1] := 0;
A[K, K] := 1;
EQUATION(I, J) := 4.5;
automatic
array
assignment
MAT T = 0 .
.
string
assignment
LET B$ = "GOOD"
.
.
single
assignment
LET S2 = 1.4142136 SQRT2 = 1.4142136 SQRT2 := 1.4142136;
multiple
assignment
. (none?) ANG1 := ANG2 := 0;
data DATA 4.48, 3.06
integer v(5)
real B(2,2)
data v/10,20,30,40,50/, B/1.0,-3.7,4.3,0.0/
.
INPUT AND OUTPUT
I/O statements
defined
in language?
yes yes no
input INPUT M
READ(6,30) M
30 FORMAT(I1)
inreal (0, guess);
data
read
FOR I = 1 TO 2
READ X(I)
(none) .
output PRINT
PRINT "HELLO!"
PRINT F
WRITE (*, *) ' HELLO!'
outstring (1, "Hello!");
spaced
output
PRINT TAB(1 + 10 * (P MOD 8)) . .
MATH FUNCTIONS
square
root
SQR(X)
SQRT(X)
DSQRT(X)
CSQRT(X)
SQRT(x)
exponential
function
EXP(X)
EXP(X)
DEXP(X)
CEXP(X)
EXP(x)
natural
logarithm
LOG(X)
ALOG(X)
DLOG(X)
CLOG(X)
LN(x)
logarithm
to base 10
LOG10(X)
ALOG10(X)
DLOG10(X)
(none)
trigonometric
functions
SIN(X)
COS(X)
TAN(X)
SIN(X), DSIN(X), CSIN(X)
COS(X), DCOS(X), CCOS(X)
TAN(X), DTAN(X)
SIN(x)
COS(x)
TAN(x)
inverse
trigonometric
functions
.
.
ATN(X)
ASIN(X), DASIN(X)
ACOS(X), DACOS(X)
ATAN(X), DATAN(X)
.
.
ARCTAN(x)
hyperbolic
trigonometric
functions
(none) SINH(X), DSINH(X)
COSH(X), DCOSH(X)
TANH(X), DTANH(X)
(none)
truncation INT(X)
AINT(X) ! Fortran 77
DINT(X) ! Fortran 77
.
round
function
ROUND(X)
NINT(X) ! Fortran 77
(none)
absolute
value
ABS(X) ABS(X) ABS()
signum
function
SGN(X) SIGN(X) ! Fortran 95 SIGN(x);
random
numbers
RND
RAN(ISEED) ! Fortran 77 RAND
wait WAIT 120
WAIT 0.5
WAIT Wait_time
WAIT Wait_time+60
WAIT
. .
integer
to
ASCII
PRINT CHR$(69) . .
PROGRAM STRUCTURE
program
statement
exist?
no (in CDC 3300) yes no
program
statement
required?
no (in CDC 3300) no no (does not exist)
program
statement
PROGRAM TTT PROGRAM TTT .
simplest
program
END
STOP
END
BEGIN
END
function
definition
DEF F(M, N)
...
LET F = ...
END DEF
AVG = SAVG(A,B,C)
...
END
.
function
definition
DEF FNA(X) = 2.1*X**3 - 4.06*X**2 + 11.9*X - 1.15
FUNCTION FAVG(I1,I2,I3)
INTEGER I1,I2,I3
FAVG = (I1+I2+I3)/3.0
RETURN
END
.
function
call
LET W = FNA(1.25) . .
procedure
definition
SUB initial(x,y)
...
END SUB
. REAL procedure average(A, n);
REAL array A; INTEGER n;
begin
...
average = ...
end;
procedure
call
CALL initial(x,y)
CALL Pop (x)
.
subroutine
call
GOSUB 100 CALL subroutine name (argument list)
CALL SAVG(A,B,C,AVG)
.
subroutine
definition
100
...
RETURN
SUBROUTINE subroutine-name (arg1, arg2, ..., argn)
IMPLICIT NONE
...
END SUBROUTINE subroutine-name

SUBROUTINE subroutine-name ()
IMPLICIT NONE
...
END SUBROUTINE subroutine-name

SUBROUTINE subroutine-name
IMPLICIT NONE
...
END SUBROUTINE subroutine-name

SUBROUTINE SAVG(I1,I2,I3,R1)
INTEGER I1,I2,I3
REAL R1
R1 = (I1+I2+I3)/3.0
RETURN
END

.
stop
required?
no yes (until Fortran 77) no
stop STOP
.
STOP
STOP 52525
STOP
.
end END END END.


References

  1. BASIC

    1. Syntax

      • version independent
        http://www.cvcc.edu/department/facstaff/frichard/csc132/Notes/ch4to6.html
      • Compaq BASIC
        http://h71000.www7.hp.com/commercial/basic/basic_doc/bas_um_019.htm
      • GW-BASIC
        http://66.70.194.202/BlastOff.htm
      • HP Business BASIC/XL
        http://docs.hp.com/cgi-bin/doc3k/B3271590001.10189/1
      • MDL-BASIC-D
        http://www.mdllabs.com/basfun.htm
      • QuickBasic
        http://www.math.hawaii.edu/~hile/basic/basicmain.htm
      • True BASIC
        http://sip.clarku.edu/tutorials/True_BASIC.html
      Syntax overview
      http://encyclopedia.laborlawtalk.com/BASIC_programming_language (5-5-05)
      http://www.answers.com/topic/basic-programming-language (5-5-05)
      http://www.networkautomation.com/automate/user/resources/help/misc/Sbe6_000Groups.htm
      http://www.xploiter.com/programming/vb/vb3_tutor/vb3c.htm
      http://academic.evergreen.edu/curricular/cofc99/vb-lang-2.html
      http://4h-technology.ifas.ufl.edu/Lessons_Activities/prog101.htm
      http://www.nicholson.com/rhn/basic/basic.man.html
      http://www.ece.gatech.edu/research/ccss/testing/docs/basic.html
      http://library.thinkquest.org/C0115420/Cyber-club%20800x600/Computer%20Parts/Software/BASIC.htm
      Specific syntax
      http://64.233.179.104/search?q=cache:eT-Vc-91bIQJ:www.nbtinc.com/pdfs/Documentation/SM800-Basic-Language-Ref.pdf+%22basic+language%22+arctangent&hl=en&client=firefox-a
      http://www.sysworks.com.au/disk$axpdocdec971/progtool/d37aaa51.p245.bkb
      http://www.devili.iki.fi/Computers/Commodore/C64/Programmers_Reference/Chapter_2/page_092.html

    2. History

      http://encyclopedia.laborlawtalk.com/BASIC_programming_language (5-5-05)
      http://www.webopedia.com/TERM/B/BASIC.html (5-5-05)

  2. FORTRAN

    1. Syntax

      General use syntax
      http://www.glue.umd.edu/~nsw/ench250/fortran1.htm#GOTOA
      http://www.gavilan.edu/csis/languages/labels.html
      http://www.gac.edu/+max/courses/S2000/MCS-287/notes/6.2/
      http://64.233.161.104/search?q=cache:aqgJ3z3dvQsJ:www.physics.ohio-state.edu/~kass/P416_Fortran_tutorial_W04.doc+fortran+goto+label&hl=en&client=firefox-a
      http://docs.hp.com/cgi-bin/doc3k/B3150190021.12118/1
      http://docs.hp.com/en/B3476-90015/apbs03.html
      http://64.233.161.104/search?q=cache:92796mtXnRMJ:www.cs.toronto.edu/~krj/courses/2307/Fortran.Guide.pdf+fortran+identifier+range+integer&hl=en&client=firefox-a
      http://64.233.161.104/search?q=cache:YI15uM4KvmQJ:staff.washington.edu/aganse/presentations/f9095.pdf+%22fortran+iv%22+log10&hl=en&client=firefox-a
      • version independent
        http://www.cru.uea.ac.uk/msc/fortran/lecture1.pdf
      • Fortran IV
        http://www.jaymoseley.com/hercules/fortran/fortmm.htm
      • Fortran 77
        http://azariah.cgore.com:8080/fortran_review.html
        http://199.88.16.12/compsci/resources/fortran/fortran2.html
        http://eyrie.shef.ac.uk/will/cpe101/guide.html
      • Fortran 90
        http://64.233.161.104/search?q=cache:6w2slLOLc58J:www.owlnet.rice.edu/~mech517/F90_docs/tables.pdf+fortran+automatic+%22array+initialization%22&hl=en&client=firefox-a
        http://www.nsc.liu.se/~boein/f77to90/
        http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html
        http://64.233.161.104/search?q=cache:GNCmAfUGXXsJ:www.ukhec.ac.uk/publications/tw/fortran.pdf+%22fortran+iv%22+sign+function&hl=en&client=firefox-a
      • XL Fortran
        http://csit1cwe.fsu.edu/extra_link/xlhpf/xlflrm03.htm
      Syntax overview
      http://geophysics.ou.edu/geomechanics/notes/fortran.html
      http://www-classes.usc.edu/engr/ce/108/text/fbk01.htm
      http://www.thocp.net/software/languages/fortran.htm
      http://www.du.edu/~etuttle/math/fortran.htm
      http://math.scu.edu/~dsmolars/ma60/nchpt1.html
      http://www.cs.rit.edu/~ats/lfl/2003-1/fortran.pdf
      http://www.nea.fr/html/dbprog/ Newsletter/Upgradingto95-long.pdf
      Specific syntax
      http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap07/subroutine.html
      http://www.tacc.utexas.edu/services/userguides/intel8/fc/f_ug1/pgwarray.htm
      http://www.aspire.cs.uah.edu/aspire/summer/manuals/fortran/subroutines.html
      http://www.chem.ox.ac.uk/fortran/ifthen.html

      • subroutines
        http://www.physics.utah.edu/~p573/hamlet/lessons/packages/packages/node2.html
      • logarithms
        http://www.delorie.com/gnu/docs/gcc/g77_245.html

    2. History

      http://inventors.about.com/library/weekly/aa072198.htm
      http://www.nsc.liu.se/~boein/f77to90/a7.html
      http://www.du.edu/~etuttle/math/fortran.htm
      http://www.du.edu/~etuttle/math/fortran.htm

  3. Algol-60

    1. Syntax

      General use syntax
      http://burks.brighton.ac.uk/burks/language/other/a60rr/syntax.txt
      http://www.csci.csusb.edu/dick/samples/algol60.syntax.html
      http://www.stanford.edu/class/cs242/slides/2003/ml.pdf
      http://users.tpg.com.au/adsln4yb/Guess/guess.a60
      Syntax overview
      http://en.wikipedia.org/wiki/ALGOL_programming_language
      Specific syntax
      http://en.wikipedia.org/wiki/Boolean_datatype

    2. History

      http://mbinfo.mbdesign.net/1937-1960.htm
      http://www.thocp.net/software/languages/algol.htm


HOME

Created: March 26, 2005
Updated: May 7, 2005