267 lines
2.9 KiB
Plaintext
267 lines
2.9 KiB
Plaintext
/*
|
|
* (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
|
|
]*
|
|
]?
|
|
')'
|
|
[ ':' qualtype
|
|
]?
|
|
]?
|
|
;
|
|
|
|
block :
|
|
[ %persistent
|
|
declaration
|
|
]*
|
|
[ %default
|
|
BEGIN
|
|
StatementSequence
|
|
|
|
|
]
|
|
END
|
|
;
|
|
|
|
declaration :
|
|
CONST [ ConstantDeclaration ';' ]*
|
|
|
|
|
TYPE [ TypeDeclaration ';' ]*
|
|
|
|
|
VAR [ VariableDeclaration ';' ]*
|
|
|
|
|
ProcedureHeading ';'
|
|
block
|
|
IDENT
|
|
';'
|
|
|
|
|
ModuleDeclaration ';'
|
|
;
|
|
|
|
FPSection :
|
|
var IdentList ':' FormalType
|
|
;
|
|
|
|
FormalType :
|
|
ARRAY OF qualtype
|
|
|
|
|
qualtype
|
|
;
|
|
|
|
TypeDeclaration :
|
|
IDENT
|
|
'=' type
|
|
;
|
|
|
|
type :
|
|
%default SimpleType
|
|
|
|
|
ArrayType
|
|
|
|
|
RecordType
|
|
|
|
|
SetType
|
|
|
|
|
PointerType
|
|
|
|
|
ProcedureType
|
|
;
|
|
|
|
SimpleType :
|
|
qualtype
|
|
[
|
|
/* nothing */
|
|
|
|
|
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".
|
|
*/
|
|
'[' ConstExpression
|
|
UPTO ConstExpression
|
|
']'
|
|
;
|
|
|
|
ArrayType :
|
|
ARRAY SimpleType
|
|
[
|
|
',' SimpleType
|
|
]* OF type
|
|
;
|
|
|
|
RecordType :
|
|
RECORD
|
|
FieldListSequence
|
|
END
|
|
;
|
|
|
|
FieldListSequence :
|
|
FieldList
|
|
[
|
|
';' FieldList
|
|
]*
|
|
;
|
|
|
|
FieldList :
|
|
[
|
|
IdentList ':' type
|
|
|
|
|
CASE
|
|
/* Also accept old fashioned Modula-2 syntax, but give a warning.
|
|
Sorry for the complicated code.
|
|
*/
|
|
[ qualident
|
|
[ ':' qualtype
|
|
/* This is correct, in both kinds of Modula-2, if
|
|
the first qualident is a single identifier.
|
|
*/
|
|
| /* Old fashioned! the first qualident now represents
|
|
the type
|
|
*/
|
|
]
|
|
| ':' qualtype
|
|
/* Aha, third edition. Well done! */
|
|
]
|
|
OF variant
|
|
[
|
|
'|' variant
|
|
]*
|
|
[ ELSE FieldListSequence
|
|
]?
|
|
END
|
|
]?
|
|
;
|
|
|
|
variant :
|
|
[
|
|
CaseLabelList
|
|
':' FieldListSequence
|
|
]?
|
|
/* Changed rule in new modula-2 */
|
|
;
|
|
|
|
CaseLabelList :
|
|
CaseLabels
|
|
[
|
|
',' CaseLabels
|
|
]*
|
|
;
|
|
|
|
CaseLabels :
|
|
ConstExpression
|
|
[
|
|
UPTO
|
|
ConstExpression
|
|
]?
|
|
;
|
|
|
|
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
|
|
|
|
|
]
|
|
;
|
|
|
|
FormalTypeList :
|
|
'('
|
|
[
|
|
VarFormalType
|
|
[
|
|
',' VarFormalType
|
|
]*
|
|
]?
|
|
')'
|
|
[ ':' qualtype
|
|
|
|
|
]
|
|
;
|
|
|
|
VarFormalType :
|
|
var
|
|
FormalType
|
|
;
|
|
|
|
var :
|
|
[
|
|
VAR
|
|
|
|
|
/* empty */
|
|
]
|
|
;
|
|
|
|
ConstantDeclaration :
|
|
IDENT
|
|
'=' ConstExpression
|
|
;
|
|
|
|
VariableDeclaration :
|
|
IdentAddr
|
|
[ %persistent
|
|
',' IdentAddr
|
|
]*
|
|
':' type
|
|
;
|
|
|
|
IdentAddr :
|
|
IDENT
|
|
[ '['
|
|
ConstExpression
|
|
']'
|
|
]?
|
|
;
|