1
#! /usr/local/bin/perl -sw
3
# RECURSIVE #includes DURING A RECURSIVE DESCENT
9
open FILE, $_[0] or die "Couldn't find included file: $_[0]\n";
10
my $contents = <FILE>;
20
while (($macro,$defn) = each %macro )
22
$text =~ s/$macro/$defn/;
34
{ $thisline = $item[1]; }
36
{ print "found: [$item[1]] at $thisline\n" }
38
include : '#include' filename
40
print "pre: [$text] at $thisline\n";
41
$text = ::loadfile($item[-1]) . $text;
42
Parse::RecDescent::LineCounter::resync $thisline;
43
print "post: [$text] at $thisline\n";
46
filename : '"' m#[a-z0-9_./-]+#i '"'
47
{ $return = $item[-2] }
48
| '<' m#[a-z0-9_./-]+#i '>'
49
{ $return = $item[-2] }
51
macrodef : '#define' /[a-z]\w*/i /.*/
52
{ $::macro{$item[-2]} = $item[-1] }
54
linedir: '#line' /\d+/
57
{ $return = ::demacro($item[-1]); }
61
$parse = new Parse::RecDescent ($grammar);
65
$reinput = $input = <>;
67
$parse->file($input) or die "Bad file! No biscuit!\n";
69
$parse->file($reinput) or die "Bad file! No biscuit!\n";