reset_file_scope_vars
los tipos básicos INT
, CHAR
y VOID
.
Este último se utilizará en las expresiones de tipo
para representar la ausencia de tipo.
pl@nereida:~/doc/casiano/PLBOOK/PLBOOK/code/Simple-Types/lib/Simple$ \ sed -ne '/^program:/,/^;/p' Types.eyp | cat -n 1 program: 2 { 3 reset_file_scope_vars(); 4 } 5 definition<%name PROGRAM +>.program 6 { 7 $program->{symboltable} = { %st }; # creates a copy of the s.t. 8 $program->{depth} = 0; 9 $program->{line} = 1; 10 $program->{types} = { %type }; 11 $program->{lines} = $tokenend; 12 13 my ($nondec, $declared) = $ids->end_scope($program->{symboltable}, $program, 'type'); 14 15 if (@$nondec) { 16 warn "Identifier ".$_->key." not declared at line ".$_->line."\n" for @$nondec; 17 die "\n"; 18 } 19 20 # Type checking: add a direct pointer to the data-structure 21 # describing the type 22 $_->{t} = $type{$_->{type}} for @$declared; 23 24 my $out_of_loops = $loops->end_scope($program); 25 if (@$out_of_loops) { 26 warn "Error: ".ref($_)." outside of loop at line $_->{line}\n" for @$out_of_loops; 27 die "\n"; 28 } 29 30 # Check that are not dangling breaks 31 reset_file_scope_vars(); 32 33 $program; 34 } 35 ;
Se procede a establecer el atributo t
como enlace directo a la expresión de tipo. Lo mismo se hace en las funciones
y en los bloques.
Sigue el código de reset_file_scope_vars
:
pl@nereida:~/doc/casiano/PLBOOK/PLBOOK/code/Simple-Types/lib/Simple$ \ sed -ne '/^sub re.*vars/,/^}/p' Types.eyp | cat -n 1 sub reset_file_scope_vars { 2 %st = (); # reset symbol table 3 ($tokenbegin, $tokenend) = (1, 1); 4 %type = ( INT => Parse::Eyapp::Node->hnew('INT'), 5 CHAR => Parse::Eyapp::Node->hnew('CHAR'), 6 VOID => Parse::Eyapp::Node->hnew('VOID'), 7 ); 8 $depth = 0; 9 $ids = Parse::Eyapp::Scope->new( 10 SCOPE_NAME => 'block', 11 ENTRY_NAME => 'info', 12 SCOPE_DEPTH => 'depth', 13 ); 14 $loops = Parse::Eyapp::Scope->new( 15 SCOPE_NAME => 'exits', 16 ); 17 $ids->begin_scope(); 18 $loops->begin_scope(); # just for checking 19 }