00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX
00019
00020 # include <sstream>
00021 # include <limits.h>
00022
00023 # include <vaucanson/algebra/implementation/letter/int_letter.hh>
00024
00025 namespace vcsn {
00026
00027 namespace algebra {
00028
00029 template <>
00030 struct letter_traits<int>
00031 {
00032
00033 typedef misc::false_t is_char_letter;
00034
00035 enum
00036 {
00037
00038
00039 cardinal = UINT_MAX
00040 };
00041
00042 LETTER_DEFAULT(open_par, "(")
00043 LETTER_DEFAULT(close_par, ")")
00044 LETTER_DEFAULT(plus, "+")
00045 LETTER_DEFAULT(times, ".")
00046 LETTER_DEFAULT(star, "*")
00047 LETTER_DEFAULT(epsilon, "e")
00048 LETTER_DEFAULT(zero, "z")
00049 LETTER_DEFAULT(open_weight, "{")
00050 LETTER_DEFAULT(close_weight, "}")
00051 LETTER_DEFAULT(space, " ")
00052
00053 static
00054 int
00055 literal_to_letter(const std::string& str)
00056 {
00057 std::stringstream sstr(str);
00058 int ret;
00059 sstr >> ret;
00060 return ret;
00061 }
00062
00063 static
00064 std::string
00065 letter_to_literal(const int& c)
00066 {
00067 std::stringstream sstr;
00068 sstr << c;
00069 return sstr.str();
00070 }
00071 };
00072
00073 template <typename S, typename CharContainer>
00074 bool op_parse(const algebra::FreeMonoidBase<S>& set,
00075 std::basic_string<int>& v,
00076 const std::string& s,
00077 typename std::string::const_iterator& i,
00078 const CharContainer&)
00079 {
00080 typename std::string::const_iterator j = i;
00081 typename std::string::const_iterator k;
00082 typename std::string::const_iterator back;
00083
00084 while (i != s.end()) {
00085 std::string out;
00086 back = i;
00087
00088 while ((i != s.end()) && (((*i >= '0') && (*i <= '9'))) || (*i == '#'))
00089 if (*i == '#') {
00090 ++i;
00091 break;
00092 }
00093 else {
00094 out += *i;
00095 ++i;
00096 }
00097
00098 int value;
00099 std::istringstream is(out);
00100 is >> value;
00101 if (!set.alphabet().contains(value)) {
00102 i = back;
00103 break ;
00104 }
00105 v.push_back(value);
00106 }
00107 return (i != j);
00108 }
00109
00110 } // ! algebra
00111
00112 } // ! vcsn
00113
00114 namespace std {
00115
00116 inline
00117 ostream& operator<<(ostream& o, basic_string<int> s)
00118 {
00119 basic_string<int>::const_iterator i;
00120 basic_string<int>::const_iterator j;
00121
00122 for (i = s.begin(); i != s.end(); ) {
00123 o << *i;
00124 i++;
00125 if (i != s.end())
00126 o << "#";
00127 }
00128
00129 return o;
00130 }
00131
00132 } // ! std
00133
00134 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_LETTER_INT_LETTER_HXX