home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug114.arc / VALGOL.DOC < prev    next >
Text File  |  1979-12-31  |  5KB  |  180 lines

  1.  
  2.         VALGOL I INFORMATION
  3.         --------------------        G. A. Edgar
  4.  
  5. This file contains a description of the language VALGOL I, a
  6. (very) small derivative of ALGOL-60.  It is intended to
  7. explain the compiler VALGOL.PRO on this disk.
  8.  
  9. This language was published in a paper by D. V. Schorre
  10. in 1964 as a sample language for META II.  His paper was
  11. reprinted in Dr. Dobb's Journal, April, 1980.
  12.  
  13. First, we will go through a description of the language.
  14. Then we will take a sample file and see what is involved in
  15. getting it to run.
  16.  
  17. -----------------------------------------------------------
  18.  
  19. VALGOL I is basically a subset of ALGOL-60.  The main
  20. peculiarities are these:
  21.      (1)  The key words that are usually typeset in boldface
  22. are preceded by a period.  ( .begin .end .if .then .else .until
  23. .do .integer )  This also applies to the equal sign for
  24. comparing two expressions.  ( .= )
  25.      (2)  There is only one data type, namely .integer .
  26. This is a 16 bit two's-complement number in the compiler
  27. supplied. Thus you go from 0 up to 65535, and then back to 0.
  28.      (3)  The assignment statement is reverse from the normal
  29. order.  (  5 =: x  assigns the value 5 to x )
  30.      (4)   Arithmetic allows addition ( + ) subtraction ( - )
  31. and multiplication ( * ) .  There is no unary minus sign,
  32. so if you want -2 you can write either 0-2 or else 65534 (or,
  33. for that matter, 196606) .
  34.  
  35. Let's walk through some of the syntax of the language.
  36.  
  37. A program consists of the keyword ".begin", 
  38. followed by an optional declaration, followed by one or more
  39. statements, separated by semicolons ( ; ) , followed by the
  40. keyword ".end".
  41.  
  42. A declaration consists of the keyword ".integer" followed
  43. by a list of identifiers, separated by commas.
  44.  
  45. A statement is one of the following:
  46.  
  47. (1) an I/O statement.  This is either of the form
  48.      edit( expression , 'string')
  49. which will send (expression) spaces and then the (string) to
  50. the console, or of the form
  51.      print
  52. which will send an end-of-line to the console.
  53.  
  54. (2) an assignment statement, which has the form
  55.      expression =: variable
  56.  
  57. (3) a loop, of the form
  58.      .until expression .do statement
  59. A value of 0 for the expression is considered false, and a
  60. nonzero value is true.
  61.  
  62. (4) a conditional statement of the form
  63.      .if expression .then statement .else statement
  64. The .else is not optional.
  65.  
  66. (5) a block, which consists of the keyword ".begin",
  67. followed by an optional declaration, followed by zero
  68. or more statements, separated by semicolons, followed by the
  69. keyword ".end".  Notice that the null statement in the form
  70.      .begin .end
  71. is allowed.  It is important that the semicolon is a
  72. statement separator, and not a statement terminator (as in
  73. some other languages, such as PL/I and C).  You will get
  74. a syntax error message if you put a semicolon just before
  75. the ".end" in a block.
  76.  
  77. A test for equality is allowed:
  78.     2 + x .= y * y
  79. This has value 1 if true and 0 if false.  Expressions can be
  80. built up from variables, numbers, the operations + , - ,
  81. *, and parentheses "(" , ")".
  82.  
  83.  
  84. --------------------------------------------------
  85.  
  86. Now we will go through a compile and run of a VALGOL program.
  87.  
  88. Let's use this sample program:
  89.  
  90. .begin
  91. .integer x ;
  92. 0 =: x ;
  93. .until x .= 15 .do
  94.     .begin
  95.     edit ( 1 + 14*x - x*x , '+' ) ;
  96.     print ;
  97.     x + 1 =: x
  98.     .end
  99. .end
  100.  
  101. Suppose it is in a file called P.VAL.  We compile it:
  102.  
  103. B>EPRO
  104.  
  105. E-Prolog   ver. 2.3      (August 1, 1985)
  106. > (LOAD VALGOL)
  107.  
  108. > (compile P)
  109. VALGOL 1 compiler - translates VALGOL to ASM
  110. P.VAL -> P.ASM
  111.  
  112. *** Compilation complete ***
  113. Yes.
  114. > ^C
  115.  
  116. This creates an ASM-compatible assembly-language file that
  117. begins like this:
  118.  
  119. VBDOS    EQU    5
  120. VTPA    EQU    256
  121. VCR    EQU    13
  122. VLF    EQU    10
  123.     ORG    VTPA
  124.     LXI    SP,VSTACK
  125.     JMP    V1
  126. Vx:    DW    0
  127. V1:
  128.     LXI    H,0
  129.     SHLD    Vx
  130. V2:
  131.     LHLD    Vx
  132.     PUSH    H
  133.     LXI    H,9
  134.     ...
  135. and so on.
  136.  
  137. Next, the program can be compiled and run as normal:
  138.  
  139. B>ASM P.BBZ
  140.  
  141. CP/M ASSEMBLER - VER 2.0
  142. 01F5
  143. 001H USE FACTOR
  144. END OF ASSEMBLY
  145.  
  146. B>LOAD P
  147.  
  148.  
  149. FIRST ADDRESS 0100
  150. LAST  ADDRESS 01B8
  151. BYTES READ    00B7
  152. RECORDS WRITTEN 02
  153.  
  154. B>P
  155.  +
  156.                +
  157.                          +
  158.                                   +
  159.                                         +
  160.                                               +
  161.                                                  +
  162.                                                   +
  163.                                                  +
  164.                                               +
  165.                                         +
  166.                                   +
  167.                          +
  168.                +
  169.  +
  170.  
  171. And there it is.
  172.  
  173.  
  174. -------------------------------
  175. G. A. Edgar
  176.  
  177.     May 21, 1984     [CompuServe release]
  178. revised October 21, 1984 [for Meta4 material, SIG/M vol. 208]
  179. revised August 1, 1985   [for E-Prolog release]
  180.