Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Parse::Eyapp 1.111

    Download button

    No screenshots available
    Downloads: 425  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    Good (3.5/5)
    25 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Casiano Rodriguez-Leon | More programs
    Perl Artistic License / FREE
    June 26th, 2008, 18:38 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Parse::Eyapp description

    Parse::Eyapp module contains extensions for Parse::Yapp.

    Parse::Eyapp module contains extensions for Parse::Yapp.

    SYNOPSIS

    use strict;
    use Parse::Eyapp;
    use Parse::Eyapp::Treeregexp;

    sub TERMINAL::info {
    $_[0]{attr}
    }

    my $grammar = q{
    %right '=' # Lowest precedence
    %left '-' '+' # + and - have more precedence than = Disambiguate a-b-c as (a-b)-c
    %left '*' '/' # * and / have more precedence than + Disambiguate a/b/c as (a/b)/c
    %left NEG # Disambiguate -a-b as (-a)-b and not as -(a-b)
    %tree # Let us build an abstract syntax tree ...

    %%
    line: exp { $_[1] } /* list of expressions separated by ';' */
    ;

    /* The %name directive defines the name of the class to which the node being built belongs */
    exp:
    %name NUM NUM | %name VAR VAR | %name ASSIGN VAR '=' exp
    | %name PLUS exp '+' exp | %name MINUS exp '-' exp | %name TIMES exp '*' exp
    | %name DIV exp '/' exp | %name UMINUS '-' exp %prec NEG
    | '(' exp ')' { $_[2] } /* Let us simplify a bit the tree */
    ;

    %%
    sub _Error { die "Syntax error near ".($_[0]->YYCurval?$_[0]->YYCurval:"end of file")."n" }

    sub _Lexer {
    my($parser)=shift; # The parser object

    for ($parser->YYData->{INPUT}) { # Topicalize
    m{Gs+}gc;
    $_ eq '' and return('',undef);
    m{G([0-9]+(?:.[0-9]+)?)}gc and return('NUM',$1);
    m{G([A-Za-z][A-Za-z0-9_]*)}gc and return('VAR',$1);
    m{G(.)}gcs and return($1,$1);
    }
    }

    sub Run {
    my($self)=shift;
    $self->YYParse( yylex => &_Lexer, yyerror => &_Error, );
    }
    }; # end grammar

    our (@all, $uminus);

    Parse::Eyapp->new_grammar( # Create the parser package/class
    input=>$grammar,
    classname=>'Calc', # The name of the package containing the parser
    firstline=>7 # String $grammar starts at line 7 (for error diagnostics)
    );
    my $parser = Calc->new(); # Create a parser
    $parser->YYData->{INPUT} = "2*-3+b*0;--2n"; # Set the input
    my $t = $parser->Run; # Parse it!
    local $Parse::Eyapp::Node::INDENT=2;
    print "Syntax Tree:",$t->str;

    # Let us transform the tree. Define the tree-regular expressions ..
    my $p = Parse::Eyapp::Treeregexp->new( STRING => q{
    { # Example of support code
    my %Op = (PLUS=>'+', MINUS => '-', TIMES=>'*', DIV => '/');
    }
    constantfold: /TIMES|PLUS|DIV|MINUS/:bin(NUM($x), NUM($y))
    => {
    my $op = $Op{ref($bin)};
    $x->{attr} = eval "$x->{attr} $op $y->{attr}";
    $_[0] = $NUM[0];
    }
    uminus: UMINUS(NUM($x)) => { $x->{attr} = -$x->{attr}; $_[0] = $NUM }
    zero_times_whatever: TIMES(NUM($x), .) and { $x->{attr} == 0 } => { $_[0] = $NUM }
    whatever_times_zero: TIMES(., NUM($x)) and { $x->{attr} == 0 } => { $_[0] = $NUM }
    },
    OUTPUTFILE=> 'main.pm'
    );
    $p->generate(); # Create the tranformations

    $t->s($uminus); # Transform UMINUS nodes
    $t->s(@all); # constant folding and mult. by zero

    local $Parse::Eyapp::Node::INDENT=0;
    print "nSyntax Tree after transformations:n",$t->str,"n";

    Requirements:

    · Perl



    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    Parse::Yapp extensions | Perl extension | Perl module | Parse::Eyapp | Parse::Yapp | Perl

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM