Mercurial > repos > deepakjadmin > mayatool3_test2
comparison docs/modules/txt/SimpleCalcParser.txt @ 0:4816e4a8ae95 draft default tip
Uploaded
author | deepakjadmin |
---|---|
date | Wed, 20 Jan 2016 09:23:18 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4816e4a8ae95 |
---|---|
1 NAME | |
2 Parsers::SimpleCalcParser | |
3 | |
4 SYNOPSIS | |
5 use Parsers::SimpleCalcParser ; | |
6 | |
7 use Parsers::SimpleCalcParser qw(:all); | |
8 | |
9 DESCRIPTION | |
10 Parsers::SimpleCalcParser class provides the following methods: | |
11 | |
12 new, yyclearin, yyerrok, yyerror, yyparse | |
13 | |
14 Parsers::SimpleCalcParse.yy parser grammer definition file implements a | |
15 simple calculator and is provided to highlight usage of lexer capability | |
16 available through Parsers::SimpleCalcYYLexer, which in turn uses | |
17 Parsers::YYLexer and Parsers::Lexer classes to procide underlying lexer | |
18 functionality. | |
19 | |
20 The parser package and token table files, Parsers::SimpleCalcParser.pm | |
21 and SimpleCalcParser.tab.ph, are automatically generated from parser | |
22 grammar definition file, Parsers::SimpleCalcParser.yy, using byacc | |
23 available through perl-byacc1.8 modified with perl5-byacc-patches-0.5 | |
24 for generation of object oriented parser: | |
25 | |
26 byacc -l -P -d -b SimpleCalcParser SimpleCalcParser.yy | |
27 mv SimpleCalcParser.tab.pl SimpleCalcParser.pm | |
28 | |
29 METHODS | |
30 new | |
31 $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, | |
32 \&Parsers::SimpleCalcParser::yyerror); | |
33 $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, | |
34 \&Parsers::SimpleCalcParser::yyerror, $Debug); | |
35 | |
36 Using specified *YYLex* *YYError* functions, new method generates a | |
37 new SimpleCalcParser and returns a reference to newly created | |
38 SimpleCalcYYParser object. | |
39 | |
40 Examples: | |
41 | |
42 # Input string... | |
43 $InputText = "3 + 4 +6\nx=3\ny=5\nx+y\nx+z\n"; | |
44 $YYLexer = new Parsers::SimpleCalcYYLexer($InputText); | |
45 $YYLex = $YYLexer->GetYYLex(); | |
46 | |
47 $Debug = 0; | |
48 $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, | |
49 \&Parsers::SimpleCalcParser::yyerror, $Debug); | |
50 $Value = $SimpleCalcParser->yyparse(); | |
51 print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n"; | |
52 | |
53 # Input file... | |
54 $InputFile = "TestSimpleCalcParser.txt"; | |
55 open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n"; | |
56 | |
57 $YYLexer = new Parsers::SimpleCalcYYLexer(\*INPUTFILE); | |
58 $YYLex = $YYLexer->GetYYLex(); | |
59 | |
60 $Debug = 0; | |
61 $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, | |
62 \&Parsers::SimpleCalcParser::yyerror, $Debug); | |
63 $Value = $SimpleCalcParser->yyparse(); | |
64 print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n"; | |
65 | |
66 close INPUTFILE; | |
67 | |
68 # Input iterator... | |
69 $InputFile = "TestSimpleCalcParser.txt"; | |
70 open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n"; | |
71 $InputIterator = sub { return <INPUTFILE>; }; | |
72 | |
73 $YYLexer = new Parsers::SimpleCalcYYLexer($InputIterator); | |
74 $YYLex = $YYLexer->GetYYLex(); | |
75 | |
76 $Debug = 0; | |
77 $SimpleCalcParser = new Parsers::SimpleCalcParser($YYLex, | |
78 \&Parsers::SimpleCalcParser::yyerror, $Debug); | |
79 $Value = $SimpleCalcParser->yyparse(); | |
80 print "Value = " . (defined($Value) ? "$Value" : "Undefined") . "\n"; | |
81 | |
82 close INPUTFILE; | |
83 | |
84 yyclearin | |
85 $SimpleCalcParser->yyclearin(); | |
86 | |
87 yyclearin method clears any previous look-ahead token after | |
88 encountering a syntax error during parsing. It can be used after | |
89 yyerrok in a grammer rule with the reserved word error. | |
90 | |
91 yyerrok | |
92 $SimpleCalcParser->yyerrok(); | |
93 | |
94 yyerrok method is used with the reserved word error in grammer rule | |
95 to indcate error recovery is complete after encountering a syntax | |
96 error during parsing. | |
97 | |
98 yyerror | |
99 $SimpleCalcParser->yyerror(); | |
100 | |
101 yyerror function is provided for the caller to use during | |
102 initialization of a parser. It is used by yyparse to print any error | |
103 messages encountered during parsing of the input. | |
104 | |
105 yyparse | |
106 $Value = $SimpleCalcParser->yyparse(); | |
107 | |
108 Returns *Value* after parsing all the input from a input stream | |
109 using specified grammer rules. | |
110 | |
111 AUTHOR | |
112 Manish Sud <msud@san.rr.com> | |
113 | |
114 SEE ALSO | |
115 Lexer.pm, YYLexer.pm, SimpleCalcYYLexer.pm | |
116 | |
117 COPYRIGHT | |
118 Copyright (C) 2015 Manish Sud. All rights reserved. | |
119 | |
120 This file is part of MayaChemTools. | |
121 | |
122 MayaChemTools is free software; you can redistribute it and/or modify it | |
123 under the terms of the GNU Lesser General Public License as published by | |
124 the Free Software Foundation; either version 3 of the License, or (at | |
125 your option) any later version. | |
126 |