1987-09-24 13:01:27 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* D E C L A R A T I O N S */
|
|
|
|
|
|
|
|
/* stripped down version of the one in the Modula-2 compiler */
|
|
|
|
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
ProcedureHeading :
|
|
|
|
PROCEDURE IDENT
|
|
|
|
[
|
|
|
|
'('
|
|
|
|
[
|
|
|
|
FPSection
|
|
|
|
[
|
|
|
|
';' FPSection
|
|
|
|
]*
|
1988-02-17 17:21:51 +00:00
|
|
|
|
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
')'
|
1988-02-17 17:21:51 +00:00
|
|
|
[
|
|
|
|
':' qualtype
|
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
block :
|
1988-02-17 17:21:51 +00:00
|
|
|
[ %persistent
|
1987-09-24 13:01:27 +00:00
|
|
|
declaration
|
|
|
|
]*
|
1988-02-17 17:21:51 +00:00
|
|
|
[ %default
|
|
|
|
BEGIN StatementSequence
|
1987-09-24 13:01:27 +00:00
|
|
|
|
|
1988-02-17 17:21:51 +00:00
|
|
|
/* empty */
|
1987-09-24 13:01:27 +00:00
|
|
|
]
|
|
|
|
END
|
|
|
|
;
|
|
|
|
|
|
|
|
declaration :
|
|
|
|
CONST [ ConstantDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
TYPE [ TypeDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
VAR [ VariableDeclaration ';' ]*
|
|
|
|
|
|
1988-02-17 17:21:51 +00:00
|
|
|
ProcedureHeading ';' block IDENT ';'
|
1987-09-24 13:01:27 +00:00
|
|
|
|
|
|
|
|
ModuleDeclaration ';'
|
|
|
|
;
|
|
|
|
|
|
|
|
FPSection :
|
|
|
|
var IdentList ':' FormalType
|
|
|
|
;
|
|
|
|
|
|
|
|
FormalType :
|
|
|
|
ARRAY OF qualtype
|
|
|
|
|
|
|
|
|
qualtype
|
|
|
|
;
|
|
|
|
|
|
|
|
TypeDeclaration :
|
1988-02-17 17:21:51 +00:00
|
|
|
IDENT '=' type
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
type :
|
1988-02-17 17:21:51 +00:00
|
|
|
%default
|
|
|
|
SimpleType
|
1987-09-24 13:01:27 +00:00
|
|
|
|
|
|
|
|
ArrayType
|
|
|
|
|
|
|
|
|
RecordType
|
|
|
|
|
|
|
|
|
SetType
|
|
|
|
|
|
|
|
|
PointerType
|
|
|
|
|
|
|
|
|
ProcedureType
|
|
|
|
;
|
|
|
|
|
|
|
|
SimpleType :
|
|
|
|
qualtype
|
|
|
|
[
|
1988-02-17 17:21:51 +00:00
|
|
|
/* empty */
|
1987-09-24 13:01:27 +00:00
|
|
|
|
|
|
|
|
SubrangeType
|
|
|
|
/* The subrange type is given a base type by the
|
|
|
|
qualident (this is new modula-2).
|
|
|
|
*/
|
|
|
|
]
|
|
|
|
|
|
|
|
|
enumeration
|
|
|
|
|
|
|
|
|
SubrangeType
|
|
|
|
;
|
|
|
|
|
|
|
|
enumeration :
|
|
|
|
'(' IdentList ')'
|
|
|
|
;
|
|
|
|
|
|
|
|
IdentList :
|
|
|
|
IDENT
|
|
|
|
[ %persistent
|
|
|
|
',' IDENT
|
|
|
|
]*
|
|
|
|
;
|
|
|
|
|
|
|
|
SubrangeType :
|
|
|
|
/*
|
|
|
|
This is not exactly the rule in the new report, but see
|
|
|
|
the rule for "SimpleType".
|
|
|
|
*/
|
1988-02-17 17:21:51 +00:00
|
|
|
'[' ConstExpression UPTO ConstExpression ']'
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ArrayType :
|
|
|
|
ARRAY SimpleType
|
|
|
|
[
|
|
|
|
',' SimpleType
|
1988-02-17 17:21:51 +00:00
|
|
|
]*
|
|
|
|
OF type
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
RecordType :
|
1988-02-17 17:21:51 +00:00
|
|
|
RECORD FieldListSequence END
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
FieldListSequence :
|
|
|
|
FieldList
|
|
|
|
[
|
|
|
|
';' FieldList
|
|
|
|
]*
|
|
|
|
;
|
|
|
|
|
|
|
|
FieldList :
|
|
|
|
IdentList ':' type
|
|
|
|
|
|
|
|
|
CASE
|
|
|
|
/* Also accept old fashioned Modula-2 syntax, but give a warning.
|
|
|
|
Sorry for the complicated code.
|
|
|
|
*/
|
1988-02-17 17:21:51 +00:00
|
|
|
[
|
|
|
|
qualident
|
|
|
|
[
|
|
|
|
':' qualtype
|
1987-09-24 13:01:27 +00:00
|
|
|
/* This is correct, in both kinds of Modula-2, if
|
|
|
|
the first qualident is a single identifier.
|
|
|
|
*/
|
1988-02-17 17:21:51 +00:00
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
/* Old fashioned! the first qualident now represents
|
1987-09-24 13:01:27 +00:00
|
|
|
the type
|
|
|
|
*/
|
1988-02-17 17:21:51 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
':' qualtype
|
|
|
|
/* Aha, third edition. Well done! */
|
1987-09-24 13:01:27 +00:00
|
|
|
]
|
|
|
|
OF variant
|
|
|
|
[
|
1988-02-17 17:21:51 +00:00
|
|
|
'|' variant
|
1987-09-24 13:01:27 +00:00
|
|
|
]*
|
1988-02-17 17:21:51 +00:00
|
|
|
[
|
|
|
|
ELSE FieldListSequence
|
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
END
|
1988-02-17 17:21:51 +00:00
|
|
|
|
|
|
|
|
/* empty */
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
variant :
|
|
|
|
[
|
1988-02-17 17:21:51 +00:00
|
|
|
CaseLabelList ':' FieldListSequence
|
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
/* Changed rule in new modula-2 */
|
|
|
|
;
|
|
|
|
|
|
|
|
CaseLabelList :
|
|
|
|
CaseLabels
|
|
|
|
[
|
|
|
|
',' CaseLabels
|
|
|
|
]*
|
|
|
|
;
|
|
|
|
|
|
|
|
CaseLabels :
|
|
|
|
ConstExpression
|
|
|
|
[
|
1988-02-17 17:21:51 +00:00
|
|
|
UPTO ConstExpression
|
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
SetType :
|
|
|
|
SET OF SimpleType
|
|
|
|
;
|
|
|
|
|
|
|
|
/* In a pointer type definition, the type pointed at does not
|
|
|
|
have to be declared yet, so be careful about identifying
|
|
|
|
type-identifiers
|
|
|
|
*/
|
|
|
|
PointerType :
|
|
|
|
POINTER TO type
|
|
|
|
;
|
|
|
|
|
|
|
|
qualtype :
|
|
|
|
qualident
|
|
|
|
;
|
|
|
|
|
|
|
|
ProcedureType :
|
|
|
|
PROCEDURE
|
|
|
|
[
|
|
|
|
FormalTypeList
|
|
|
|
|
|
1988-02-17 17:21:51 +00:00
|
|
|
/* empty */
|
1987-09-24 13:01:27 +00:00
|
|
|
]
|
|
|
|
;
|
|
|
|
|
|
|
|
FormalTypeList :
|
|
|
|
'('
|
|
|
|
[
|
|
|
|
VarFormalType
|
|
|
|
[
|
|
|
|
',' VarFormalType
|
|
|
|
]*
|
1988-02-17 17:21:51 +00:00
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
')'
|
1988-02-17 17:21:51 +00:00
|
|
|
[
|
|
|
|
':' qualtype
|
1987-09-24 13:01:27 +00:00
|
|
|
|
|
1988-02-17 17:21:51 +00:00
|
|
|
/* empty */
|
1987-09-24 13:01:27 +00:00
|
|
|
]
|
|
|
|
;
|
|
|
|
|
|
|
|
VarFormalType :
|
1988-02-17 17:21:51 +00:00
|
|
|
var FormalType
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
var :
|
1988-02-17 17:21:51 +00:00
|
|
|
VAR
|
|
|
|
|
|
|
|
|
/* empty */
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
ConstantDeclaration :
|
1988-02-17 17:21:51 +00:00
|
|
|
IDENT '=' ConstExpression
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
VariableDeclaration :
|
|
|
|
IdentAddr
|
|
|
|
[ %persistent
|
|
|
|
',' IdentAddr
|
|
|
|
]*
|
|
|
|
':' type
|
|
|
|
;
|
|
|
|
|
|
|
|
IdentAddr :
|
|
|
|
IDENT
|
1988-02-17 17:21:51 +00:00
|
|
|
[
|
|
|
|
'[' ConstExpression ']'
|
|
|
|
|
|
|
|
|
/* empty */
|
|
|
|
]
|
1987-09-24 13:01:27 +00:00
|
|
|
;
|