51 bool read_until(std::istream &ist,
const char *st);
71 int get_token(std::istream &ist, std::string &st,
72 bool ignore_cr =
true,
bool to_up =
true,
73 bool read_un_pm =
true,
int *linenb = 0);
77 skip(
const char *s_) : s(s_) {}
79 std::istream& operator>>(std::istream& is,
const skip& t);
84 int casecmp(
const char *a,
const char *b,
unsigned n=
unsigned(-1));
86 inline int casecmp(
const std::string& a,
const char *b,
87 unsigned n=
unsigned(-1))
88 {
return casecmp(a.c_str(),b,n); }
90 inline int casecmp(
const std::string& a,
const std::string& b,
91 unsigned n=
unsigned(-1))
92 {
return casecmp(a.c_str(), b.c_str(),n); }
94 inline int casecmp(
char a,
char b)
95 {
return toupper(a)<toupper(b) ? -1 : (toupper(a) == toupper(b) ? 0 : +1); }
132 typedef enum { REAL_VALUE, STRING_VALUE, ARRAY_VALUE } param_type;
137 std::string string_value;
138 std::vector<param_value> array_value;
141 param_type type_of_param()
const {
return pt; }
142 double &real() {
return real_value; }
143 double real()
const {
return real_value; }
144 std::string &string() {
return string_value; }
145 const std::string &string()
const {
return string_value; }
146 std::vector<param_value> &array() {
return array_value; }
147 const std::vector<param_value> &array()
const {
return array_value; }
148 param_value(
double e = 0.0) : pt(REAL_VALUE), real_value(e) {}
149 param_value(std::string s) : pt(STRING_VALUE), real_value(0.0),
151 param_value(
char *s) : pt(STRING_VALUE), real_value(0.0),
153 param_value(param_type p): pt(p), real_value(0.0) {}
158 std::map<std::string, param_value> parameters;
161 std::string current_file;
163 int get_next_token(std::istream &f);
165 std::string temp_string;
166 param_value read_expression_list(std::istream &f,
bool skipped);
167 param_value read_expression(std::istream &f,
bool skipped);
168 int read_instruction_list(std::istream &f,
bool sk =
false);
169 int read_instruction(std::istream &f,
bool sk =
false);
170 void parse_error(
const std::string &t);
171 void syntax_error(
const std::string &t);
172 void do_bin_op(std::vector<md_param::param_value> &value_list,
173 std::vector<int> &op_list, std::vector<int> &prior_list);
177 double real_value(
const std::string &name,
const char *comment = 0,
178 double default_val=0.);
179 long int_value(
const std::string &name,
const char *comment = 0,
181 const std::string &string_value(
const std::string &name,
182 const char *comment = 0,
183 const std::string &default_val=
"");
184 const std::vector<param_value> &array_value(
const std::string &name,
185 const char *comment = 0);
186 void add_int_param(
const std::string &name,
long e)
187 { parameters[name] = param_value(
double(e)); }
188 void add_real_param(
const std::string &name,
double e)
189 { parameters[name] = param_value(e); }
190 void add_string_param(
const std::string &name,
const std::string &s)
191 { parameters[name] = param_value(s); }
195 void read_param_file(std::istream &f);
201 void read_command_line(
int argc,
char *argv[]);
211 using bgeot::md_param;
int get_token(std::istream &ist, std::string &st, bool ignore_cr, bool to_up, bool read_un_pm, int *linenb)
Very simple lexical analysis of general interest for reading small languages with a "MATLAB like" syn...