# #line directives plus adding a #ifdef PERL_CORE
#
# perly.tab the parser table C definitions extracted from the bison output
+# plus an extra table generated by this script.
#
# perly.act the action case statements extracted from the bison output
#
# the test below to allow that version too. DAPM Feb 04.
my $version = `$bison -V`;
-unless ($version =~ /\b(1\.875|2\.0)\b/) { die <<EOF; }
+unless ($version =~ /\b(1\.875[a-z]?|2\.[01])\b/) { die <<EOF; }
You have the wrong version of bison in your path; currently 1.875
-or 2.0 is required. Try installing
- http://ftp.gnu.org/gnu/bison/bison-2.0.tar.gz
-or
- http://ftp.gnu.org/gnu/bison/bison-1.875.tar.bz2
+2.0 or 2.1 is required. Try installing
+ http://ftp.gnu.org/gnu/bison/bison-2.1.tar.gz
or similar. Your bison identifies itself as:
$version
my ($actlines, $tablines) = extract($clines);
+$tablines .= make_opval_tab($y_file, $tablines);
+
chmod 0644, $act_file;
open ACTFILE, ">$act_file" or die "can't open $act_file: $!\n";
print ACTFILE $actlines;
unlink $tmpc_file;
# Wrap PERL_CORE round the symbol definitions. Also, the
-# C<#line 123 "perlytmp.h"> gets picked up by make depend, so change it.
+# C<#line 30 "perly.y"> confuses the Win32 resource compiler and the
+# C<#line 188 "perlytmp.h"> gets picked up by make depend, so remove them.
open TMPH_FILE, $tmph_file or die "Can't open $tmph_file: $!\n";
chmod 0644, $h_file;
print H_FILE "#endif /* PERL_CORE */\n";
$endcore_done = 1;
}
- s/"perlytmp.h"/"perly.h"/;
+ next if /^#line \d+ ".*"/;
print H_FILE $_;
}
close TMPH_FILE;
switch \s* \( \s* \w+ \s* \) \s* { \s*
(
case \s* \d+ \s* : \s*
- \#line [^\n]+"perly\.y"
+ \#line [^\n]+"\Q$y_file\E"
.*?
)
}
return $actlines. "\n", $tablines. "\n";
}
+# read a .y file and extract a list of all the token names and
+# non-terminal names that are declared to be of type opval
+# then scan the string $tablines for the table yytname which gives
+# the token index of each token/non-terminal, then use this to
+# create a new table, indexed by token number, which indicates
+# whether that token is of type opval.
+#
+# ie given
+# %token <opval> A B
+# %type <opval> C D
+#
+# and yytname[] = { "A" "B", "C", "D", "E", "F" };
+#
+# then return
+# static const int yy_is_opval[] = { 1, 1, 1, 1, 0, 0 }
+
+sub make_opval_tab {
+ my ($y_file, $tablines) = @_;
+ my %tokens;
+ open my $fh, '<', $y_file or die "Can't open $y_file: $!\n";
+ while (<$fh>) {
+ next unless s/^%(token|type)\s+<opval>\s+//;
+ $tokens{$_} =1 for (split ' ', $_);
+ }
+
+ $tablines =~ /^\Qstatic const char *const yytname[] =\E\n
+ {\n
+ (.*?)
+ ^};
+ /xsm
+ or die "Can't extract yytname[] from table string\n";
+ my $fields = $1;
+ $fields =~ s/"([^"]+)"/$tokens{$1}||0/ge;
+ return
+ "/* which symbols are of type opval */\n" .
+ "static const int yy_is_opval[] =\n{\n" . $fields . "\n};\n";
+}
+
+
sub my_system {
system(@_);
if ($? == -1) {