00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef EXTENDED_REGULAR_EXPRESSIONERE_DUPS_H
00021 #define EXTENDED_REGULAR_EXPRESSIONERE_DUPS_H
00022
00023 namespace extended_regular_expression {
00024
00043 template< typename E >
00044 class ere_dups
00045 {
00046 typedef typename grammar_to_parser::basic_parser<E>::parser_list
00047 parser_list;
00048
00049 unsigned long m_rep;
00050 class dup_and_dup_branch
00051 {
00052 grammar_to_parser::basic_choice<E,ere_dupl_symbol<E> >
00053 m_dup;
00054 grammar_to_parser::basic_choice<E,ere_dups<E> > m_dups;
00055
00056 public:
00057 void push_parsers( parser_list& l )
00058 {
00059 l.push_back( &m_dup );
00060 l.push_back( &m_dups );
00061 }
00062
00063 unsigned long get_max()
00064 {
00065 double max = m_dup->get_max();
00066 if( max == INT_MAX )
00067 return INT_MAX;
00068
00069 double max_from_branch = m_dups->get_max();
00070 if( max_from_branch == INT_MAX )
00071 return INT_MAX;
00072
00073 max = max * max_from_branch;
00074 if( max >= INT_MAX )
00075 return INT_MAX;
00076
00077 return (unsigned long)max;
00078 }
00079
00080 bool is_lazy()
00081 {
00082 return (m_dup.is_parsed() && m_dup->is_lazy()) ||
00083 (m_dups.is_parsed() && m_dups->is_lazy());
00084 }
00085
00086 unsigned long get_min()
00087 {
00088 return m_dup->get_min() * m_dups->get_min();
00089 }
00090 };
00091
00092 grammar_to_parser::basic_non_terminal<E, dup_and_dup_branch >
00093 m_dup_and_dups;
00094 grammar_to_parser::basic_choice<E,ere_dupl_symbol<E> >
00095 m_dup;
00096
00097 public:
00098
00099 bool is_lazy()
00100 {
00101 return (m_dup_and_dups.is_parsed() && m_dup_and_dups->is_lazy()) ||
00102 (m_dup.is_parsed() && m_dup->is_lazy());
00103 }
00104
00105 void push_parsers( parser_list& l )
00106 {
00107 l.push_back( &m_dup_and_dups );
00108 l.push_back( &m_dup );
00109 }
00110
00111 void set_recognized_dup( unsigned long rec_dup )
00112 {
00113 m_rep = rec_dup;
00114 }
00115
00116 unsigned long get_recognized_dup()
00117 {
00118 return m_rep;
00119 }
00120
00121 unsigned long get_max()
00122 {
00123 if( m_dup_and_dups.is_parsed() )
00124 return m_dup_and_dups->get_max();
00125 else
00126 return m_dup->get_max();
00127 }
00128
00129 unsigned long get_min()
00130 {
00131 if( m_dup_and_dups.is_parsed() )
00132 return m_dup_and_dups->get_min();
00133 else
00134 return m_dup->get_min();
00135 }
00136
00137 ere_dups() : m_rep(0) {};
00138 ~ere_dups() {};
00139 };
00140
00141 };
00142
00143 #endif