~ubuntu-branches/ubuntu/trusty/horae/trusty

« back to all changes in this revision

Viewing changes to 0CPAN/Parse-RecDescent-1.94/demo/demo_selfmod.pl

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/local/bin/perl -sw
2
 
 
3
 
# A SELF-MODIFYING**2 PARSER
4
 
 
5
 
use Parse::RecDescent;
6
 
 
7
 
$grammar =
8
 
q{
9
 
        type_defn : 'only' <commit> "$::keyword" is type_name ';'
10
 
                       { $thisparser->Replace("type_name: '$item[5]'");
11
 
                          print "\"$item[5]\" is now the only valid type name\n";
12
 
                       }
13
 
 
14
 
                  | "$::keyword" <commit> identifier(s) is type_name /('?s)?/ ';'
15
 
                       { my $newnames = join " | ", map { "'$_'" } @{$item[3]};
16
 
                          $thisparser->Extend("type_name: $newnames"); 
17
 
                          print "added $newnames as type name(s)\n";
18
 
                       }
19
 
 
20
 
                  | /change\s+$::keyword\s+to/ identifier
21
 
                       { $::keyword = $item[2];
22
 
                          print "changed $item[0] keyword to: $item[2]\n";
23
 
                       }
24
 
 
25
 
                  | <error>
26
 
 
27
 
        is        : /is|are/
28
 
 
29
 
        type_name : 'int' | 'float' 
30
 
 
31
 
        identifier: ...!is ...!"$::keyword" ...!type_name /[A-Za-z]\w*/
32
 
 
33
 
};
34
 
 
35
 
use vars qw { $keyword };
36
 
 
37
 
$keyword = "type";
38
 
 
39
 
$parse = new Parse::RecDescent ($grammar);
40
 
 
41
 
while (<>)
42
 
{
43
 
        $parse->type_defn($_) or print "huh?\n";
44
 
}