safety commit, newer version
This commit is contained in:
parent
4a91a6bf4b
commit
f2ff7661e4
9 changed files with 118 additions and 45 deletions
|
@ -196,7 +196,7 @@ again:
|
||||||
PushBack(ch);
|
PushBack(ch);
|
||||||
*tg++ = '\0';
|
*tg++ = '\0';
|
||||||
|
|
||||||
id = tk->TOK_IDF = str2idf(buf, 1);
|
tk->TOK_IDF = id = str2idf(buf, 1);
|
||||||
if (!id) fatal("Out of memory");
|
if (!id) fatal("Out of memory");
|
||||||
return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT;
|
return tk->tk_symb = id->id_reserved ? id->id_reserved : IDENT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,12 +75,12 @@ tokenname.o: Lpars.h idf.h tokenname.h
|
||||||
idf.o: idf.h
|
idf.o: idf.h
|
||||||
input.o: f_info.h input.h
|
input.o: f_info.h input.h
|
||||||
type.o: Lpars.h def.h def_sizes.h idf.h type.h
|
type.o: Lpars.h def.h def_sizes.h idf.h type.h
|
||||||
def.o: Lpars.h def.h idf.h main.h scope.h
|
def.o: Lpars.h debug.h def.h idf.h main.h scope.h
|
||||||
scope.o: debug.h scope.h
|
scope.o: debug.h scope.h
|
||||||
misc.o: LLlex.h f_info.h idf.h misc.h
|
misc.o: LLlex.h f_info.h idf.h misc.h
|
||||||
enter.o: def.h idf.h scope.h type.h
|
enter.o: def.h idf.h misc.h scope.h type.h
|
||||||
tokenfile.o: Lpars.h
|
tokenfile.o: Lpars.h
|
||||||
program.o: LLlex.h Lpars.h idf.h main.h misc.h scope.h
|
program.o: LLlex.h Lpars.h def.h idf.h main.h misc.h scope.h type.h
|
||||||
declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h
|
declar.o: LLlex.h Lpars.h def.h idf.h misc.h scope.h type.h
|
||||||
expression.o: Lpars.h
|
expression.o: Lpars.h
|
||||||
statement.o: Lpars.h
|
statement.o: Lpars.h
|
||||||
|
|
|
@ -5,6 +5,7 @@ static char *RcsId = "$Header$";
|
||||||
|
|
||||||
#include <em_arith.h>
|
#include <em_arith.h>
|
||||||
#include <em_label.h>
|
#include <em_label.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "idf.h"
|
#include "idf.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "LLlex.h"
|
#include "LLlex.h"
|
||||||
|
@ -15,29 +16,26 @@ static char *RcsId = "$Header$";
|
||||||
|
|
||||||
ProcedureDeclaration
|
ProcedureDeclaration
|
||||||
{
|
{
|
||||||
register struct def *df;
|
struct def *df;
|
||||||
} :
|
} :
|
||||||
/* ProcedureHeading(&df) */
|
ProcedureHeading(&df, D_PROCEDURE)
|
||||||
PROCEDURE IDENT
|
|
||||||
{ df = define(dot.TOK_IDF, CurrentScope, D_PROCEDURE);
|
|
||||||
open_scope(OPENSCOPE, 0);
|
|
||||||
}
|
|
||||||
FormalParameters?
|
|
||||||
';' block IDENT
|
';' block IDENT
|
||||||
{ match_id(dot.TOK_IDF, df->df_idf);
|
{ match_id(dot.TOK_IDF, df->df_idf);
|
||||||
close_scope();
|
close_scope();
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
ProcedureHeading
|
ProcedureHeading(struct def **pdf; int type;)
|
||||||
{
|
{
|
||||||
register struct def *df;
|
|
||||||
} :
|
} :
|
||||||
/* Only used for definition modules
|
|
||||||
*/
|
|
||||||
PROCEDURE IDENT
|
PROCEDURE IDENT
|
||||||
{ df = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD); }
|
{ assert(type == D_PROCEDURE || type == D_PROCHEAD);
|
||||||
FormalParameters?
|
*pdf = define(dot.TOK_IDF, CurrentScope, D_PROCHEAD);
|
||||||
|
if (type == D_PROCEDURE) {
|
||||||
|
open_scope(OPENSCOPE, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FormalParameters(type, &((*pdf)->df_type))?
|
||||||
;
|
;
|
||||||
|
|
||||||
block:
|
block:
|
||||||
|
@ -56,13 +54,13 @@ declaration:
|
||||||
ModuleDeclaration ';'
|
ModuleDeclaration ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
FormalParameters:
|
FormalParameters(int doparams; struct type **tp;) :
|
||||||
'(' [ FPSection [ ';' FPSection ]* ]? ')'
|
'(' [ FPSection(doparams) [ ';' FPSection(doparams)]* ]? ')'
|
||||||
[ ':' qualident
|
[ ':' qualident
|
||||||
]?
|
]?
|
||||||
;
|
;
|
||||||
|
|
||||||
FPSection
|
FPSection(int doparams;)
|
||||||
{
|
{
|
||||||
struct id_list *FPList;
|
struct id_list *FPList;
|
||||||
int VARflag = 0;
|
int VARflag = 0;
|
||||||
|
@ -72,6 +70,13 @@ FPSection
|
||||||
]?
|
]?
|
||||||
IdentList(&FPList) ':' FormalType
|
IdentList(&FPList) ':' FormalType
|
||||||
{
|
{
|
||||||
|
if (doparams) {
|
||||||
|
EnterIdList(FPList,
|
||||||
|
D_VARIABLE,
|
||||||
|
VARflag,
|
||||||
|
(struct type *) 0 /* ???? */
|
||||||
|
);
|
||||||
|
}
|
||||||
FreeIdList(FPList);
|
FreeIdList(FPList);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
@ -82,10 +87,13 @@ FormalType:
|
||||||
|
|
||||||
TypeDeclaration
|
TypeDeclaration
|
||||||
{
|
{
|
||||||
register struct def *df;
|
struct def *df;
|
||||||
|
struct idf *id;
|
||||||
}:
|
}:
|
||||||
IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE); }
|
IDENT { id = dot.TOK_IDF; }
|
||||||
'=' type
|
'=' type { df = define(id, CurrentScope, D_TYPE);
|
||||||
|
/* ???? */
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
type:
|
type:
|
||||||
|
@ -124,22 +132,29 @@ enumeration
|
||||||
struct id_list *EnumList;
|
struct id_list *EnumList;
|
||||||
} :
|
} :
|
||||||
'(' IdentList(&EnumList) ')'
|
'(' IdentList(&EnumList) ')'
|
||||||
|
{
|
||||||
|
EnterIdList(EnumList,
|
||||||
|
D_ENUM,
|
||||||
|
0,
|
||||||
|
(struct type *) 0 /* ???? */
|
||||||
|
);
|
||||||
|
FreeIdList(EnumList);
|
||||||
|
}
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
IdentList(struct id_list **p;)
|
IdentList(struct id_list **p;)
|
||||||
{
|
{
|
||||||
register struct id_list *q = new_id_list();
|
register struct id_list *q = new_id_list();
|
||||||
} :
|
} :
|
||||||
IDENT { q->id_ptr = dot.TOK_IDF; }
|
IDENT { q->id_ptr = dot.TOK_IDF; *p = q;}
|
||||||
[
|
[
|
||||||
',' IDENT { q->next = new_id_list();
|
',' IDENT { q->next = new_id_list();
|
||||||
q = q->next;
|
q = q->next;
|
||||||
q->id_ptr = dot.TOK_IDF;
|
q->id_ptr = dot.TOK_IDF;
|
||||||
}
|
}
|
||||||
]*
|
]*
|
||||||
{ q->next = 0;
|
{ q->next = 0; }
|
||||||
*p = q;
|
|
||||||
}
|
|
||||||
;
|
;
|
||||||
|
|
||||||
SubrangeType:
|
SubrangeType:
|
||||||
|
@ -209,10 +224,13 @@ FormalTypeList:
|
||||||
|
|
||||||
ConstantDeclaration
|
ConstantDeclaration
|
||||||
{
|
{
|
||||||
register struct def *df;
|
struct def *df;
|
||||||
|
struct idf *id;
|
||||||
}:
|
}:
|
||||||
IDENT { df = define(dot.TOK_IDF, CurrentScope, D_CONST); }
|
IDENT { id = dot.TOK_IDF; }
|
||||||
'=' ConstExpression
|
'=' ConstExpression { df = define(id, CurrentScope, D_CONST);
|
||||||
|
/* ???? */
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
VariableDeclaration
|
VariableDeclaration
|
||||||
|
@ -224,4 +242,11 @@ VariableDeclaration
|
||||||
ConstExpression
|
ConstExpression
|
||||||
]?
|
]?
|
||||||
':' type
|
':' type
|
||||||
|
{ EnterIdList(VarList,
|
||||||
|
D_VARIABLE,
|
||||||
|
0,
|
||||||
|
(struct type *) 0 /* ???? */
|
||||||
|
);
|
||||||
|
FreeIdList(VarList);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
struct module {
|
struct module {
|
||||||
int mo_priority; /* Priority of a module */
|
int mo_priority; /* Priority of a module */
|
||||||
|
int mo_scope; /* Scope of this module */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct variable {
|
struct variable {
|
||||||
|
|
|
@ -10,6 +10,7 @@ static char *RcsId = "$Header$";
|
||||||
#include "idf.h"
|
#include "idf.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "scope.h"
|
#include "scope.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
struct def *h_def; /* Pointer to free list of def structures */
|
struct def *h_def; /* Pointer to free list of def structures */
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ define(id, scope, kind)
|
||||||
*/
|
*/
|
||||||
register struct def *df = lookup(id, scope->sc_scope);
|
register struct def *df = lookup(id, scope->sc_scope);
|
||||||
|
|
||||||
|
DO_DEBUG(debug(3,"Defining identifier %s in scope %d", id->id_text, scope->sc_scope));
|
||||||
if ( /* Already in this scope */
|
if ( /* Already in this scope */
|
||||||
df
|
df
|
||||||
|| /* A closed scope, and id defined in the pervasive scope */
|
|| /* A closed scope, and id defined in the pervasive scope */
|
||||||
|
@ -46,7 +48,7 @@ define(id, scope, kind)
|
||||||
return df;
|
return df;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
error("Identifier %s already declared", id->id_text);
|
error("Identifier \"%s\" already declared", id->id_text);
|
||||||
return df;
|
return df;
|
||||||
}
|
}
|
||||||
df = new_def();
|
df = new_def();
|
||||||
|
@ -71,6 +73,7 @@ lookup(id, scope)
|
||||||
|
|
||||||
df1 = 0;
|
df1 = 0;
|
||||||
df = id->id_def;
|
df = id->id_def;
|
||||||
|
DO_DEBUG(debug(3,"Looking for identifier %s in scope %d", id->id_text, scope));
|
||||||
while (df) {
|
while (df) {
|
||||||
if (df->df_scope == scope) {
|
if (df->df_scope == scope) {
|
||||||
if (df1) {
|
if (df1) {
|
||||||
|
@ -80,6 +83,7 @@ lookup(id, scope)
|
||||||
}
|
}
|
||||||
return df;
|
return df;
|
||||||
}
|
}
|
||||||
|
df1 = df;
|
||||||
df = df->next;
|
df = df->next;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2,16 +2,19 @@
|
||||||
|
|
||||||
static char *RcsId = "$Header$";
|
static char *RcsId = "$Header$";
|
||||||
|
|
||||||
|
#include <alloc.h>
|
||||||
#include <em_arith.h>
|
#include <em_arith.h>
|
||||||
#include <em_label.h>
|
#include <em_label.h>
|
||||||
#include "idf.h"
|
#include "idf.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "scope.h"
|
#include "scope.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
extern struct idf *str2idf();
|
extern struct idf *str2idf();
|
||||||
extern struct def *define();
|
extern struct def *define();
|
||||||
|
|
||||||
|
struct def *
|
||||||
Enter(name, kind, type, pnam)
|
Enter(name, kind, type, pnam)
|
||||||
char *name;
|
char *name;
|
||||||
struct type *type;
|
struct type *type;
|
||||||
|
@ -26,4 +29,27 @@ Enter(name, kind, type, pnam)
|
||||||
if (kind == D_STDPROC || kind == D_STDFUNC) {
|
if (kind == D_STDPROC || kind == D_STDFUNC) {
|
||||||
df->df_value.df_stdname = pnam;
|
df->df_value.df_stdname = pnam;
|
||||||
}
|
}
|
||||||
|
return df;
|
||||||
|
}
|
||||||
|
|
||||||
|
EnterIdList(idlist, kind, flags, type)
|
||||||
|
register struct id_list *idlist;
|
||||||
|
struct type *type;
|
||||||
|
{
|
||||||
|
register struct def *df;
|
||||||
|
struct def *last = 0;
|
||||||
|
int assval = 0;
|
||||||
|
|
||||||
|
while (idlist) {
|
||||||
|
df = define(idlist->id_ptr, CurrentScope, kind);
|
||||||
|
df->df_type = type;
|
||||||
|
df->df_flags = flags;
|
||||||
|
if (kind == D_ENUM) {
|
||||||
|
df->df_value.df_enum.en_val = assval++;
|
||||||
|
if (last) last->df_value.df_enum.en_next = df;
|
||||||
|
last = df;
|
||||||
|
}
|
||||||
|
idlist = idlist->next;
|
||||||
|
}
|
||||||
|
if (last) last->df_value.df_enum.en_next = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,3 +10,5 @@ struct id_list {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ALLOCDEF "id_list" */
|
/* ALLOCDEF "id_list" */
|
||||||
|
|
||||||
|
#define is_anon_idf(x) ((x)->id_text[0] == '#')
|
||||||
|
|
|
@ -17,7 +17,7 @@ match_id(id1, id2)
|
||||||
first place, and if not, give an error message
|
first place, and if not, give an error message
|
||||||
*/
|
*/
|
||||||
if (id1 != id2 && !is_anon_idf(id1) && !is_anon_idf(id2)) {
|
if (id1 != id2 && !is_anon_idf(id1) && !is_anon_idf(id2)) {
|
||||||
error("Identifier \"%s\" does not match identifier \"%s\"",
|
error("Name \"%s\" does not match block name \"%s\"",
|
||||||
id1->id_text,
|
id1->id_text,
|
||||||
id2->id_text
|
id2->id_text
|
||||||
);
|
);
|
||||||
|
@ -54,10 +54,3 @@ gen_anon_idf()
|
||||||
++name_cnt, FileName, LineNumber);
|
++name_cnt, FileName, LineNumber);
|
||||||
return str2idf(buff, 1);
|
return str2idf(buff, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
is_anon_idf(idf)
|
|
||||||
struct idf *idf;
|
|
||||||
{
|
|
||||||
return idf->id_text[0] == '#';
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,11 +5,14 @@ static char *RcsId = "$Header$";
|
||||||
|
|
||||||
#include <alloc.h>
|
#include <alloc.h>
|
||||||
#include <em_arith.h>
|
#include <em_arith.h>
|
||||||
|
#include <em_label.h>
|
||||||
#include "idf.h"
|
#include "idf.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "LLlex.h"
|
#include "LLlex.h"
|
||||||
#include "scope.h"
|
#include "scope.h"
|
||||||
|
#include "def.h"
|
||||||
|
#include "type.h"
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
The grammar as given by Wirth is already almost LL(1); the
|
The grammar as given by Wirth is already almost LL(1); the
|
||||||
|
@ -40,8 +43,13 @@ priority:
|
||||||
export
|
export
|
||||||
{
|
{
|
||||||
struct id_list *ExportList;
|
struct id_list *ExportList;
|
||||||
|
int QUALflag = 0;
|
||||||
} :
|
} :
|
||||||
EXPORT QUALIFIED? IdentList(&ExportList) ';'
|
EXPORT
|
||||||
|
[
|
||||||
|
QUALIFIED { QUALflag = 1; }
|
||||||
|
]?
|
||||||
|
IdentList(&ExportList) ';'
|
||||||
{
|
{
|
||||||
FreeIdList(ExportList);
|
FreeIdList(ExportList);
|
||||||
}
|
}
|
||||||
|
@ -67,9 +75,16 @@ import(int local;)
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
DefinitionModule:
|
DefinitionModule
|
||||||
|
{
|
||||||
|
struct def *df;
|
||||||
|
} :
|
||||||
DEFINITION { state = DEFINITION; }
|
DEFINITION { state = DEFINITION; }
|
||||||
MODULE IDENT { open_scope(CLOSEDSCOPE, 0); }
|
MODULE IDENT {
|
||||||
|
df = define(dot.TOK_IDF, CurrentScope, D_MODULE);
|
||||||
|
open_scope(CLOSEDSCOPE, 0);
|
||||||
|
df->df_value.df_module.mo_scope = CurrentScope->sc_scope;
|
||||||
|
}
|
||||||
';'
|
';'
|
||||||
import(0)*
|
import(0)*
|
||||||
/* export?
|
/* export?
|
||||||
|
@ -80,7 +95,10 @@ DefinitionModule:
|
||||||
{ close_scope(); }
|
{ close_scope(); }
|
||||||
;
|
;
|
||||||
|
|
||||||
definition:
|
definition
|
||||||
|
{
|
||||||
|
struct def *df;
|
||||||
|
} :
|
||||||
CONST [ ConstantDeclaration ';' ]*
|
CONST [ ConstantDeclaration ';' ]*
|
||||||
|
|
|
|
||||||
TYPE
|
TYPE
|
||||||
|
@ -98,13 +116,17 @@ definition:
|
||||||
|
|
|
|
||||||
VAR [ VariableDeclaration ';' ]*
|
VAR [ VariableDeclaration ';' ]*
|
||||||
|
|
|
|
||||||
ProcedureHeading ';'
|
ProcedureHeading(&df, D_PROCHEAD) ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
ProgramModule:
|
ProgramModule:
|
||||||
MODULE { if (state != IMPLEMENTATION) state = PROGRAM; }
|
MODULE { if (state != IMPLEMENTATION) state = PROGRAM; }
|
||||||
IDENT { if (state == IMPLEMENTATION) {
|
IDENT { if (state == IMPLEMENTATION) {
|
||||||
/* Re-open scope ??? */
|
/* ????
|
||||||
|
Read definition module,
|
||||||
|
Look for current identifier,
|
||||||
|
and find out its scope number
|
||||||
|
*/
|
||||||
open_scope(CLOSEDSCOPE, 0);
|
open_scope(CLOSEDSCOPE, 0);
|
||||||
}
|
}
|
||||||
else open_scope(CLOSEDSCOPE, 0);
|
else open_scope(CLOSEDSCOPE, 0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue