| 
0
 | 
     1 <html>
 | 
| 
 | 
     2 <head>
 | 
| 
 | 
     3 <title>MayaChemTools:Documentation:Parsers::SimpleCalcParser.pm</title>
 | 
| 
 | 
     4 <meta http-equiv="content-type" content="text/html;charset=utf-8">
 | 
| 
 | 
     5 <link rel="stylesheet" type="text/css" href="../../css/MayaChemTools.css">
 | 
| 
 | 
     6 </head>
 | 
| 
 | 
     7 <body leftmargin="20" rightmargin="20" topmargin="10" bottommargin="10">
 | 
| 
 | 
     8 <br/>
 | 
| 
 | 
     9 <center>
 | 
| 
 | 
    10 <a href="http://www.mayachemtools.org" title="MayaChemTools Home"><img src="../../images/MayaChemToolsLogo.gif" border="0" alt="MayaChemTools"></a>
 | 
| 
 | 
    11 </center>
 | 
| 
 | 
    12 <br/>
 | 
| 
 | 
    13 <div class="DocNav">
 | 
| 
 | 
    14 <table width="100%" border=0 cellpadding=0 cellspacing=2>
 | 
| 
 | 
    15 <tr align="left" valign="top"><td width="33%" align="left"><a href="./Lexer.html" title="Lexer.html">Previous</a>  <a href="./index.html" title="Table of Contents">TOC</a>  <a href="./SimpleCalcYYLexer.html" title="SimpleCalcYYLexer.html">Next</a></td><td width="34%" align="middle"><strong>Parsers::SimpleCalcParser.pm</strong></td><td width="33%" align="right"><a href="././code/SimpleCalcParser.html" title="View source code">Code</a> | <a href="./../pdf/SimpleCalcParser.pdf" title="PDF US Letter Size">PDF</a> | <a href="./../pdfgreen/SimpleCalcParser.pdf" title="PDF US Letter Size with narrow margins: www.changethemargins.com">PDFGreen</a> | <a href="./../pdfa4/SimpleCalcParser.pdf" title="PDF A4 Size">PDFA4</a> | <a href="./../pdfa4green/SimpleCalcParser.pdf" title="PDF A4 Size with narrow margins: www.changethemargins.com">PDFA4Green</a></td></tr>
 | 
| 
 | 
    16 </table>
 | 
| 
 | 
    17 </div>
 | 
| 
 | 
    18 <p>
 | 
| 
 | 
    19 </p>
 | 
| 
 | 
    20 <h2>NAME</h2>
 | 
| 
 | 
    21 <p>Parsers::SimpleCalcParser</p>
 | 
| 
 | 
    22 <p>
 | 
| 
 | 
    23 </p>
 | 
| 
 | 
    24 <h2>SYNOPSIS</h2>
 | 
| 
 | 
    25 <p>use Parsers::SimpleCalcParser ;</p>
 | 
| 
 | 
    26 <p>use Parsers::SimpleCalcParser qw(:all);</p>
 | 
| 
 | 
    27 <p>
 | 
| 
 | 
    28 </p>
 | 
| 
 | 
    29 <h2>DESCRIPTION</h2>
 | 
| 
 | 
    30 <p><strong>Parsers::SimpleCalcParser</strong> class provides the following methods:</p>
 | 
| 
 | 
    31 <p> <a href="#new">new</a>, <a href="#yyclearin">yyclearin</a>, <a href="#yyerrok">yyerrok</a>, <a href="#yyerror">yyerror</a>, <a href="#yyparse">yyparse</a>
 | 
| 
 | 
    32 </p><p><strong>Parsers::SimpleCalcParse.yy</strong> parser grammer definition file implements a simple
 | 
| 
 | 
    33 calculator and is provided to highlight usage of lexer capability available through
 | 
| 
 | 
    34 <strong>Parsers::SimpleCalcYYLexer</strong>, which in turn uses <strong>Parsers::YYLexer</strong> and
 | 
| 
 | 
    35 <strong>Parsers::Lexer</strong> classes to procide underlying lexer functionality.</p>
 | 
| 
 | 
    36 <p>The parser package and token table files, <strong>Parsers::SimpleCalcParser.pm</strong> and
 | 
| 
 | 
    37 <strong>SimpleCalcParser.tab.ph</strong>, are automatically generated from parser grammar definition
 | 
| 
 | 
    38 file, <strong>Parsers::SimpleCalcParser.yy</strong>, using byacc available through perl-byacc1.8 modified
 | 
| 
 | 
    39 with perl5-byacc-patches-0.5 for generation of object oriented parser:</p>
 | 
| 
 | 
    40 <div class="OptionsBox">
 | 
| 
 | 
    41     byacc -l -P -d -b SimpleCalcParser SimpleCalcParser.yy
 | 
| 
 | 
    42 <br/>    mv SimpleCalcParser.tab.pl SimpleCalcParser.pm</div>
 | 
