comparison docs/modules/txt/SimpleCalcYYLexer.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::SimpleCalcYYLexer
3
4 SYNOPSIS
5 use Parsers::SimpleCalcYYLexer;
6
7 use Parsers::SimpleCalcYYLexer qw(:all);
8
9 DESCRIPTION
10 SimpleCalcYYLexer class provides the following methods:
11
12 new, YYLex, GetYYLex, StringifySimpleCalcYYLexer
13
14 Parser::SimpleCalcYYLexer class is derived from Parser::YYLexer class,
15 which in turn is derived from base class Parser::Lexer that provides all
16 the underlying lexer functionality. SimpleCalcYYLexer class is designed
17 to be used with yyparse code generated by running byacc on a parser
18 defined using parser definition SimpleCalcParser.yy file.
19
20 The parser package and token table files, SimpleCalcParser.pm and
21 SimpleCalcParser.tab.ph, are automatically generated from parser grammar
22 definition file, SimpleCalcParser.yy, using byacc available through
23 perl-byacc1.8 modified with perl5-byacc-patches-0.5 for generation of
24 object oriented parser:
25
26 byacc -l -P -d -b SimpleCalcParser SimpleCalcParser.yy
27 mv SimpleCalcParser.tab.pl SimpleCalcParser.pm
28
29 SimpleCalcYYLexer.pm class implements a lexer for a simple calculator
30 and is provided to highlight usasge of YYLex through yyparse.
31
32 The default specification of lexer tokens for SimpleCalcYYLexer.pm
33 includes:
34
35 @YYLexerTokensSpec = (
36 [ 'LETTER', qr/[a-zA-Z]/ ],
37 [ 'NUMBER', qr/\d+/ ],
38 [ 'SPACE', qr/[ ]*/,
39 sub { my($This, $TokenLabel, $MatchedText) = @_; return ''; }
40 ],
41 [ 'NEWLINE', qr/(?:\r\n|\r|\n)/,
42 sub { my($This, $TokenLabel, $MatchedText) = @_; return "\n"; }
43 ],
44 [ 'CHAR', qr/./ ]
45 );
46
47 The default SimpleCalcParser.tab.ph file containing token identifiers
48 for SimpleCalcParser.yy includes:
49
50 $NUMBER=257;
51 $LETTER=258;
52
53 METHODS
54 new
55 $SimpleCalcYYLexer = new Parsers::SimpleCalcYYLexer($Input);
56
57 Using specified *Input*, new method generates a new
58 SimpleCalcYYLexer and returns a reference to newly created
59 SimpleCalcYYLexer object.
60
61 Examples:
62
63 # Input string...
64 $InputText = "3 + 4 +6\nx=3\ny=5\nx+y\nx+z\n";
65
66 $YYLexer = new Parsers::SimpleCalcYYLexer($InputText);
67 $YYLex = $YYLexer->GetYYLex();
68
69 $Debug = 0;
70 $CalcParser = new Parsers::SimpleCalcParser($YYLex,
71 \&Parsers::SimpleCalcParser::yyerror, $Debug);
72 $Value = $SimpleCalcParser->yyparse();
73 print "Value: $Value\n";
74
75 # Input file...
76 $InputFile = "Input.txt";
77 open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";
78 $YYLexer = new Parsers::SimpleCalcYYLexer($InputFile);
79 $YYLex = $YYLexer->GetYYLex();
80
81 $CalcParser = new Parsers::SimpleCalcParser($YYLex,
82 \&Parsers::SimpleCalcParser::yyerror);
83 $Value = $SimpleCalcParser->yyparse();
84 print "Value: $Value\n";
85
86 # Input file iterator...
87 $InputFile = "TestSimpleCalcParser.txt";
88 open INPUTFILE, "$InputFile" or die "Couldn't open $InputFile: $!\n";
89 $InputIterator = sub { return <INPUTFILE>; };
90 $YYLexer = new Parsers::SimpleCalcYYLexer($InputIterator);
91 $YYLex = $YYLexer->GetYYLex();
92
93 $CalcParser = new Parsers::SimpleCalcParser($YYLex,
94 \&Parsers::SimpleCalcParser::yyerror);
95 $Value = $SimpleCalcParser->yyparse();
96 print "Value: $Value\n";
97
98 StringifySimpleCalcYYLexer
99 $YYLexerString = $YYLexer->StringifySimpleCalcYYLexer();
100
101 Returns a string containing information about *YYLexer* object.
102
103 AUTHOR
104 Manish Sud <msud@san.rr.com>
105
106 SEE ALSO
107 Lexer.pm, YYLexer.pm, SimpleCalcParser.yy
108
109 COPYRIGHT
110 Copyright (C) 2015 Manish Sud. All rights reserved.
111
112 This file is part of MayaChemTools.
113
114 MayaChemTools is free software; you can redistribute it and/or modify it
115 under the terms of the GNU Lesser General Public License as published by
116 the Free Software Foundation; either version 3 of the License, or (at
117 your option) any later version.
118