2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* O V E R A L L S T R U C T U R E */
10 /* stripped down version of the one in the Modula-2 compiler */
12 /* $Id: program.g,v 1.5 1994/06/24 12:45:31 ceriel Exp $ */
15 The grammar as given by Wirth is already almost LL(1); the
16 main problem is that the full form of a qualified designator
18 [ module_ident '.' ]* IDENT [ '.' field_ident ]*
19 which is quite confusing to an LL(1) parser. Rather than
20 resorting to context-sensitive techniques, I have decided
23 on the grounds that it is quite natural to consider the first
24 IDENT to be the name of the object and regard the others as
42 p = (struct lnk *)Malloc(50*sizeof(struct lnk));
53 %start CompUnit, CompilationUnit;
54 %start DefModule, DefinitionModule;
57 MODULE IDENT priority ';' import((struct lnk **) 0)* export?
63 '[' ConstExpression ']'
79 import(register struct lnk **p;)
81 register struct idf *fromid = 0;
85 { if (p) while (*p) p = &((*p)->lnk_next); }
87 identifier(&id) { fromid = id;
89 if (AddToList(fromid->id_text, ".def")) {
91 (*p)->lnk_imp = fromid;
97 identifier(&id) { if (! fromid && p) {
98 if (AddToList(id->id_text, ".def")) {
101 p = &((*p)->lnk_next);
107 { if (! fromid && p) {
108 if (AddToList(id->id_text, ".def")) {
111 p = &((*p)->lnk_next);
118 When parsing a global module, this is the place where we must
119 read already compiled definition modules.
120 If the FROM clause is present, the identifier in it is a module
121 name, otherwise the names in the import list are module names.
128 extern char *strrindex();
132 MODULE identifier(&id)
133 { if (! ForeignFlag) {
134 AddToList(id->id_text, ".mod");
137 id->id_type = DEFINITION;
139 else if (id->id_type != IMPLEMENTATION) {
140 error("multiple declaration for module %s",
144 id->id_dir = WorkingDir;
146 else if (strcmp(id->id_dir, WorkingDir)) {
147 Gerror("definition and implementation of module %s reside in different directories", id->id_text);
149 id->id_def = strrindex(FileName, '/');
150 if (! id->id_def) id->id_def = FileName;
152 CurrentArg->a_idf = id;
155 import(&(id->id_defimports))*
161 definition* END IDENT
166 CONST [ %persistent ConstantDeclaration ';' ]*
174 Here, the exported type has a hidden implementation.
175 The export is said to be opaque.
176 It is restricted to pointer types.
182 VAR [ %persistent VariableDeclaration ';' ]*
194 identifier(&id) { if (! id->id_type) {
197 else if (id->id_type != DEFINITION ||
198 state != IMPLEMENTATION) {
199 error("multiple declaration for module %s",
203 id->id_dir = WorkingDir;
205 else if (strcmp(id->id_dir, WorkingDir)) {
206 Gerror("definition and implementation of module %s reside in different directories", id->id_text);
208 CurrentArg->a_idf = id;
211 ';' import(&(id->id_modimports))*
218 { fatal("Definition module in .mod file"); }
221 IMPLEMENTATION { state = IMPLEMENTATION; }
223 /* empty */ { state = PROGRAM; }
232 identifier(struct idf **id;):
234 { extern char idfbuf[];
235 *id = str2idf(idfbuf, 1);