Beruflich Dokumente
Kultur Dokumente
Scope
{L}+
{entry = lookup(yytext);
if (entry == -1) /* i.e. new ID_T */
insert(yytext,ID_T);
}
Scoping Rules
In block structured languages, the same variable
name can be used in different places to refer to
different objects.
We now cannot simply look to see if the name has
already been entered in the table, as the current use
may be a new declaration.
int i;
i is globally accessible
int f1(int k) {
int j;
...
print i;
}
int f2() {
int j;
...
}
a different j, in f2 only
Prog
Prog
Dec
Dec
VDec
FDec
SFDec
Par
Par
Par
PList
PList
{L}+
decr(stack);
incr(stack);
{entry = lookup(yytext,stack);
if (entry == -1) insert(yytext,ID_T,stack);
}
Str
i
f1
k
j
f2
j
Nest
0
0
1
1
0
1
Scope
0
0
1
1
0
4
Atts
...
VDec
int
id
i
func
int
id
f1
func
VDec
int
id
k
VDec
int
id
j
int
id l
f2
id
i
VDec
int
id
j