0
|
1 <html>
|
|
2 <head>
|
|
3 <title>MayaChemTools:Documentation:Parsers::SimpleCalcYYLexer.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="./SimpleCalcParser.html" title="SimpleCalcParser.html">Previous</a> <a href="./index.html" title="Table of Contents">TOC</a> <a href="./YYLexer.html" title="YYLexer.html">Next</a></td><td width="34%" align="middle"><strong>Parsers::SimpleCalcYYLexer.pm</strong></td><td width="33%" align="right"><a href="././code/SimpleCalcYYLexer.html" title="View source code">Code</a> | <a href="./../pdf/SimpleCalcYYLexer.pdf" title="PDF US Letter Size">PDF</a> | <a href="./../pdfgreen/SimpleCalcYYLexer.pdf" title="PDF US Letter Size with narrow margins: www.changethemargins.com">PDFGreen</a> | <a href="./../pdfa4/SimpleCalcYYLexer.pdf" title="PDF A4 Size">PDFA4</a> | <a href="./../pdfa4green/SimpleCalcYYLexer.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::SimpleCalcYYLexer</p>
|
|
22 <p>
|
|
23 </p>
|
|
24 <h2>SYNOPSIS</h2>
|
|
25 <p>use Parsers::SimpleCalcYYLexer;</p>
|
|
26 <p>use Parsers::SimpleCalcYYLexer qw(:all);</p>
|
|
27 <p>
|
|
28 </p>
|
|
29 <h2>DESCRIPTION</h2>
|
|
30 <p><strong>SimpleCalcYYLexer</strong> class provides the following methods:</p>
|
|
31 <p> <a href="#new">new</a>, <a href="#yylex">YYLex</a>, <a href="#getyylex">GetYYLex</a>, <a href="#stringifysimplecalcyylexer">StringifySimpleCalcYYLexer</a>
|
|
32 </p><p><strong>Parser::SimpleCalcYYLexer</strong> class is derived from <strong>Parser::YYLexer</strong> class, which in
|
|
33 turn is derived from base class <strong>Parser::Lexer</strong> that provides all the underlying
|
|
34 lexer functionality. <strong>SimpleCalcYYLexer</strong> class is designed to be used with
|
|
35 <strong>yyparse</strong> code generated by running <strong>byacc</strong> on a parser defined using
|
|
36 parser definition <strong>SimpleCalcParser.yy</strong> file.</p>
|
|
37 <p>The parser package and token table files, <strong>SimpleCalcParser.pm</strong> and <strong>SimpleCalcParser.tab.ph</strong>,
|
|
38 are automatically generated from parser grammar definition file, <strong>SimpleCalcParser.yy</strong>, using
|
|
39 byacc available through perl-byacc1.8 modified with perl5-byacc-patches-0.5 for generation
|
|
40 of object oriented parser:</p>
|
|
41 <div class="OptionsBox">
|
|
42 byacc -l -P -d -b SimpleCalcParser SimpleCalcParser.yy
|
|
43 <br/> mv SimpleCalcParser.tab.pl SimpleCalcParser.pm</div>
|
|
44 <p><strong>SimpleCalcYYLexer.pm</strong> class implements a lexer for a simple calculator and is provided
|
|
45 to highlight usasge of <strong>YYLex</strong> through <strong>yyparse</strong>.</p>
|
|
46 <p>The default specification of lexer tokens for <strong>SimpleCalcYYLexer.pm</strong> includes:</p>
|
|
47 <div class="OptionsBox">
|
|
48 @YYLexerTokensSpec = (
|
|
49 <br/> [ 'LETTER', qr/[a-zA-Z]/ ],
|
|
50 [ 'NUMBER', qr/\d+/ ],
|
|
51 [ 'SPACE', qr/[ ]*/,
|
|
52 <br/> sub { my($This, $TokenLabel, $MatchedText) = @_; return ''; }
|
|
53 <br/> ],
|
|
54 [ 'NEWLINE', qr/(?:\r\n|\r|\n)/,
|
|
55 <br/> sub { my($This, $TokenLabel, $MatchedText) = @_; return "\n"; }
|
|
56 <br/> ],
|
|
57 [ 'CHAR', qr/./ ]
|
|
58 <br/> );</div>
|
|
59 <p>The default <strong>SimpleCalcParser.tab.ph</strong> file containing token identifiers for
|
|
60 <strong>SimpleCalcParser.yy</strong> includes:</p>
|
|
61 <div class="OptionsBox">
|
|
62 $NUMBER=257;
|
|
63 <br/> $LETTER=258;</div>
|
|
64 <p>
|
|
65 </p>
|
|
66 <h2>METHODS</h2>
|
|
67 <dl>
|
|
68 <dt><strong><a name="new" class="item"><strong>new</strong></a></strong></dt>
|
|
69 <dd>
|
|
70 <div class="OptionsBox">
|
|
71 $SimpleCalcYYLexer = new Parsers::SimpleCalcYYLexer($Input);</div>
|
|
72 <p>Using specified <em>Input</em>, <strong>new</strong> method generates a new <strong>SimpleCalcYYLexer</strong>
|
|
73 and returns a reference to newly created <strong>SimpleCalcYYLexer</strong> object.</p>
|
|
74 <p>Examples:</p>
|
|
75 <div class="OptionsBox">
|
|
76 # Input string...
|
|
77 <br/> $InputText = "3 + 4 +6\nx=3\ny=5\nx+y\nx+z\n";</div>
|
|
78 <div class="OptionsBox">
|
|
79 $YYLexer = new Parsers::SimpleCalcYYLexer($InputText);
|
|
80 <br/> $YYLex = $YYLexer->GetYYLex();</div>
|
|
81 <div class="OptionsBox">
|
|
82 $Debug = 0;
|
|
83 <br/> $CalcParser = new Parsers::SimpleCalcParser($YYLex,
|
|
84 \&Parsers::SimpleCalcParser::yyerror, $Debug);
|
|
85 <br/> $Value = $SimpleCalcParser->yyparse();
|
|
86 <br/> print "Value: $Value\n";</div>
|
|
87 <div class="OptionsBox">
|
|
88 # Input file...
|
|
89 <br/> $InputFile = "Input.txt";
|
|
90 <br/> open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";
|
|
91 <br/> $YYLexer = new Parsers::SimpleCalcYYLexer($InputFile);
|
|
92 <br/> $YYLex = $YYLexer->GetYYLex();</div>
|
|
93 <div class="OptionsBox">
|
|
94 $CalcParser = new Parsers::SimpleCalcParser($YYLex,
|
|
95 \&Parsers::SimpleCalcParser::yyerror);
|
|
96 <br/> $Value = $SimpleCalcParser->yyparse();
|
|
97 <br/> print "Value: $Value\n";</div>
|
|
98 <div class="OptionsBox">
|
|
99 # Input file iterator...
|
|
100 <br/> $InputFile = "TestSimpleCalcParser.txt";
|
|
101 <br/> open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";
|
|
102 <br/> $InputIterator = sub { return <INPUTFILE>; };
|
|
103 <br/> $YYLexer = new Parsers::SimpleCalcYYLexer($InputIterator);
|
|
104 <br/> $YYLex = $YYLexer->GetYYLex();</div>
|
|
105 <div class="OptionsBox">
|
|
106 $CalcParser = new Parsers::SimpleCalcParser($YYLex,
|
|
107 \&Parsers::SimpleCalcParser::yyerror);
|
|
108 <br/> $Value = $SimpleCalcParser->yyparse();
|
|
109 <br/> print "Value: $Value\n";</div>
|
|
110 </dd>
|
|
111 <dt><strong><a name="stringifysimplecalcyylexer" class="item"><strong>StringifySimpleCalcYYLexer</strong></a></strong></dt>
|
|
112 <dd>
|
|
113 <div class="OptionsBox">
|
|
114 $YYLexerString = $YYLexer->StringifySimpleCalcYYLexer();</div>
|
|
115 <p>Returns a string containing information about <em>YYLexer</em> object.</p>
|
|
116 </dd>
|
|
117 </dl>
|
|
118 <p>
|
|
119 </p>
|
|
120 <h2>AUTHOR</h2>
|
|
121 <p><a href="mailto:msud@san.rr.com">Manish Sud</a></p>
|
|
122 <p>
|
|
123 </p>
|
|
124 <h2>SEE ALSO</h2>
|
|
125 <p><a href="./Lexer.html">Lexer.pm</a>, <a href="./YYLexer.html">YYLexer.pm</a>, <a href="./SimpleCalcParser.html">SimpleCalcParser.yy</a>
|
|
126 </p>
|
|
127 <p>
|
|
128 </p>
|
|
129 <h2>COPYRIGHT</h2>
|
|
130 <p>Copyright (C) 2015 Manish Sud. All rights reserved.</p>
|
|
131 <p>This file is part of MayaChemTools.</p>
|
|
132 <p>MayaChemTools is free software; you can redistribute it and/or modify it under
|
|
133 the terms of the GNU Lesser General Public License as published by the Free
|
|
134 Software Foundation; either version 3 of the License, or (at your option)
|
|
135 any later version.</p>
|
|
136 <p> </p><p> </p><div class="DocNav">
|
|
137 <table width="100%" border=0 cellpadding=0 cellspacing=2>
|
|
138 <tr align="left" valign="top"><td width="33%" align="left"><a href="./SimpleCalcParser.html" title="SimpleCalcParser.html">Previous</a> <a href="./index.html" title="Table of Contents">TOC</a> <a href="./YYLexer.html" title="YYLexer.html">Next</a></td><td width="34%" align="middle"><strong>March 29, 2015</strong></td><td width="33%" align="right"><strong>Parsers::SimpleCalcYYLexer.pm</strong></td></tr>
|
|
139 </table>
|
|
140 </div>
|
|
141 <br />
|
|
142 <center>
|
|
143 <img src="../../images/h2o2.png">
|
|
144 </center>
|
|
145 </body>
|
|
146 </html>
|