| 
 | 
    43 <p>
 | 
| 
 | 
    44 </p>
 | 
| 
 | 
    45 <h2>METHODS</h2>
 | 
| 
 | 
    46 <dl>
 | 
| 
 | 
    47 <dt><strong><a name="new" class="item"><strong>new</strong></a></strong></dt>
 | 
| 
 | 
    48 <dd>
 | 
| 
 | 
    49 <div class="OptionsBox">
 | 
| 
 | 
    50     $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex,
 | 
| 
 | 
    51                                 \&Parsers::SimpleCalcParser::yyerror);
 | 
| 
 | 
    52 <br/>    $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex,
 | 
| 
 | 
    53                                 \&Parsers::SimpleCalcParser::yyerror, $Debug);</div>
 | 
| 
 | 
    54 <p>Using specified <em>YYLex</em> <em>YYError</em> functions, <strong>new</strong> method generates a new
 | 
| 
 | 
    55 <strong>SimpleCalcParser</strong> and returns a reference to newly created <strong>SimpleCalcYYParser</strong> object.</p>
 | 
| 
 | 
    56 <p>Examples:</p>
 | 
| 
 | 
    57 <div class="OptionsBox">
 | 
| 
 | 
    58     # Input string...
 | 
| 
 | 
    59 <br/>    $InputText = "3 + 4 +6\nx=3\ny=5\nx+y\nx+z\n";
 | 
| 
 | 
    60 <br/>    $YYLexer = new Parsers::SimpleCalcYYLexer($InputText);
 | 
| 
 | 
    61 <br/>    $YYLex = $YYLexer->GetYYLex();</div>
 | 
| 
 | 
    62 <div class="OptionsBox">
 | 
| 
 | 
    63     $Debug = 0;
 | 
| 
 | 
    64 <br/>    $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex,
 | 
| 
 | 
    65                                \&Parsers::SimpleCalcParser::yyerror, $Debug);
 | 
| 
 | 
    66 <br/>    $Value = $SimpleCalcParser->yyparse();
 | 
| 
 | 
    67 <br/>    print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n";</div>
 | 
| 
 | 
    68 <div class="OptionsBox">
 | 
| 
 | 
    69     # Input file...
 | 
| 
 | 
    70 <br/>    $InputFile = "TestSimpleCalcParser.txt";
 | 
| 
 | 
    71 <br/>    open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";</div>
 | 
| 
 | 
    72 <div class="OptionsBox">
 | 
| 
 | 
    73     $YYLexer = new Parsers::SimpleCalcYYLexer(\*INPUTFILE);
 | 
| 
 | 
    74 <br/>    $YYLex = $YYLexer->GetYYLex();</div>
 | 
| 
 | 
    75 <div class="OptionsBox">
 | 
| 
 | 
    76     $Debug = 0;
 | 
| 
 | 
    77 <br/>    $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex,
 | 
| 
 | 
    78                                \&Parsers::SimpleCalcParser::yyerror, $Debug);
 | 
| 
 | 
    79 <br/>    $Value = $SimpleCalcParser->yyparse();
 | 
| 
 | 
    80 <br/>    print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n";</div>
 | 
| 
 | 
    81 <div class="OptionsBox">
 | 
| 
 | 
    82     close INPUTFILE;</div>
 | 
| 
 | 
    83 <div class="OptionsBox">
 | 
| 
 | 
    84     # Input iterator...
 | 
| 
 | 
    85 <br/>    $InputFile = "TestSimpleCalcParser.txt";
 | 
| 
 | 
    86 <br/>    open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";
 | 
| 
 | 
    87 <br/>    $InputIterator = sub { return <INPUTFILE>; };</div>
 | 
| 
 | 
    88 <div class="OptionsBox">
 | 
| 
 | 
    89     $YYLexer = new Parsers::SimpleCalcYYLexer($InputIterator);
 | 
| 
 | 
    90 <br/>    $YYLex = $YYLexer->GetYYLex();</div>
 | 
| 
 | 
    91 <div class="OptionsBox">
 | 
| 
 | 
    92     $Debug = 0;
 | 
| 
 | 
    93 <br/>    $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex,
 | 
| 
 | 
    94                                \&Parsers::SimpleCalcParser::yyerror, $Debug);
 | 
| 
 | 
    95 <br/>    $Value = $SimpleCalcParser->yyparse();
 | 
| 
 | 
    96 <br/>    print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n";</div>
 | 
| 
 | 
    97 <div class="OptionsBox">
 | 
| 
 | 
    98     close INPUTFILE;</div>
 | 
| 
 | 
    99 </dd>
 | 
| 
 | 
   100 <dt><strong><a name="yyclearin" class="item"><strong>yyclearin</strong></a></strong></dt>
 | 
| 
 | 
   101 <dd>
 | 
| 
 | 
   102 <div class="OptionsBox">
 | 
