1986-03-26 15:11:02 +00:00
|
|
|
/* O V E R A L L S T R U C T U R E */
|
|
|
|
|
|
|
|
{
|
|
|
|
static char *RcsId = "$Header$";
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
#include <alloc.h>
|
|
|
|
#include <em_arith.h>
|
1986-03-26 22:46:48 +00:00
|
|
|
#include <em_label.h>
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "main.h"
|
1986-04-08 18:15:46 +00:00
|
|
|
#include "idf.h"
|
1986-03-26 15:11:02 +00:00
|
|
|
#include "LLlex.h"
|
1986-03-26 17:53:13 +00:00
|
|
|
#include "scope.h"
|
1986-03-26 22:46:48 +00:00
|
|
|
#include "def.h"
|
|
|
|
#include "type.h"
|
1986-04-06 17:42:56 +00:00
|
|
|
#include "node.h"
|
1986-04-03 00:44:39 +00:00
|
|
|
#include "debug.h"
|
1986-04-03 17:41:26 +00:00
|
|
|
|
1986-04-12 02:21:24 +00:00
|
|
|
static int DEFofIMPL = 0; /* Flag indicating that we are currently
|
|
|
|
parsing the definition module of the
|
|
|
|
implementation module currently being
|
|
|
|
compiled
|
|
|
|
*/
|
1986-03-26 15:11:02 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
/*
|
|
|
|
The grammar as given by Wirth is already almost LL(1); the
|
|
|
|
main problem is that the full form of a qualified designator
|
|
|
|
may be:
|
|
|
|
[ module_ident '.' ]* IDENT [ '.' field_ident ]*
|
|
|
|
which is quite confusing to an LL(1) parser. Rather than
|
|
|
|
resorting to context-sensitive techniques, I have decided
|
|
|
|
to render this as:
|
|
|
|
IDENT [ '.' IDENT ]*
|
|
|
|
on the grounds that it is quite natural to consider the first
|
|
|
|
IDENT to be the name of the object and regard the others as
|
|
|
|
field identifiers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
%lexical LLlex;
|
|
|
|
|
|
|
|
%start CompUnit, CompilationUnit;
|
1986-04-03 00:44:39 +00:00
|
|
|
%start DefModule, DefinitionModule;
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-29 01:04:49 +00:00
|
|
|
ModuleDeclaration
|
|
|
|
{
|
|
|
|
struct idf *id;
|
1986-04-02 17:34:21 +00:00
|
|
|
struct def *df;
|
1986-03-29 01:04:49 +00:00
|
|
|
} :
|
1986-04-02 17:34:21 +00:00
|
|
|
MODULE IDENT {
|
1986-03-29 01:04:49 +00:00
|
|
|
id = dot.TOK_IDF;
|
1986-04-02 17:34:21 +00:00
|
|
|
df = define(id, CurrentScope, D_MODULE);
|
1986-04-12 02:21:24 +00:00
|
|
|
if (!df->mod_scope) {
|
1986-04-15 17:51:53 +00:00
|
|
|
open_scope(CLOSEDSCOPE);
|
|
|
|
df->mod_scope = CurrentScope;
|
1986-04-12 02:21:24 +00:00
|
|
|
}
|
1986-04-15 17:51:53 +00:00
|
|
|
else CurrentScope = df->mod_scope;
|
1986-04-09 18:14:49 +00:00
|
|
|
df->df_type =
|
1986-04-10 01:08:49 +00:00
|
|
|
standard_type(T_RECORD, 0, (arith) 0);
|
1986-04-09 18:14:49 +00:00
|
|
|
df->df_type->rec_scope = df->mod_scope;
|
1986-03-29 01:04:49 +00:00
|
|
|
}
|
|
|
|
priority? ';'
|
|
|
|
import(1)*
|
1986-04-03 00:44:39 +00:00
|
|
|
export(0)?
|
1986-03-29 01:04:49 +00:00
|
|
|
block
|
1986-04-12 02:21:24 +00:00
|
|
|
IDENT { close_scope(SC_CHKFORW|SC_CHKPROC);
|
1986-03-29 01:04:49 +00:00
|
|
|
match_id(id, dot.TOK_IDF);
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-06 17:42:56 +00:00
|
|
|
priority
|
|
|
|
{
|
|
|
|
struct node *nd;
|
|
|
|
}:
|
|
|
|
'[' ConstExpression(&nd) ']'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-03 00:44:39 +00:00
|
|
|
export(int def;)
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-04-06 17:42:56 +00:00
|
|
|
struct node *ExportList;
|
1986-03-26 22:46:48 +00:00
|
|
|
int QUALflag = 0;
|
1986-03-20 14:52:03 +00:00
|
|
|
} :
|
1986-03-26 22:46:48 +00:00
|
|
|
EXPORT
|
|
|
|
[
|
|
|
|
QUALIFIED { QUALflag = 1; }
|
|
|
|
]?
|
|
|
|
IdentList(&ExportList) ';'
|
1986-03-26 15:11:02 +00:00
|
|
|
{
|
1986-04-12 02:21:24 +00:00
|
|
|
if (!def) {
|
|
|
|
Export(ExportList, QUALflag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
warning("export list in definition module ignored");
|
|
|
|
FreeNode(ExportList);
|
|
|
|
}
|
1986-03-26 15:11:02 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
import(int local;)
|
1986-03-20 14:52:03 +00:00
|
|
|
{
|
1986-04-06 17:42:56 +00:00
|
|
|
struct node *ImportList;
|
|
|
|
struct node *id = 0;
|
1986-03-20 14:52:03 +00:00
|
|
|
} :
|
|
|
|
[ FROM
|
1986-04-06 17:42:56 +00:00
|
|
|
IDENT { id = MkNode(Value, NULLNODE, NULLNODE, &dot); }
|
1986-03-20 14:52:03 +00:00
|
|
|
]?
|
|
|
|
IMPORT IdentList(&ImportList) ';'
|
|
|
|
/*
|
|
|
|
When parsing a global module, this is the place where we must
|
|
|
|
read already compiled definition modules.
|
|
|
|
If the FROM clause is present, the identifier in it is a module
|
|
|
|
name, otherwise the names in the import list are module names.
|
|
|
|
*/
|
1986-03-26 15:11:02 +00:00
|
|
|
{
|
1986-03-29 01:04:49 +00:00
|
|
|
Import(ImportList, id, local);
|
1986-03-26 15:11:02 +00:00
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
DefinitionModule
|
|
|
|
{
|
1986-04-03 00:44:39 +00:00
|
|
|
register struct def *df;
|
1986-03-29 01:04:49 +00:00
|
|
|
struct idf *id;
|
1986-03-26 22:46:48 +00:00
|
|
|
} :
|
1986-04-03 17:41:26 +00:00
|
|
|
DEFINITION
|
1986-03-29 01:04:49 +00:00
|
|
|
MODULE IDENT { id = dot.TOK_IDF;
|
1986-04-03 00:44:39 +00:00
|
|
|
df = define(id, GlobalScope, D_MODULE);
|
1986-04-15 17:51:53 +00:00
|
|
|
if (!SYSTEMModule) open_scope(CLOSEDSCOPE);
|
|
|
|
df->mod_scope = CurrentScope;
|
1986-04-10 01:08:49 +00:00
|
|
|
df->df_type = standard_type(T_RECORD, 0, (arith) 0);
|
1986-04-09 18:14:49 +00:00
|
|
|
df->df_type->rec_scope = df->mod_scope;
|
1986-04-03 17:41:26 +00:00
|
|
|
DefinitionModule = 1;
|
1986-04-07 17:40:38 +00:00
|
|
|
DO_DEBUG(1, debug("Definition module \"%s\"", id->id_text));
|
1986-03-26 22:46:48 +00:00
|
|
|
}
|
1986-03-26 15:11:02 +00:00
|
|
|
';'
|
|
|
|
import(0)*
|
1986-04-03 00:44:39 +00:00
|
|
|
export(1)?
|
|
|
|
/* New Modula-2 does not have export lists in definition modules.
|
1986-04-03 17:41:26 +00:00
|
|
|
For the time being, we ignore export lists here, and a
|
|
|
|
warning is issued.
|
1986-03-20 14:52:03 +00:00
|
|
|
*/
|
1986-04-03 17:41:26 +00:00
|
|
|
definition* END IDENT
|
1986-04-03 00:44:39 +00:00
|
|
|
{
|
1986-04-12 02:21:24 +00:00
|
|
|
if (DEFofIMPL) {
|
1986-04-03 17:41:26 +00:00
|
|
|
/* Just read the definition module of the
|
|
|
|
implementation module being compiled
|
|
|
|
*/
|
|
|
|
RemImports(&(CurrentScope->sc_def));
|
|
|
|
}
|
1986-04-03 00:44:39 +00:00
|
|
|
df = CurrentScope->sc_def;
|
|
|
|
while (df) {
|
|
|
|
/* Make all definitions "QUALIFIED EXPORT" */
|
|
|
|
df->df_flags |= D_QEXPORTED;
|
|
|
|
df = df->df_nextinscope;
|
|
|
|
}
|
1986-04-12 02:21:24 +00:00
|
|
|
if (!SYSTEMModule) close_scope(SC_CHKFORW);
|
1986-04-03 17:41:26 +00:00
|
|
|
DefinitionModule = 0;
|
1986-03-29 01:04:49 +00:00
|
|
|
match_id(id, dot.TOK_IDF);
|
|
|
|
}
|
1986-04-03 17:41:26 +00:00
|
|
|
'.'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
definition
|
|
|
|
{
|
|
|
|
struct def *df;
|
|
|
|
} :
|
1986-03-20 14:52:03 +00:00
|
|
|
CONST [ ConstantDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
TYPE
|
1986-04-03 00:44:39 +00:00
|
|
|
[ IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); }
|
1986-04-08 18:15:46 +00:00
|
|
|
[ '=' type(&(df->df_type))
|
1986-03-20 14:52:03 +00:00
|
|
|
| /* empty */
|
|
|
|
/*
|
|
|
|
Here, the exported type has a hidden implementation.
|
|
|
|
The export is said to be opaque.
|
|
|
|
It is restricted to pointer types.
|
|
|
|
*/
|
1986-04-15 17:51:53 +00:00
|
|
|
{ df->df_kind = D_HIDDEN;
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
]
|
|
|
|
';'
|
|
|
|
]*
|
|
|
|
|
|
|
|
|
VAR [ VariableDeclaration ';' ]*
|
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
ProcedureHeading(&df, D_PROCHEAD) ';'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-03 17:41:26 +00:00
|
|
|
ProgramModule(int state;)
|
1986-04-03 00:44:39 +00:00
|
|
|
{
|
1986-03-29 01:04:49 +00:00
|
|
|
struct idf *id;
|
1986-04-03 00:44:39 +00:00
|
|
|
struct def *df, *GetDefinitionModule();
|
1986-04-15 17:51:53 +00:00
|
|
|
struct scope *scope = 0;
|
1986-03-29 01:04:49 +00:00
|
|
|
} :
|
1986-04-03 17:41:26 +00:00
|
|
|
MODULE
|
1986-04-03 00:44:39 +00:00
|
|
|
IDENT {
|
1986-03-29 01:04:49 +00:00
|
|
|
id = dot.TOK_IDF;
|
1986-04-03 00:44:39 +00:00
|
|
|
if (state == IMPLEMENTATION) {
|
1986-04-15 17:51:53 +00:00
|
|
|
DEFofIMPL = 1;
|
|
|
|
df = GetDefinitionModule(id);
|
|
|
|
CurrentScope = df->mod_scope;
|
|
|
|
DEFofIMPL = 0;
|
|
|
|
DefinitionModule = 0;
|
1986-04-03 00:44:39 +00:00
|
|
|
}
|
1986-04-15 17:51:53 +00:00
|
|
|
else open_scope(CLOSEDSCOPE);
|
1986-03-29 01:04:49 +00:00
|
|
|
}
|
|
|
|
priority?
|
|
|
|
';' import(0)*
|
|
|
|
block IDENT
|
1986-04-12 02:21:24 +00:00
|
|
|
{ close_scope(SC_CHKFORW|SC_CHKPROC);
|
1986-03-29 01:04:49 +00:00
|
|
|
match_id(id, dot.TOK_IDF);
|
1986-03-26 17:53:13 +00:00
|
|
|
}
|
|
|
|
'.'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-04-03 17:41:26 +00:00
|
|
|
Module
|
|
|
|
{
|
|
|
|
int state = PROGRAM;
|
|
|
|
} :
|
1986-03-20 14:52:03 +00:00
|
|
|
DefinitionModule
|
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
[
|
|
|
|
IMPLEMENTATION { state = IMPLEMENTATION; }
|
|
|
|
]?
|
1986-04-03 17:41:26 +00:00
|
|
|
ProgramModule(state)
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
CompilationUnit:
|
|
|
|
Module
|
|
|
|
;
|