1986-03-26 15:11:02 +00:00
|
|
|
/* D E C L A R A T I O N S */
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
{
|
1986-03-20 14:52:03 +00:00
|
|
|
static char *RcsId = "$Header$";
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
#include <em_arith.h>
|
|
|
|
#include <em_label.h>
|
1986-03-26 22:46:48 +00:00
|
|
|
#include <assert.h>
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "idf.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "LLlex.h"
|
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "scope.h"
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
ProcedureDeclaration
|
|
|
|
{
|
1986-03-26 22:46:48 +00:00
|
|
|
struct def *df;
|
1986-03-26 15:11:02 +00:00
|
|
|
} :
|
1986-03-26 22:46:48 +00:00
|
|
|
ProcedureHeading(&df, D_PROCEDURE)
|
1986-03-26 15:11:02 +00:00
|
|
|
';' block IDENT
|
|
|
|
{ match_id(dot.TOK_IDF, df->df_idf);
|
|
|
|
close_scope();
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
ProcedureHeading(struct def **pdf; int type;)
|
1986-03-26 15:11:02 +00:00
|
|
|
{
|
|
|
|
} :
|
|
|
|
PROCEDURE IDENT
|
1986-03-26 22:46:48 +00:00
|
|
|
{ assert(type == D_PROCEDURE || type == D_PROCHEAD);
|
|
|
|
*pdf = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD);
|
|
|
|
if (type == D_PROCEDURE) {
|
|
|
|
open_scope(OPENSCOPE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FormalParameters(type, &((*pdf)->df_type))?
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
block:
|
|
|
|
declaration* [ BEGIN StatementSequence ]? END
|
|
|
|
;
|
|
|
|
|
|
|
|
declaration:
|
|
|
|
CONST [ ConstantDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
TYPE [ TypeDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
VAR [ VariableDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
ProcedureDeclaration ';'
|
|
|
|
|
|
|
|
|
ModuleDeclaration ';'
|
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
FormalParameters(int doparams; struct type **tp;) :
|
|
|
|
'(' [ FPSection(doparams) [ ';' FPSection(doparams)]* ]? ')'
|
1986-03-26 15:11:02 +00:00
|
|
|
[ ':' qualident
|
|
|
|
]?
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
FPSection(int doparams;)
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
|
|
|
struct id_list *FPList;
|
1986-03-26 15:11:02 +00:00
|
|
|
int VARflag = 0;
|
1986-03-20 14:52:03 +00:00
|
|
|
} :
|
1986-03-26 15:11:02 +00:00
|
|
|
[
|
|
|
|
VAR { VARflag = 1; }
|
|
|
|
]?
|
|
|
|
IdentList(&FPList) ':' FormalType
|
|
|
|
{
|
1986-03-26 22:46:48 +00:00
|
|
|
if (doparams) {
|
|
|
|
EnterIdList(FPList,
|
|
|
|
D_VARIABLE,
|
|
|
|
VARflag,
|
|
|
|
(struct type *) 0 /* ???? */
|
|
|
|
);
|
|
|
|
}
|
1986-03-26 15:11:02 +00:00
|
|
|
FreeIdList(FPList);
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
FormalType:
|
|
|
|
[ ARRAY OF ]? qualident
|
|
|
|
;
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
TypeDeclaration
|
|
|
|
{
|
1986-03-26 22:46:48 +00:00
|
|
|
struct def *df;
|
|
|
|
struct idf *id;
|
1986-03-26 15:11:02 +00:00
|
|
|
}:
|
1986-03-26 22:46:48 +00:00
|
|
|
IDENT { id = dot.TOK_IDF; }
|
|
|
|
'=' type { df = define(id, CurrentScope, D_TYPE);
|
|
|
|
/* ???? */
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
type:
|
|
|
|
SimpleType
|
|
|
|
|
|
|
|
|
ArrayType
|
|
|
|
|
|
|
|
|
RecordType
|
|
|
|
|
|
|
|
|
SetType
|
|
|
|
|
|
|
|
|
PointerType
|
|
|
|
|
|
|
|
|
ProcedureType
|
|
|
|
;
|
|
|
|
|
|
|
|
SimpleType:
|
|
|
|
qualident
|
|
|
|
[
|
|
|
|
|
|
|
|
|
|
|
|
|
SubrangeType
|
|
|
|
/*
|
|
|
|
* The subrange type is given a base type by the
|
|
|
|
* qualident (this is new modula-2).
|
|
|
|
*/
|
|
|
|
]
|
|
|
|
|
|
|
|
|
enumeration
|
|
|
|
|
|
|
|
|
SubrangeType
|
|
|
|
;
|
|
|
|
|
|
|
|
enumeration
|
|
|
|
{
|
|
|
|
struct id_list *EnumList;
|
|
|
|
} :
|
|
|
|
'(' IdentList(&EnumList) ')'
|
1986-03-26 22:46:48 +00:00
|
|
|
{
|
|
|
|
EnterIdList(EnumList,
|
|
|
|
D_ENUM,
|
|
|
|
0,
|
|
|
|
(struct type *) 0 /* ???? */
|
|
|
|
);
|
|
|
|
FreeIdList(EnumList);
|
|
|
|
}
|
|
|
|
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
IdentList(struct id_list **p;)
|
|
|
|
{
|
|
|
|
register struct id_list *q = new_id_list();
|
|
|
|
} :
|
1986-03-26 22:46:48 +00:00
|
|
|
IDENT { q->id_ptr = dot.TOK_IDF; *p = q;}
|
1986-03-20 14:52:03 +00:00
|
|
|
[
|
|
|
|
',' IDENT { q->next = new_id_list();
|
|
|
|
q = q->next;
|
|
|
|
q->id_ptr = dot.TOK_IDF;
|
|
|
|
}
|
|
|
|
]*
|
1986-03-26 22:46:48 +00:00
|
|
|
{ q->next = 0; }
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
struct id_list *FldList;
|
|
|
|
} :
|
|
|
|
[
|
|
|
|
IdentList(&FldList) ':' type
|
|
|
|
|
|
|
|
|
CASE IDENT? /* Changed rule in new modula-2 */
|
|
|
|
':' qualident
|
|
|
|
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
|
|
|
|
;
|
|
|
|
|
|
|
|
PointerType:
|
|
|
|
POINTER TO type
|
|
|
|
;
|
|
|
|
|
|
|
|
ProcedureType:
|
|
|
|
PROCEDURE FormalTypeList?
|
|
|
|
;
|
|
|
|
|
|
|
|
FormalTypeList:
|
|
|
|
'(' [ VAR? FormalType [ ',' VAR? FormalType ]* ]? ')'
|
|
|
|
[ ':' qualident ]?
|
|
|
|
;
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
ConstantDeclaration
|
|
|
|
{
|
1986-03-26 22:46:48 +00:00
|
|
|
struct def *df;
|
|
|
|
struct idf *id;
|
1986-03-26 15:11:02 +00:00
|
|
|
}:
|
1986-03-26 22:46:48 +00:00
|
|
|
IDENT { id = dot.TOK_IDF; }
|
|
|
|
'=' ConstExpression { df = define(id, CurrentScope, D_CONST);
|
|
|
|
/* ???? */
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
VariableDeclaration
|
|
|
|
{
|
|
|
|
struct id_list *VarList;
|
|
|
|
} :
|
1986-03-24 17:29:57 +00:00
|
|
|
IdentList(&VarList)
|
|
|
|
[
|
|
|
|
ConstExpression
|
|
|
|
]?
|
|
|
|
':' type
|
1986-03-26 22:46:48 +00:00
|
|
|
{ EnterIdList(VarList,
|
|
|
|
D_VARIABLE,
|
|
|
|
0,
|
|
|
|
(struct type *) 0 /* ???? */
|
|
|
|
);
|
|
|
|
FreeIdList(VarList);
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|