Contents |
Prev |
Next |
Index
Vocabulary and Representation
Modula-2 represents its terminal symbols in terms of characters using
the ASCII set. Symbols are identifiers, numbers, strings, operators, and
delimiters. Blanks and line breaks must not occur within symbols (except
for blanks in strings). They are are ignored unless they are essential to
separate two consecutive symbols. Upper-case and lower-case letters are
considered distinct because Modula-2 identifiers and keywords are
case-sensitive.
Here is how the terminal symbols are defined:
-
Identifiers
are sequences of letters and digits. The first character must not be a digit.
This compiler also accepts underscore ('_') characters in an identifier
sequence.
-
Numbers are unsigned
integer or real constants. The type of an integer constant is the minimal
type to which the constant value belongs (see
basic types). If the constant
is specified with the suffix H, the representation is hexadecimal; otherwise
it is decimal. If it is specified with the suffix C, it denotes a character
with the given octal ordinal number and is of type
CHAR. If the constant is specified
with the suffix B, it is taken as an octal number.
A real number always contains a decimal point. It may optionally be followed
by a scale factor. The letter E introduces the scale factor portion and means
"times ten to the power of". A real number is of
REAL type, unless a bigger scale
factor or mantissa requires it to be of type
LONGREAL.
number = integer | real
integer = digit {digit} |
digit {hex_digit} "H" |
digit {octal_digit} ("B"|"C")
real = digit {digit} "." {digit} [scale_factor]
scale_factor = "E" ["+"|"-"] digit {digit}
hex_digit = digit |"A"|"B"|"C"|"D"|"E"|"F"
digit = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"
octal_digit = "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"
Examples:
1991 |
CARDINAL or INTEGER |
1991 |
0DH |
SHORTCARD or SHORTINT |
13 |
12.3 |
REAL |
12.3 |
4.567E8 |
REAL |
456700000 |
-
Character
constants are denoted by the ordinal number of the character in
octal notation followed by the letter C.
character = digit {octal_digit} "C"
-
Strings are character
sequences enclosed in single (') or double (") quotation marks. Opening and
closing quotation marks must match and must not occur within the string.
The number of characters in the string is called its length. A one-character
string can be used whereever a character is allowed and vice versa.
string = '"' {char} '"' | "'" {char} "'"
Examples:
"Modula-2" "Don't worry" "x"
-
Operators and
delimiters are of special characters, character pairs,
or reserved words. The reserved words are of capital letters only and cannot
be used as identifiers. The symbols # and <> are synonyms, and so are
& and AND, as well as ~ and NOT. Some of the reserved words are only
available with the language extensions
switch or
directive and are shown in the
following table in red.
+ |
= |
AND |
FORWARD |
QUALIFIED |
- |
# |
ARRAY |
FROM |
RECORD |
* |
< |
BEGIN |
IF |
REPEAT |
/ |
> |
BY |
IMPLEMENTATION |
RETURN |
:= |
<> |
CASE |
IMPORT |
SET |
& |
<= |
CONST |
IN |
SHL |
. |
>= |
DEFINITION |
IS |
SHR |
, |
.. |
DIV |
LOOP |
THEN |
; |
: |
DO |
MOD |
TO |
( |
) |
ELSE |
MODULE |
TYPE |
[ |
] |
ELSIF |
NOT |
UNTIL |
{ |
} |
END |
OF |
VAR |
^ |
| |
EXIT |
OR |
WHILE |
~ |
|
EXPORT |
POINTER |
WITH |
|
|
FOR |
PROCEDURE |
XOR |
-
Comments
may be inserted between any two symbols in a program. They are (almost) arbitrary
character sequences opened by the bracket "(*" and closed by "*)". Comments
may be nested. They do not affect the meaning of a program.
This compiler recognizes certain comment-embedded
directives which give the compiler
some hints on how to perform its compilation.
Contents |
Prev |
Next |
Index
Canterbury Modula-2 for Java (Last documentation update
Feb 8, 2000)
Copyright © 1998 Mill Hill &
Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to
mhc@webcom.com