1 package Parsers::SimpleCalcYYLexer; 2 # 3 # $RCSfile: SimpleCalcYYLexer.pm,v $ 4 # $Date: 2015/02/28 20:50:55 $ 5 # $Revision: 1.9 $ 6 # 7 # Author: Manish Sud <msud@san.rr.com> 8 # 9 # Copyright (C) 2015 Manish Sud. All rights reserved. 10 # 11 # This file is part of MayaChemTools. 12 # 13 # MayaChemTools is free software; you can redistribute it and/or modify it under 14 # the terms of the GNU Lesser General Public License as published by the Free 15 # Software Foundation; either version 3 of the License, or (at your option) any 16 # later version. 17 # 18 # MayaChemTools is distributed in the hope that it will be useful, but without 19 # any warranty; without even the implied warranty of merchantability of fitness 20 # for a particular purpose. See the GNU Lesser General Public License for more 21 # details. 22 # 23 # You should have received a copy of the GNU Lesser General Public License 24 # along with MayaChemTools; if not, see <http://www.gnu.org/licenses/> or 25 # write to the Free Software Foundation Inc., 59 Temple Place, Suite 330, 26 # Boston, MA, 02111-1307, USA. 27 # 28 29 use strict; 30 use Carp; 31 use Exporter; 32 use Scalar::Util (); 33 use Parsers::YYLexer; 34 35 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); 36 37 @ISA = qw(Parsers::YYLexer Exporter); 38 @EXPORT = qw(); 39 @EXPORT_OK = qw(); 40 41 %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]); 42 43 # Setup class variables... 44 my($ClassName, $YYTabFile, @YYLexerTokensSpec); 45 _InitializeClass(); 46 47 # Overload Perl functions... 48 use overload '""' => 'StringifySimpleCalcYYLexer'; 49 50 # Class constructor... 51 sub new { 52 my($Class, $Input) = @_; 53 my(@TokensSpec); 54 55 # Initialize object... 56 my $This = $Class->SUPER::new($Input, @YYLexerTokensSpec); 57 bless $This, ref($Class) || $Class; 58 $This->_InitializeYYLexer(); 59 60 return $This; 61 } 62 63 # Initialize object data... 64 # 65 sub _InitializeYYLexer { 66 my($This) = @_; 67 68 # Setup default YYTabFile containing mapping of token names to numbers... 69 $This->SetupYYTabFile($YYTabFile); 70 71 return $This; 72 } 73 74 # Initialize class ... 75 sub _InitializeClass { 76 #Class name... 77 $ClassName = __PACKAGE__; 78 79 # Setup default token table file... 80 $YYTabFile = "Parsers/SimpleCalcParser.tab.ph"; 81 82 # Setup default lexer tokens specs... 83 @YYLexerTokensSpec = ( 84 [ 'LETTER', qr/[a-zA-Z]/ ], 85 [ 'NUMBER', qr/\d+/ ], 86 [ 'SPACE', qr/[ ]*/, sub { my($This, $TokenLabel, $MatchedText) = @_; return ''; } ], 87 [ 'NEWLINE', qr/(?:\r\n|\r|\n)/, sub { my($This, $TokenLabel, $MatchedText) = @_; return "\n"; } ], 88 [ 'CHAR', qr/./ ] 89 ); 90 } 91 92 # Is it a lexer object? 93 sub _IsSimpleCalcYYLexer { 94 my($Object) = @_; 95 96 return (Scalar::Util::blessed($Object) && $Object->isa($ClassName)) ? 1 : 0; 97 } 98 99 # Return a string containing information about lexer... 100 sub StringifySimpleCalcYYLexer { 101 my($This) = @_; 102 my($SimleCalcYYLexerString); 103 104 $SimleCalcYYLexerString = "SimpleCalcYYLexer: PackageName: $ClassName; " . $This->_GetYYLexerInfoString(); 105 106 return $SimleCalcYYLexerString; 107 } 108