syntax.doc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. .sp 1.5i
  2. .LP
  3. .vs 14
  4. .nh
  5. .ft B
  6. Appendix A: ISO-PASCAL grammar
  7. .ft R
  8. \fBA.1 Lexical tokens\fR
  9. The syntax describes the formation of lexical tokens from characters and the
  10. separation of these tokens, and therefore does not adhere to the same rules
  11. as the syntax in A.2.
  12. The lexical tokens used to construct Pascal programs shall be classified into
  13. special-symbols, identifiers, directives, unsigned-numbers, labels and
  14. character-strings. The representation of any letter (upper-case or lower-case,
  15. differences of font, etc) occurring anywhere outside of a character-string
  16. shall be insignificant in that occurrence to the meaning of the program.
  17. letter = \fBa\fR | \fBb\fR | \fBc\fR | \fBd\fR | \fBe\fR | \fBf\fR | \fBg\fR | \fBh\fR | \fBi\fR | \fBj\fR | \fBk\fR | \fBl\fR | \fBm\fR | \fBn\fR | \fBo\fR | \fBp\fR | \fBq\fR | \fBr\fR | \fBs\fR | \fBt\fR | \fBu\fR | \fBv\fR | \fBw\fR | \fBx\fR | \fBy\fR | \fBz\fR .
  18. digit = \fB0\fR | \fB1\fR | \fB2\fR | \fB3\fR | \fB4\fR | \fB5\fR | \fB6\fR | \fB7\fR | \fB8\fR | \fB9\fR .
  19. The special symbols are tokens having special meanings and shall be used to
  20. delimit the syntactic units of the language.
  21. special-symbol = \fB+\fR | \fB\-\fR | \fB*\fR | \fB/\fR | \fB=\fR | \fB<\fR | \fB>\fR | \fB[\fR | \fB]\fR | \fB.\fR | \fB,\fR | \fB:\fR | \fB;\fR | \fB^\fR | \fB(\fR | \fB)\fR | \fB<>\fR | \fB<=\fR | \fB>=\fR | \fB:=\fR | \fB..\fR |
  22. \h'\w'special-symbol = 'u'word-symbol .
  23. word-symbol = \fBand\fR | \fBarray\fR | \fBbegin\fR | \fBcase\fR | \fBconst\fR | \fBdiv\fR | \fBdo\fR | \fBdownto\fR | \fBelse\fR | \fBend\fR | \fBfile\fR | \fBfor\fR | \fBfunction\fR |
  24. \h'\w'word-symbol = 'u'\fBgoto\fR | \fBif\fR | \fBin\fR | \fBlabel\fR | \fBmod\fR | \fBnil\fR | \fBnot\fR | \fBof\fR | \fBor\fR | \fBpacked\fR | \fBprocedure\fR | \fBprogram\fR | \fBrecord\fR |
  25. \h'\w'word-symbol = 'u'\fBrepeat\fR | \fBset\fR | \fBthen\fR | \fBto\fR | \fBtype\fR | \fBuntil\fR | \fBvar\fR | \fBwhile\fR | \fBwith\fR .
  26. Identifiers may be of any length. All characters of an identifier shall be
  27. significant. No identifier shall have the same spelling as any word-symbol.
  28. identifier = letter { letter | digit } .
  29. A directive shall only occur in a procedure-declaration or function-declaration.
  30. No directive shall have the same spelling as any word-symbol.
  31. directive = letter {letter | digit} .
  32. Numbers are given in decimal notation.
  33. .nf
  34. unsigned-integer = digit-sequence .
  35. unsigned-real = unsigned-integer \fB.\fR fractional-part [ \fBe\fR scale-factor ] | unsigned-integer \fBe\fR scale-factor .
  36. digit-sequence = digit {digit} .
  37. fractional-part = digit-sequence .
  38. scale-factor = signed-integer .
  39. signed-integer = [sign] unsigned-integer .
  40. sign = \fB+\fR | \fB\-\fR .
  41. .fi
  42. .bp
  43. Labels shall be digit-sequences and shall be distinguished by their apparent
  44. integral values and shall be in the closed interval 0 to 9999.
  45. label = digit-sequence .
  46. A character-string containing a single string-element shall denote a value of
  47. the required char-type. Each string-character shall denote an implementation-
  48. defined value of the required char-type.
  49. .nf
  50. character-string = \fB'\fR string-element { string-element } \fB'\fR .
  51. string-element = apostrophe-image | string-character .
  52. apostrophe-image = \fB''\fR .
  53. string-character = All 7-bits ASCII characters except linefeed (10), vertical tab (11), and new page (12).
  54. .fi
  55. The construct:
  56. \fB{\fR any-sequence-of-characters-and-separations-of-lines- not-containing-right-brace \fB}\fR
  57. shall be a comment if the "{" does not occur within a character-string or
  58. within a comment. The substitution of a space for a comment shall not alter
  59. the meaning of a program.
  60. Comments, spaces (except in character-strings), and the separation of
  61. consecutive lines shall be considered to be token separators. Zero or more
  62. token separators may occur between any two consecutive tokens, or before
  63. the first token of a program text. No separators shall occur within tokens.
  64. .bp
  65. .po
  66. \fBA.2 Grammar\fR
  67. The non-terminal symbol \fIprogram\fR is the start symbol of the grammar.
  68. .nf
  69. actual-parameter : expression | variable-access | procedure-identifier | function-identifier .
  70. actual-parameter-list : \fB(\fR actual-parameter { \fB,\fR actual-parameter } \fB)\fR .
  71. adding-operator : \fB+\fR | \fB\-\fR | \fBor\fR .
  72. array-type : \fBarray\fR \fB[\fR index-type { \fB,\fR index-type } \fB]\fR \fBof\fR component-type .
  73. array-variable : variable-access .
  74. assignment-statement : ( variable-access | function-identifier ) \fB:=\fR expression .
  75. base-type : ordinal-type .
  76. block : label-declaration-part constant-definition-part type-definition-part variable-declaration-part
  77. \h'\w'block : 'u'procedure-and-function-declaration-part statement-part .
  78. Boolean-expression : expression .
  79. bound-identifier : identifier .
  80. buffer-variable : file-variable \fB^\fR .
  81. case-constant : constant .
  82. case-constant-list : case-constant { \fB,\fR case-constant } .
  83. case-index : expression .
  84. case-list-element : case-constant-list \fB:\fR statement .
  85. case-statement : \fBcase\fR case-index \fBof\fR case-list-element { \fB;\fR case-list-element } [ \fB;\fR ] \fBend\fR .
  86. component-type : type-denoter .
  87. component-variable : indexed-variable | field-designator .
  88. compound-statement : \fBbegin\fR statement-sequence \fBend\fR .
  89. conditional-statement : if-statement | case-statement .
  90. conformant-array-parameter-specification : value-conformant-array-specification |
  91. \h'+18.5m'variable-conformant-array-specification .
  92. conformant-array-schema : packed-conformant-array-schema | unpacked-conformant-array-schema .
  93. constant : [ sign ] ( unsigned-number | constant-identifier ) | character-string .
  94. constant-definition : identifier \fB=\fR constant .
  95. constant-definition-part : [ \fBconst\fR constant-definition \fB;\fR { constant-definition \fB;\fR } ] .
  96. constant-identifier : identifier .
  97. control-variable : entire-variable .
  98. domain-type : type-identifier .
  99. else-part : \fBelse\fR statement .
  100. empty-statement : .
  101. entire-variable : variable-identifier .
  102. enumerated-type : \fB(\fR identifier-list \fB)\fR .
  103. expression : simple-expression [ relational-operator simple-expression ] .
  104. .bp
  105. .po
  106. factor : variable-access | unsigned-constant | bound-identifier | function-designator | set-constructor |
  107. \h'\w'factor : 'u'\fB(\fR expression \fB)\fR | \fBnot\fR factor .
  108. field-designator : record-variable \fB.\fR field-specifier | field-designator-identifier .
  109. field-designator-identifier : identifier .
  110. field-identifier : identifier .
  111. field-list : [ ( fixed-part [ \fB;\fR variant-part ] | variant-part ) [ \fB;\fR ] ] .
  112. field-specifier : field-identifier .
  113. file-type : \fBfile\fR \fBof\fR component-type .
  114. file-variable : variable-access .
  115. final-value : expression .
  116. fixed-part : record-section { \fB;\fR record-section } .
  117. for-statement : \fBfor\fR control-variable \fB:=\fR initial-value ( \fBto\fR | \fBdownto\fR ) final-value \fBdo\fR statement .
  118. formal-parameter-list : \fB(\fR formal-parameter-section { \fB;\fR formal-parameter-section } \fB)\fR .
  119. formal-parameter-section : value-parameter-specification | variable-parameter-specification |
  120. \h'\w'formal-parameter-section : 'u'procedural-parameter-specification | functional-parameter-specification |
  121. \h'\w'formal-parameter-section : 'u'conformant-array-parameter-specification .
  122. function-block : block .
  123. function-declaration : function-heading \fB;\fR directive | function-identification \fB;\fR function-block |
  124. \h'\w'function-declaration : 'u'function-heading \fB;\fR function-block .
  125. function-designator : function-identifier [ actual-parameter-list ] .
  126. function-heading : \fBfunction\fR identifier [ formal-parameter-list ] \fB:\fR result-type .
  127. function-identification : \fBfunction\fR function-identifier .
  128. function-identifier : identifier .
  129. functional-parameter-specification : function-heading .
  130. goto-statement : \fBgoto\fR label .
  131. identified-variable : pointer-variable \fB^\fR .
  132. identifier-list : identifier { \fB,\fR identifier } .
  133. if-statement : \fBif\fR Boolean-expression \fBthen\fR statement [ else-part ] .
  134. index-expression : expression .
  135. index-type : ordinal-type .
  136. index-type-specification : identifier \fB..\fR identifier \fB:\fR ordinal-type-identifier .
  137. indexed-variable : array-variable \fB[\fR index-expression { \fB,\fR index-expression } \fB]\fR .
  138. initial-value : expression .
  139. label : digit-sequence .
  140. label-declaration-part : [ \fBlabel\fR label { \fB,\fR label } \fB;\fR ] .
  141. member-designator : expression [ \fB..\fR expression ] .
  142. multiplying-operator : \fB*\fR | \fB/\fR | \fBdiv\fR | \fBmod\fR | \fBand\fR .
  143. .bp
  144. .po
  145. new-ordinal-type : enumerated-type | subrange-type .
  146. new-pointer-type : \fB^\fR domain-type .
  147. new-structured-type : [ \fBpacked\fR ] unpacked-structured-type .
  148. new-type : new-ordinal-type | new-structured-type | new-pointer-type .
  149. ordinal-type : new-ordinal-type | ordinal-type-identifier .
  150. ordinal-type-identifier : type-identifier .
  151. packed-conformant-array-schema : \fBpacked\fR \fBarray\fR \fB[\fR index-type-specification \fB]\fR \fBof\fR type-identifier .
  152. pointer-type-identifier : type-identifier .
  153. pointer-variable : variable-access .
  154. procedural-parameter-specification : procedure-heading .
  155. procedure-and-function-declaration-part : { ( procedure-declaration | function-declaration ) \fB;\fR } .
  156. procedure-block : block .
  157. procedure-declaration : procedure-heading \fB;\fR directive | procedure-identification \fB;\fR procedure-block |
  158. \h'\w'procedure-declaration : 'u'procedure-heading \fB;\fR procedure-block .
  159. procedure-heading : \fBprocedure\fR identifier [ formal-parameter-list ] .
  160. procedure-identification : \fBprocedure \fR procedure-identifier .
  161. procedure-identifier : identifier .
  162. procedure-statement : procedure-identifier ( [ actual-parameter-list ] | read-parameter-list | readln-parameter-list |
  163. \h'\w'procedure-statement : procedure-identifier ( ['u'write-parameter-list | writeln-parameter-list ) .
  164. program : program-heading \fB;\fR program-block \fB.\fR .
  165. program-block : block .
  166. program-heading : \fBprogram\fR identifier [ \fB(\fR program-parameters \fB)\fR ] .
  167. program-parameters : identifier-list .
  168. read-parameter-list : \fB(\fR [ file-variable \fB,\fR ] variable-access { \fB,\fR variable-access } \fB)\fR .
  169. readln-parameter-list : [ \fB(\fR ( file-variable | variable-access ) { \fB,\fR variable-access } \fB)\fR ] .
  170. record-section : identifier-list \fB:\fR type-denoter .
  171. record-type : \fBrecord\fR field-list \fBend\fR .
  172. record-variable : variable-access .
  173. record-variable-list : record-variable { \fB,\fR record-variable } .
  174. relational-operator : \fB=\fR | \fB<>\fR | \fB<\fR | \fB>\fR | \fB<=\fR | \fB>=\fR | \fBin\fR .
  175. repeat-statement : \fBrepeat\fR statement-sequence \fBuntil\fR Boolean-expression .
  176. repetitive-statement : repeat-statement | while-statement | for-statement .
  177. result-type : simple-type-identifier | pointer-type-identifier .
  178. set-constructor : \fB[\fR [ member-designator { \fB,\fR member-designator } ] \fB]\fR .
  179. set-type : \fBset\fR \fBof\fR base-type .
  180. sign : \fB+\fR | \fB\-\fR .
  181. simple-expression : [ sign ] term { adding-operator term } .
  182. simple-statement : empty-statement | assignment-statement | procedure-statement | goto-statement .
  183. simple-type-identifier : type-identifier .
  184. .bp
  185. .po
  186. statement : [ label \fB:\fR ] ( simple-statement | structured-statement ) .
  187. statement-part : compound-statement .
  188. statement-sequence : statement { \fB;\fR statement } .
  189. structured-statement : compound-statement | conditional-statement | repetitive-statement | with-statement .
  190. subrange-type : constant \fB..\fR constant .
  191. tag-field : identifier .
  192. tag-type : ordinal-type-identifier .
  193. term : factor { multiplying-operator factor } .
  194. type-definition : identifier \fB=\fR type-denoter .
  195. type-definition-part : [ \fBtype\fR type-definition \fB;\fR { type-definition \fB;\fR } ] .
  196. type-denoter : type-identifier | new-type .
  197. type-identifier : identifier .
  198. unpacked-conformant-array-schema : \fBarray\fR \fB[\fR index-type-specification { \fB;\fR index-type-specification } \fB]\fR \fBof\fR
  199. \h'\w'unpacked-conformant-array-schema : 'u'( type-identifier | conformant-array-schema ) .
  200. unpacked-structured-type : array-type | record-type | set-type | file-type .
  201. unsigned-constant : unsigned-number | character-string | constant-identifier | \fBnil\fR .
  202. unsigned-number : unsigned-integer | unsigned-real .
  203. value-conformant-array-specification : identifier-list \fB:\fR conformant-array-schema .
  204. value-parameter-specification : identifier-list \fB:\fR type-identifier .
  205. variable-access : entire-variable | component-variable | identified-variable | buffer-variable .
  206. variable-conformant-array-specification : \fBvar\fR identifier-list \fB:\fR conformant-array-schema .
  207. variable-declaration : identifier-list \fB:\fR type-denoter .
  208. variable-declaration-part : [ \fBvar\fR variable-declaration \fB;\fR { variable-declaration \fB;\fR } ] .
  209. variable-identifier : identifier .
  210. variable-parameter-specification : \fBvar\fR identifier-list \fB:\fR type-identifier .
  211. variant : case-constant-list \fB:\fR \fB(\fR field-list \fB)\fR .
  212. variant-part : \fBcase\fR variant-selector \fBof\fR variant { \fB;\fR variant } .
  213. variant-selector : [ tag-field \fB:\fR ] tag-type .
  214. while-statement : \fBwhile\fR Boolean-expression \fBdo\fR statement .
  215. with-statement : \fBwith\fR record-variable-list \fBdo\fR statement .
  216. write-parameter : expression [ \fB:\fR expression [ \fB:\fR expression ] ] .
  217. write-parameter-list : \fB(\fR [ file-variable \fB,\fR ] write-parameter { \fB,\fR write-parameter } \fB)\fR .
  218. writeln-parameter-list : [ \fB(\fR ( file-variable | write-parameter ) { \fB,\fR write-parameter } \fB)\fR ] .
  219. .fi
  220. .vs
  221. .bp
  222. .po