Author: bernhard
Date: Tue Dec 23 10:33:34 2008
New Revision: 34280
Modified:
trunk/languages/pipp/src/pct/actions.pm
trunk/languages/pipp/src/pct/grammar.pg
Log:
[Pipp] Start with keeping track whether a variable is declared.
Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm (original)
+++ trunk/languages/pipp/src/pct/actions.pm Tue Dec 23 10:33:34 2008
@@ -19,32 +19,40 @@
class Pipp::Grammar::Actions;
-method TOP($/) {
- my $past := PAST::Block.new(
- :node($/),
- :hll('pipp')
- );
-
- # set up scope 'package' for the superglobals
- $past.symbol( :scope('package'), '$_GET' );
- $past.symbol( :scope('package'), '$_POST' );
- $past.symbol( :scope('package'), '$_SERVER' );
- $past.symbol( :scope('package'), '$_GLOBALS' );
- $past.symbol( :scope('package'), '$_FILES' );
- $past.symbol( :scope('package'), '$_COOKIE' );
- $past.symbol( :scope('package'), '$_SESSION' );
- $past.symbol( :scope('package'), '$_REQUEST' );
- $past.symbol( :scope('package'), '$_ENV' );
+method TOP($/, $key) {
+ our $?BLOCK;
+ our @?BLOCK; # keep track of the current block
+
+ if $key eq 'open' {
+ $?BLOCK := PAST::Block.new(
+ :node($/),
+ :hll('pipp')
+ );
+
+ # set up scope 'package' for the superglobals
+ # TODO: use a loop
+ $?BLOCK.symbol_defaults( :scope('lexical') );
+ $?BLOCK.symbol( :scope('package'), '$_GET' );
+ $?BLOCK.symbol( :scope('package'), '$_POST' );
+ $?BLOCK.symbol( :scope('package'), '$_SERVER' );
+ $?BLOCK.symbol( :scope('package'), '$_GLOBALS' );
+ $?BLOCK.symbol( :scope('package'), '$_FILES' );
+ $?BLOCK.symbol( :scope('package'), '$_COOKIE' );
+ $?BLOCK.symbol( :scope('package'), '$_SESSION' );
+ $?BLOCK.symbol( :scope('package'), '$_REQUEST' );
+ $?BLOCK.symbol( :scope('package'), '$_ENV' );
+ }
+ elsif $key eq 'close' {
+ # a PHP script consists of a list of statements
+ for $<sea_or_code> {
+ $?BLOCK.push( $($_) );
+ }
- # a PHP script consists of a list of statements
- for $<sea_or_code> {
- $past.push( $($_) );
+ make $?BLOCK;
}
-
- make $past;
}
-method sea_or_code($/,$key) {
+method sea_or_code($/, $key) {
make $( $/{$key} );
}
@@ -101,7 +109,7 @@
make $past;
}
-method statement($/,$key) {
+method statement($/, $key) {
make $( $/{$key} );
}
@@ -335,12 +343,26 @@
);
}
-method var($/,$key) {
+method var($/, $key) {
make $( $/{$key} );
}
method VAR_NAME($/) {
our $?PIPP_CURRENT_SCOPE;
+ our $?BLOCK;
+
+ my $isdecl;
+ if $?BLOCK.symbol( ~$/ ) {
+ # symbol is already present
+ $isdecl := 0;
+ }
+ else {
+ $isdecl := 1;
+ $?BLOCK.symbol(
+ ~$/,
+ :scope( $?PIPP_CURRENT_SCOPE ?? $?PIPP_CURRENT_SCOPE !! 'package' )
+ );
+ }
make PAST::Var.new(
:scope( $?PIPP_CURRENT_SCOPE ?? $?PIPP_CURRENT_SCOPE !! 'package'
),
@@ -404,11 +426,11 @@
}
-method term($/,$key) {
+method term($/, $key) {
make $( $/{$key} );
}
-method literal($/,$key) {
+method literal($/, $key) {
make $( $/{$key} );
}
Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg (original)
+++ trunk/languages/pipp/src/pct/grammar.pg Tue Dec 23 10:33:34 2008
@@ -6,7 +6,11 @@
grammar Pipp::Grammar is PCT::Grammar;
# the starting rule
-token TOP { ^ <sea_or_code>+ {*} }
+token TOP {
+ {*} #= open
+ ^ <sea_or_code>+
+ {*} #= close
+}
# Whitespace and comments