Mercurial > repos > deepakjadmin > mayatool3_test3
view mayachemtools/docs/modules/html/SimpleCalcParser.html @ 9:ab29fa5c8c1f draft default tip
Uploaded
author | deepakjadmin |
---|---|
date | Thu, 15 Dec 2016 14:18:03 -0500 |
parents | 73ae111cf86f |
children |
line wrap: on
line source
<html> <head> <title>MayaChemTools:Documentation:Parsers::SimpleCalcParser.pm</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <link rel="stylesheet" type="text/css" href="../../css/MayaChemTools.css"> </head> <body leftmargin="20" rightmargin="20" topmargin="10" bottommargin="10"> <br/> <center> <a href="http://www.mayachemtools.org" title="MayaChemTools Home"><img src="../../images/MayaChemToolsLogo.gif" border="0" alt="MayaChemTools"></a> </center> <br/> <div class="DocNav"> <table width="100%" border=0 cellpadding=0 cellspacing=2> <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> </table> </div> <p> </p> <h2>NAME</h2> <p>Parsers::SimpleCalcParser</p> <p> </p> <h2>SYNOPSIS</h2> <p>use Parsers::SimpleCalcParser ;</p> <p>use Parsers::SimpleCalcParser qw(:all);</p> <p> </p> <h2>DESCRIPTION</h2> <p><strong>Parsers::SimpleCalcParser</strong> class provides the following methods:</p> <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> </p><p><strong>Parsers::SimpleCalcParse.yy</strong> parser grammer definition file implements a simple calculator and is provided to highlight usage of lexer capability available through <strong>Parsers::SimpleCalcYYLexer</strong>, which in turn uses <strong>Parsers::YYLexer</strong> and <strong>Parsers::Lexer</strong> classes to procide underlying lexer functionality.</p> <p>The parser package and token table files, <strong>Parsers::SimpleCalcParser.pm</strong> and <strong>SimpleCalcParser.tab.ph</strong>, are automatically generated from parser grammar definition file, <strong>Parsers::SimpleCalcParser.yy</strong>, using byacc available through perl-byacc1.8 modified with perl5-byacc-patches-0.5 for generation of object oriented parser:</p> <div class="OptionsBox"> byacc -l -P -d -b SimpleCalcParser SimpleCalcParser.yy <br/> mv SimpleCalcParser.tab.pl SimpleCalcParser.pm</div> <p> </p> <h2>METHODS</h2> <dl> <dt><strong><a name="new" class="item"><strong>new</strong></a></strong></dt> <dd> <div class="OptionsBox"> $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, \&Parsers::SimpleCalcParser::yyerror); <br/> $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, \&Parsers::SimpleCalcParser::yyerror, $Debug);</div> <p>Using specified <em>YYLex</em> <em>YYError</em> functions, <strong>new</strong> method generates a new <strong>SimpleCalcParser</strong> and returns a reference to newly created <strong>SimpleCalcYYParser</strong> object.</p> <p>Examples:</p> <div class="OptionsBox"> # Input string... <br/> $InputText = "3 + 4 +6\nx=3\ny=5\nx+y\nx+z\n"; <br/> $YYLexer = new Parsers::SimpleCalcYYLexer($InputText); <br/> $YYLex = $YYLexer->GetYYLex();</div> <div class="OptionsBox"> $Debug = 0; <br/> $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, \&Parsers::SimpleCalcParser::yyerror, $Debug); <br/> $Value = $SimpleCalcParser->yyparse(); <br/> print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n";</div> <div class="OptionsBox"> # Input file... <br/> $InputFile = "TestSimpleCalcParser.txt"; <br/> open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";</div> <div class="OptionsBox"> $YYLexer = new Parsers::SimpleCalcYYLexer(\*INPUTFILE); <br/> $YYLex = $YYLexer->GetYYLex();</div> <div class="OptionsBox"> $Debug = 0; <br/> $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, \&Parsers::SimpleCalcParser::yyerror, $Debug); <br/> $Value = $SimpleCalcParser->yyparse(); <br/> print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n";</div> <div class="OptionsBox"> close INPUTFILE;</div> <div class="OptionsBox"> # Input iterator... <br/> $InputFile = "TestSimpleCalcParser.txt"; <br/> open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n"; <br/> $InputIterator = sub { return <INPUTFILE>; };</div> <div class="OptionsBox"> $YYLexer = new Parsers::SimpleCalcYYLexer($InputIterator); <br/> $YYLex = $YYLexer->GetYYLex();</div> <div class="OptionsBox"> $Debug = 0; <br/> $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, \&Parsers::SimpleCalcParser::yyerror, $Debug); <br/> $Value = $SimpleCalcParser->yyparse(); <br/> print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n";</div> <div class="OptionsBox"> close INPUTFILE;</div> </dd> <dt><strong><a name="yyclearin" class="item"><strong>yyclearin</strong></a></strong></dt> <dd> <div class="OptionsBox"> $SimpleCalcParser->yyclearin();</div> <p><strong>yyclearin</strong> method clears any previous look-ahead token after encountering a syntax error during parsing. It can be used after <strong>yyerrok</strong> in a grammer rule with the reserved word <strong>error</strong>.</p> </dd> <dt><strong><a name="yyerrok" class="item"><strong>yyerrok</strong></a></strong></dt> <dd> <div class="OptionsBox"> $SimpleCalcParser->yyerrok();</div> <p><strong>yyerrok</strong> method is used with the reserved word <strong>error</strong> in grammer rule to indcate error recovery is complete after encountering a syntax error during parsing.</p> </dd> <dt><strong><a name="yyerror" class="item"><strong>yyerror</strong></a></strong></dt> <dd> <div class="OptionsBox"> $SimpleCalcParser->yyerror();</div> <p><strong>yyerror</strong> function is provided for the caller to use during initialization of a parser. It is used by <strong>yyparse</strong> to print any error messages encountered during parsing of the input.</p> </dd> <dt><strong><a name="yyparse" class="item"><strong>yyparse</strong></a></strong></dt> <dd> <div class="OptionsBox"> $Value = $SimpleCalcParser->yyparse();</div> <p>Returns <em>Value</em> after parsing all the input from a input stream using specified grammer rules.</p> </dd> </dl> <p> </p> <h2>AUTHOR</h2> <p><a href="mailto:msud@san.rr.com">Manish Sud</a></p> <p> </p> <h2>SEE ALSO</h2> <p><a href="./Lexer.html">Lexer.pm</a>, <a href="./YYLexer.html">YYLexer.pm</a>, <a href="./SimpleCalcYYLexer.html">SimpleCalcYYLexer.pm</a> </p> <p> </p> <h2>COPYRIGHT</h2> <p>Copyright (C) 2015 Manish Sud. All rights reserved.</p> <p>This file is part of MayaChemTools.</p> <p>MayaChemTools is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.</p> <p> </p><p> </p><div class="DocNav"> <table width="100%" border=0 cellpadding=0 cellspacing=2> <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> </table> </div> <br /> <center> <img src="../../images/h2o2.png"> </center> </body> </html>