50 bool read_until(std::istream &ist,
const char *st);
70 int get_token(std::istream &ist, std::string &st,
71 bool ignore_cr =
true,
bool to_up =
true,
72 bool read_un_pm =
true,
int *linenb = 0);
76 skip(
const char *s_) : s(s_) {}
78 std::istream& operator>>(std::istream& is,
const skip& t);
83 int casecmp(
const char *a,
const char *b,
unsigned n=
unsigned(-1));
85 inline int casecmp(
const std::string& a,
const char *b,
86 unsigned n=
unsigned(-1))
87 {
return casecmp(a.c_str(),b,n); }
89 inline int casecmp(
const std::string& a,
const std::string& b,
90 unsigned n=
unsigned(-1))
91 {
return casecmp(a.c_str(), b.c_str(),n); }
93 inline int casecmp(
char a,
char b)
94 {
return toupper(a)<toupper(b) ? -1 : (toupper(a) == toupper(b) ? 0 : +1); }
131 typedef enum { REAL_VALUE, STRING_VALUE, ARRAY_VALUE } param_type;
136 std::string string_value;
137 std::vector<param_value> array_value;
140 param_type type_of_param()
const {
return pt; }
141 double &real() {
return real_value; }
142 double real()
const {
return real_value; }
143 std::string &string() {
return string_value; }
144 const std::string &string()
const {
return string_value; }
145 std::vector<param_value> &array() {
return array_value; }
146 const std::vector<param_value> &array()
const {
return array_value; }
147 param_value(
double e = 0.0) : pt(REAL_VALUE), real_value(e) {}
148 param_value(std::string s) : pt(STRING_VALUE), real_value(0.0),
150 param_value(
char *s) : pt(STRING_VALUE), real_value(0.0),
152 param_value(param_type p): pt(p), real_value(0.0) {}
157 std::map<std::string, param_value> parameters;
160 std::string current_file;
162 int get_next_token(std::istream &f);
164 std::string temp_string;
165 param_value read_expression_list(std::istream &f,
bool skipped);
166 param_value read_expression(std::istream &f,
bool skipped);
167 int read_instruction_list(std::istream &f,
bool sk =
false);
168 int read_instruction(std::istream &f,
bool sk =
false);
169 void parse_error(
const std::string &t);
170 void syntax_error(
const std::string &t);
171 void do_bin_op(std::vector<md_param::param_value> &value_list,
172 std::vector<int> &op_list, std::vector<int> &prior_list);
176 double real_value(
const std::string &name,
const char *comment = 0,
177 double default_val=0.);
178 long int_value(
const std::string &name,
const char *comment = 0,
180 const std::string &string_value(
const std::string &name,
181 const char *comment = 0,
182 const std::string &default_val=
"");
183 const std::vector<param_value> &array_value(
const std::string &name,
184 const char *comment = 0);
185 void add_int_param(
const std::string &name,
long e)
186 { parameters[name] = param_value(
double(e)); }
187 void add_real_param(
const std::string &name,
double e)
188 { parameters[name] = param_value(e); }
189 void add_string_param(
const std::string &name,
const std::string &s)
190 { parameters[name] = param_value(s); }
194 void read_param_file(std::istream &f);
200 void read_command_line(
int argc,
char *argv[]);
210 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...