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 "idf.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "main.h"
|
|
|
|
#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-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-03-29 01:04:49 +00:00
|
|
|
ModuleDeclaration
|
|
|
|
{
|
|
|
|
struct idf *id;
|
|
|
|
} :
|
|
|
|
MODULE IDENT { open_scope(CLOSEDSCOPE, 0);
|
|
|
|
id = dot.TOK_IDF;
|
|
|
|
}
|
|
|
|
priority? ';'
|
|
|
|
import(1)*
|
|
|
|
export?
|
|
|
|
block
|
|
|
|
IDENT { close_scope();
|
|
|
|
match_id(id, dot.TOK_IDF);
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
priority:
|
|
|
|
'[' ConstExpression ']'
|
|
|
|
;
|
|
|
|
|
|
|
|
export
|
|
|
|
{
|
|
|
|
struct id_list *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-03-29 01:04:49 +00:00
|
|
|
Export(ExportList, QUALflag);
|
1986-03-26 15:11:02 +00:00
|
|
|
FreeIdList(ExportList);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
struct id_list *ImportList;
|
1986-03-26 15:11:02 +00:00
|
|
|
struct idf *id = 0;
|
1986-03-20 14:52:03 +00:00
|
|
|
} :
|
|
|
|
[ FROM
|
1986-03-26 15:11:02 +00:00
|
|
|
IDENT { id = dot.TOK_IDF; }
|
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
|
|
|
FreeIdList(ImportList);
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
DefinitionModule
|
|
|
|
{
|
|
|
|
struct def *df;
|
1986-03-29 01:04:49 +00:00
|
|
|
struct idf *id;
|
1986-03-26 22:46:48 +00:00
|
|
|
} :
|
1986-03-26 15:11:02 +00:00
|
|
|
DEFINITION { state = DEFINITION; }
|
1986-03-29 01:04:49 +00:00
|
|
|
MODULE IDENT { id = dot.TOK_IDF;
|
|
|
|
df = define(id, CurrentScope, D_MODULE);
|
1986-03-26 22:46:48 +00:00
|
|
|
open_scope(CLOSEDSCOPE, 0);
|
1986-03-29 01:04:49 +00:00
|
|
|
df->mod_scope = CurrentScope;
|
1986-03-26 22:46:48 +00:00
|
|
|
}
|
1986-03-26 15:11:02 +00:00
|
|
|
';'
|
|
|
|
import(0)*
|
|
|
|
/* export?
|
1986-03-20 14:52:03 +00:00
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
New Modula-2 does not have export lists in definition modules.
|
1986-03-20 14:52:03 +00:00
|
|
|
*/
|
|
|
|
definition* END IDENT '.'
|
1986-03-29 01:04:49 +00:00
|
|
|
{ close_scope();
|
|
|
|
match_id(id, dot.TOK_IDF);
|
|
|
|
}
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
definition
|
|
|
|
{
|
|
|
|
struct def *df;
|
1986-03-27 17:37:41 +00:00
|
|
|
struct type *tp;
|
1986-03-26 22:46:48 +00:00
|
|
|
} :
|
1986-03-20 14:52:03 +00:00
|
|
|
CONST [ ConstantDeclaration ';' ]*
|
|
|
|
|
|
|
|
|
TYPE
|
|
|
|
[ IDENT
|
1986-03-27 17:37:41 +00:00
|
|
|
[ '=' type(&tp)
|
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.
|
|
|
|
*/
|
|
|
|
]
|
|
|
|
';'
|
|
|
|
]*
|
|
|
|
|
|
|
|
|
VAR [ VariableDeclaration ';' ]*
|
|
|
|
|
|
1986-03-26 22:46:48 +00:00
|
|
|
ProcedureHeading(&df, D_PROCHEAD) ';'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
1986-03-29 01:04:49 +00:00
|
|
|
ProgramModule {
|
|
|
|
struct idf *id;
|
|
|
|
} :
|
1986-03-26 15:11:02 +00:00
|
|
|
MODULE { if (state != IMPLEMENTATION) state = PROGRAM; }
|
1986-03-26 17:53:13 +00:00
|
|
|
IDENT { if (state == IMPLEMENTATION) {
|
1986-03-26 22:46:48 +00:00
|
|
|
/* ????
|
|
|
|
Read definition module,
|
|
|
|
Look for current identifier,
|
|
|
|
and find out its scope number
|
|
|
|
*/
|
1986-03-26 17:53:13 +00:00
|
|
|
}
|
1986-03-29 01:04:49 +00:00
|
|
|
id = dot.TOK_IDF;
|
|
|
|
open_scope(CLOSEDSCOPE, 0);
|
|
|
|
}
|
|
|
|
priority?
|
|
|
|
';' import(0)*
|
|
|
|
block IDENT
|
|
|
|
{ close_scope();
|
|
|
|
match_id(id, dot.TOK_IDF);
|
1986-03-26 17:53:13 +00:00
|
|
|
}
|
|
|
|
'.'
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
Module:
|
|
|
|
DefinitionModule
|
|
|
|
|
|
1986-03-26 15:11:02 +00:00
|
|
|
[
|
|
|
|
IMPLEMENTATION { state = IMPLEMENTATION; }
|
|
|
|
]?
|
|
|
|
ProgramModule
|
1986-03-20 14:52:03 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
CompilationUnit:
|
|
|
|
Module
|
|
|
|
;
|