00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NUMBER_H
00021 #define NUMBER_H
00022
00023
00024 template< class digit_choice, char prefix='x' >
00025 class number
00026 {
00027 public:
00028 grammar_to_parser::terminal<'0'> m_0;
00029 grammar_to_parser::terminal<prefix> m_prefix;
00030
00031
00032 class digits
00033 {
00034 class digit_and_digits
00035 {
00036 grammar_to_parser::choice< digit_choice > m_digit;
00037 grammar_to_parser::choice< digits > m_digits;
00038 public:
00039 void push_parsers( grammar_to_parser::parsers& l )
00040 {
00041 l.push_back( &m_digit );
00042 l.push_back( &m_digits );
00043 }
00044 unsigned long evaluate( unsigned long value, unsigned long &pow )
00045 {
00046 value = m_digits->evaluate( value, pow );
00047 pow = pow*m_digit->get_base();
00048 value += pow*m_digit->evaluate();
00049 return value;
00050 }
00051
00052 };
00053 grammar_to_parser::non_terminal<digit_and_digits>
00054 m_digit_and_digits;
00055 grammar_to_parser::choice<digit_choice> m_digit;
00056 public:
00057 void push_parsers( grammar_to_parser::parsers &l )
00058 {
00059 l.push_back( &m_digit_and_digits );
00060 l.push_back( &m_digit );
00061 }
00062 unsigned long evaluate( unsigned long value, unsigned long &pow )
00063 {
00064 if( m_digit.is_parsed() )
00065 {
00066 value = m_digit->evaluate();
00067 pow = 1;
00068 return value;
00069 }
00070 else
00071 {
00072 return m_digit_and_digits->evaluate( value, pow );
00073 }
00074 }
00075 };
00076 grammar_to_parser::choice<digits> m_digits;
00077 public:
00078 void push_parsers( grammar_to_parser::parsers &l )
00079 {
00080 l.push_back( &m_0 );
00081 l.push_back( &m_prefix );
00082 l.push_back( &m_digits );
00083 }
00084 unsigned long evaluate()
00085 {
00086 unsigned long value=0;
00087 unsigned long pow=0;
00088 return m_digits->evaluate( value, pow );
00089 }
00090 };
00091
00092 #endif