The document defines the language piece by piece. For each part it defines the syntax and semantics. It also comments on the purpose for the part and gives examples of the code described. Good LRMs need examples, comments, syntax, and semantics.
This manual was written using XBNF and translated to HTML by Dr. Botting's mth2html translator that also indexed and added the contents list and inserted hyperlinks. These are also parts of good manuals.
This is an example for a class and is the basis for project work, so I've not documented some of the options and issues that arise in the design languages. I've deliberately added one feature that is a bad idea. I wonder if you can spot the language that I ripped it from.... and added a perverse twist of my own
Warning
This is a bad language. Do not try it at home. If you feel like
wtiing a compiler -- it is not difficult BUT its better to fix the problems
with it FIRST.
Programs
An A program consists of a series of executable statements (each on one
line), and terminated by an "END" statement:
Here is an example of an A program:
READ a
b=a*a
PRINT b
ENDThe above program reads a floating point decimal number (7.0 for example, and puts it into floating point location a. The next squares it, and stores the result in b. Then it prints out the result(49.0).
A program in A starts by executing the the first statement and finishes when the END statement is executed. Normally each statement is taken in sequence, however, some statements can select a different successor statement that is before or after them in the sequence. For example to print the sum of the first n integers one writes:
i=1
s=0
READ n
j=i>=n
SKIP 4*j
s=s+i
i=i+1
SKIP -4
PRINT s
END
The following program does the same thing using a formula (s = n(n+1)/2) instead of a loop.
i=1
READ n
s=n+1
s=s*n
s=s/2
PRINT s
ENDNotice how complex formaluae are written as a series of simple ones.
d=b*b
e=4*a
e=e*c
d=d-e
READ a
READ n
PRINT d
OUT Real Roots
SKIP -12
SKIP +3
SKIP 0
SKIP +17*kThe following indicates which statement is executed given the values 0, -1, -2, +1, and +2
(-2) ...
(-1)...
SKIP ?
(0) ....
(+1) ...
(+2) ...
Examples
x
-x
i+1
x+i
x+1.234
-x+y
+x*y
-3
j=x>y
SKIP 2*j
z=y
SKIP 1
z=xexercise: can you write code to put the minimum of x, y into z?
1234
12.34Notice that "1." and ".95" must be written as "1.0" and "0.95" respectively.
READ a
READ b
READ c
d=b*b
e=4*a
e=e*c
d=d-e
e=2*a
r=d<0
SKIP r*7
d=SQRT d
s=-b+d
s=s/e
t=-t-d
t=t/e
PRINT s
PRINT t
SKIP 7
d=d-d
d=SQRT d
s=-b/e
t=d/e
PRINT s
OUT + or - i *
PRINT t
ENDExercise: handle the case when a is zero.
Semantics
Here is an outline
of the semantic structure of the language A in the
UML.
Note
A is not the smallest possible programming language.
. . . . . . . . . ( end of section The Language A) <<Contents | End>>
Notation
. . . . . . . . . ( end of section Language Reference Manual for the Language A) <<Contents | End>>