=head1 NAME Parse::Eyapp::Scope - Support for Scope Analysis =head1 SYNOPSIS # Fragment of the grammar lib/Simple/Types.eyp # in examples/typechecking/Simple-Types-XXX.tar.gz funcDef: $ID { $ids->begin_scope(); } '(' $params ')' $block { my $st = $block->{symboltable}; my @decs = $params->children(); $block->{parameters} = []; while (my ($bt, $id, $arrspec) = splice(@decs, 0, 3)) { $bt = ref($bt); # The string 'INT', 'CHAR', etc. my $name = $id->{attr}[0]; my $type = build_type($bt, $arrspec); $type{$type} = Parse::Eyapp::Node->hnew($type); # control duplicated declarations die "Duplicated declaration of $name at line $id->{attr}[1]\n" if exists($st->{$name}); $st->{$name}->{type} = $type; $st->{$name}->{param} = 1; $st->{$name}->{line} = $id->{attr}[1]; push @{$block->{parameters}}, $name; } $block->{function_name} = $ID; $block->type("FUNCTION"); my ($nodec, $dec) = $ids->end_scope($st, $block, 'type'); # Type checking: add a direct pointer to the data-structure # describing the type $_->{t} = $type{$_->{type}} for @$dec; return $block; } ; ... Primary: %name INUM INUM | %name CHARCONSTANT CHARCONSTANT | $Variable { $ids->scope_instance($Variable); return $Variable } | '(' expression ')' { $_[2] } | $function_call { $ids->scope_instance($function_call); return $function_call # bypass } ; =head1 INTRODUCTION The examples used in this document can be found in the file C. This distribution contains the front-end of a compiler (lexical analysis, syntax analysis, scope analysis and type checking) for a small subset of the C language. The language has characters, integers, arrays and functions. Here is a small example: pl@nereida:~/Lbook/code/Simple-Types/script$ cat prueba03.c int a,b,e[10]; g() {} int f(char c) { char d; c = 'X'; e[d] = 'A'+c; { int d; d = a + b; } a = b * 2; return c; } You can find more examples in the C