EYAPP(1) User Contributed Perl Documentation EYAPP(1)

eyapp - A Perl front-end to the Parse::Eyapp module

    eyapp [options] grammar[.eyp]
    eyapp -V
    eyapp -h
        grammar     The grammar file. If no suffix is given, and the file
                    does not exists, .eyp is added

The eyapp compiler is a front-end to the Parse::Eyapp module, which lets you compile Parse::Eyapp grammar input files into Perl LALR(1) Object Oriented parser modules.

Creates a file grammar.output describing your parser. It will show you a summary of conflicts, rules, the DFA (Deterministic Finite Automaton) states and overall usage of the parser.

Implies option "-N". To produce a more detailed description of the states, the LALR tables aren't compacted. Use the combination "-vN" to produce an ".output" file corresponding to the compacted tables.

Create a standalone module in which the parsing driver is included. The modules including the LALR driver (Parse::Eyapp::Driver), those for AST manipulations (Parse::Eyapp::Node and Parse::Eyapp::YATW)) and Parse::Eyapp::Base are included - almost verbatim - inside the generated module.

Note that if you have more than one parser module called from a program, to have it standalone, you need this option only for one of your grammars;

Disable source file line numbering embedded in your parser module. I don't know why one should need it, but it's there.
Gives your parser module the package name (or name space or module name or class name or whatever-you-call-it) of module. It defaults to grammar
The compiled output file will be named outfile for your parser module. It defaults to grammar.pm or, if you specified the option -m A::Module::Name (see below), to Name.pm.
Produces as output (STDOUT) the grammar without the actions. Only the syntactic parts are displayed. Comments will be also stripped if the "-v" option is added.
The -t filename option allows you to specify a file which should be used as template for generating the parser output. The default is to use the internal template defined in Parse::Eyapp::Output.pm. For how to write your own template and which substitutions are available, have a look to the module Parse::Eyapp::Output.pm : it should be obvious.
If you work on systems that understand so called shebangs, and your generated parser is directly an executable script, you can specify one with the -b option, ie:

    eyapp -b '/usr/local/bin/perl -w' -o myscript.pl myscript.yp
    

This will output a file called myscript.pl whose very first line is:

    #!/usr/local/bin/perl -w
    

The argument is mandatory, but if you specify an empty string, the value of $Config{perlpath} will be used instead.

Adds a modulino call '__PACKAGE->main(<prompt>) unless caller();' as the very last line of the output file. The argument is mandatory.
An abbreviation for the combined use of -b '' and -B ''
Equivalent to %tree.
Equivalent to the directive %nocompact. Do not compact LALR action tables.
Do not provide a default lexical analyzer. By default "eyapp" builds a lexical analyzer from your "%token = /regexp/" definitions
The input grammar file. If no suffix is given, and the file does not exists, an attempt to open the file with a suffix of .eyp is tried before exiting.
Display current version of Parse::Eyapp and gracefully exits.
Display the usage screen.

The following "eyapp" program translates an infix expression like "2+3*4" to postfix: "2 3 4 * +"

    %token NUM = /([0-9]+(?:\.[0-9]+)?)/
    %token VAR = /([A-Za-z][A-Za-z0-9_]*)/
    %right  '='
    %left   '-' '+'
    %left   '*' '/'
    %left   NEG
    %defaultaction { "$left $right $op"; }
    %%
    line: $exp  { print "$exp\n" }
    ;
    exp:        $NUM  { $NUM }            
            |   $VAR  { $VAR }            
            |   VAR.left '='.op exp.right         
            |   exp.left '+'.op exp.right         
            |   exp.left '-'.op exp.right        
            |   exp.left '*'.op exp.right       
            |   exp.left '/'.op exp.right      
            |   '-' $exp %prec NEG { "$exp NEG" }
            |   '(' $exp ')' { $exp }      
    ;
    %%

Notice that there is no need to write lexer and error report subroutines. First, we compile the grammar:

    pl@nereida:~/LEyapp/examples/eyappintro$ eyapp -o postfix.pl -C Postfix.eyp

If we use the "-C" option and no "main()" was written one default "main" sub is provided. We can now execute the resulting program:

    pl@nereida:~/LEyapp/examples/eyappintro$ ./postfix.pl -c 'a = 2*3 +b'
    a 2 3 * b + =

When a non conformant input is given, it produces an accurate error message:

    pl@nereida:~/LEyapp/examples/eyappintro$ ./postfix.pl -c 'a = 2**3 +b'
    Syntax error near '*'. 
    Expected one of these terminals: '-' 'NUM' 'VAR' '('
    There were 1 errors during parsing

Casiano Rodriguez-Leon

Copyright © 2006, 2007, 2008, 2009, 2010, 2011, 2012 Casiano Rodriguez-Leon. Copyright © 2017 William N. Braswell, Jr. All Rights Reserved.

Parse::Yapp is Copyright © 1998, 1999, 2000, 2001, Francois Desarmenien. Parse::Yapp is Copyright © 2017 William N. Braswell, Jr. All Rights Reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

Hey! The above document had some coding errors, which are explained below:

Non-ASCII character seen before =encoding in '©'. Assuming UTF-8
2017-06-14 perl v5.34.0