Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

binary_converter.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004-2006 by Radko Mihal                                *
00003  *   rmihal@pobox.sk                                                       *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
00019  ***************************************************************************/
00020 #ifndef BINARY_CONVERTER_H
00021 #define BINARY_CONVERTER_H
00022 
00023 class c_N
00024 {
00025 typedef grammar_to_parser::parsers parser_list;
00026         class c_1N
00027         {
00028                 grammar_to_parser::terminal<'1'>        m_1;
00029                 grammar_to_parser::choice<c_N>          m_N;
00030         public:
00031                 void push_parsers( parser_list &l )
00032                 {
00033                         l.push_back(&m_1);
00034                         l.push_back(&m_N);
00035                 }
00036                 unsigned long evaluate( unsigned long value, unsigned long &exp )
00037                 {
00038                         value = m_N->evaluate( value, exp );
00039                         exp = exp * 2;
00040                         value += exp * 1;
00041                         return value;
00042                 }
00043                 
00044         };
00045         class c_0N
00046         {
00047                 grammar_to_parser::terminal<'0'>        m_0;
00048                 grammar_to_parser::choice<c_N>          m_N;
00049         public:
00050                 void push_parsers( parser_list &l )
00051                 {
00052                         l.push_back(&m_0);
00053                         l.push_back(&m_N);
00054                 }
00055                 unsigned long evaluate( unsigned long value, unsigned long &exp )
00056                 {
00057                         value = m_N->evaluate( value, exp );
00058                         exp = exp * 2;
00059                         value += exp * 0;
00060                         return value;
00061                 }
00062         };
00063         grammar_to_parser::non_terminal<c_1N>           m_1N;
00064         grammar_to_parser::non_terminal<c_0N>           m_0N;
00065         grammar_to_parser::terminal<'1'>                        m_1;
00066         grammar_to_parser::terminal<'0'>                        m_0;
00067 public:
00068         void push_parsers( parser_list &l )
00069         {
00070                 l.push_back(&m_1N);
00071                 l.push_back(&m_0N);
00072                 l.push_back(&m_1);
00073                 l.push_back(&m_0);
00074         }
00075         unsigned long evaluate( unsigned long value, unsigned long &exp )
00076         {
00077                 if( m_1N.is_parsed() ) return m_1N->evaluate( value, exp );
00078                 if( m_0N.is_parsed() ) return m_0N->evaluate( value, exp );
00079                 if( m_1.is_parsed() ) return 1;
00080                 if( m_0.is_parsed() ) return 0;
00081                 return 0;
00082         }
00083 };
00084 
00085 #endif

Generated on Sun Jul 2 18:39:42 2006 for grammar2parser.kdevelop by  doxygen 1.4.1