| 
 | 
   103     $SimpleCalcParser->yyclearin();</div>
 | 
| 
 | 
   104 <p><strong>yyclearin</strong> method clears any previous look-ahead token after encountering a syntax error
 | 
| 
 | 
   105 during parsing. It can be used after <strong>yyerrok</strong> in a grammer rule with the reserved word
 | 
| 
 | 
   106 <strong>error</strong>.</p>
 | 
| 
 | 
   107 </dd>
 | 
| 
 | 
   108 <dt><strong><a name="yyerrok" class="item"><strong>yyerrok</strong></a></strong></dt>
 | 
| 
 | 
   109 <dd>
 | 
| 
 | 
   110 <div class="OptionsBox">
 | 
| 
 | 
   111     $SimpleCalcParser->yyerrok();</div>
 | 
| 
 | 
   112 <p><strong>yyerrok</strong> method is used with the reserved word <strong>error</strong> in grammer rule to indcate
 | 
| 
 | 
   113 error recovery is complete after encountering a syntax error during parsing.</p>
 | 
| 
 | 
   114 </dd>
 | 
| 
 | 
   115 <dt><strong><a name="yyerror" class="item"><strong>yyerror</strong></a></strong></dt>
 | 
| 
 | 
   116 <dd>
 | 
| 
 | 
   117 <div class="OptionsBox">
 | 
| 
 | 
   118     $SimpleCalcParser->yyerror();</div>
 | 
| 
 | 
   119 <p><strong>yyerror</strong> function is provided for the caller to use during initialization of a parser. It
 | 
| 
 | 
   120 is used by <strong>yyparse</strong> to print any error messages encountered during parsing of the
 | 
| 
 | 
   121 input.</p>
 | 
| 
 | 
   122 </dd>
 | 
| 
 | 
   123 <dt><strong><a name="yyparse" class="item"><strong>yyparse</strong></a></strong></dt>
 | 
| 
 | 
   124 <dd>
 | 
| 
 | 
   125 <div class="OptionsBox">
 | 
| 
 | 
   126     $Value = $SimpleCalcParser->yyparse();</div>
 | 
| 
 | 
   127 <p>Returns <em>Value</em> after parsing all the input from a input stream using specified
 | 
| 
 | 
   128 grammer rules.</p>
 | 
| 
 | 
   129 </dd>
 | 
| 
 | 
   130 </dl>
 | 
| 
 | 
   131 <p>
 | 
| 
 | 
   132 </p>
 | 
| 
 | 
   133 <h2>AUTHOR</h2>
 | 
| 
 | 
   134 <p><a href="mailto:msud@san.rr.com">Manish Sud</a></p>
 | 
| 
 | 
   135 <p>
 | 
| 
 | 
   136 </p>
 | 
| 
 | 
   137 <h2>SEE ALSO</h2>
 | 
| 
 | 
   138 <p><a href="./Lexer.html">Lexer.pm</a>, <a href="./YYLexer.html">YYLexer.pm</a>, <a href="./SimpleCalcYYLexer.html">SimpleCalcYYLexer.pm</a>
 | 
| 
 | 
   139 </p>
 | 
| 
 | 
   140 <p>
 | 
| 
 | 
   141 </p>
 | 
| 
 | 
   142 <h2>COPYRIGHT</h2>
 | 
| 
 | 
   143 <p>Copyright (C) 2015 Manish Sud. All rights reserved.</p>
 | 
| 
 | 
   144 <p>This file is part of MayaChemTools.</p>
 | 
| 
 | 
   145 <p>MayaChemTools is free software; you can redistribute it and/or modify it under
 | 
| 
 | 
   146 the terms of the GNU Lesser General Public License as published by the Free
 | 
| 
 | 
   147 Software Foundation; either version 3 of the License, or (at your option)
 | 
| 
 | 
   148 any later version.</p>
 | 
| 
 | 
   149 <p> </p><p> </p><div class="DocNav">
 | 
| 
 | 
   150 <table width="100%" border=0 cellpadding=0 cellspacing=2>
 | 
| 
 | 
   151 <tr align="left" valign="top"><td width="33%" align="left"><a href="./Lexer.html" title="Lexer.html">Previous</a>  <a href="./index.html" title="Table of Contents">TOC</a>  <a href="./SimpleCalcYYLexer.html" title="SimpleCalcYYLexer.html">Next</a></td><td width="34%" align="middle"><strong>March 29, 2015</strong></td><td width="33%" align="right"><strong>Parsers::SimpleCalcParser.pm</strong></td></tr>
 | 
| 
 | 
   152 </table>
 | 
| 
 | 
   153 </div>
 | 
| 
 | 
   154 <br />
 | 
| 
 | 
   155 <center>
 | 
| 
 | 
   156 <img src="../../images/h2o2.png">
 | 
| 
 | 
   157 </center>
 | 
| 
 | 
   158 </body>
 | 
| 
 | 
   159 </html>
 |