00001
00007 #ifndef DIVINE_DVE_PARSER
00008 #define DIVINE_DVE_PARSER
00009
00010 #ifndef DOXYGEN_PROCESSING
00011 #include <vector>
00012 #include <list>
00013 #include <stack>
00014 #include <cstdio>
00015 #include <string>
00016 #include "common/error.hh"
00017 #include "common/bit_string.hh"
00018 #include "common/array.hh"
00019 #include "system/dve/dve_expression.hh"
00020 #include "system/dve/dve_transition.hh"
00021 #include "system/dve/dve_prob_transition.hh"
00022 #include "system/dve/dve_process.hh"
00023 #include "system/dve/syntax_analysis/dve_symbol.hh"
00024 #include "system/dve/syntax_analysis/dve_symbol_table.hh"
00025 #include "system/dve/syntax_analysis/dve_commonparse.hh"
00026 #include "system/dve/dve_prob_process.hh"
00027 #include "common/array.hh"
00028 #include "system/dve/dve_system.hh"
00029
00030 namespace divine {
00031 using std::cerr; using std::endl;
00032 #endif //DOXYGEN_PROCESSING
00033
00035 const size_int_t DVE_MAX_ARRAY_SIZE = 2147483647;
00036
00037 class dve_system_t;
00038 class dve_prob_process_t;
00039 class dve_prob_transition_t;
00040
00042
00045 class dve_parser_t {
00046 public:
00048
00051 enum parser_mode_t { SYSTEM,
00052 PROCESS,
00053 PROB_TRANSITION,
00054 TRANSITION,
00055 EXPRESSION
00056 };
00058 dve_parser_t(error_vector_t & evect, dve_system_t * my_system);
00060 dve_parser_t(error_vector_t & evect, dve_process_t * my_process);
00062 dve_parser_t(error_vector_t & evect, dve_prob_process_t * my_process);
00064 dve_parser_t(error_vector_t & evect, dve_transition_t * my_transition);
00066 dve_parser_t(error_vector_t & evect, dve_prob_transition_t * my_transition);
00068 dve_parser_t(error_vector_t & evect, dve_expression_t * my_expression);
00070 ~dve_parser_t();
00071
00073 void set_probabilistic(const bool can_be_prob)
00074 { probabilistic = can_be_prob; }
00075
00077 bool get_probabilistic() { return probabilistic; }
00078
00086
00087
00088 void set_fpos(int line, int col);
00091 void set_lpos(int line, int col);
00093 int get_fline() { return firstline; }
00095 int get_lline() { return lastline; }
00097 int get_fcol() { return firstcol; }
00099 int get_lcol() { return lastcol; }
00100
00101
00103 void done();
00104
00105
00107 void proc_decl_begin(const char * name);
00109 void proc_decl_done();
00110
00111
00114 void type_is_const(const bool const_prefix) { current_const = const_prefix; }
00115
00116
00118 void take_expression();
00120 void take_expression_cancel();
00121
00122
00124
00127 void var_decl_begin(const int type_nbr);
00129
00130 void var_init_is_field(const bool is_field);
00133
00134 void var_init_field_part();
00136
00137 void var_decl_done();
00140
00141 void var_decl_create(const char * name, const int arrayDimesions,
00142 const bool initialized);
00145 void var_decl_cancel();
00148 void var_decl_array_size(const int bound);
00149
00150
00153 void expr_false();
00156 void expr_true();
00159 void expr_nat(const int num);
00162
00164 void expr_id(const char * name, int expr_op = T_ID);
00167 void expr_array_mem(const char * name, int expr_op = T_SQUARE_BRACKETS);
00170
00172 void expr_parenthesis();
00175
00178 void expr_assign(const int assignType);
00181 void expr_unary(const int unaryType);
00184 void expr_bin(const int binaryType);
00187 void expr_state_of_process(const char * proc_name, const char * name);
00190 void expr_var_of_process(const char * proc_name, const char * name,
00191 const bool array = false);
00192
00194 void state_decl(const char * name);
00196 void state_init(const char * name);
00197
00200 void accept_type(int type);
00201
00204 void state_accept(const char * name);
00205
00208 void accept_genbuchi_muller_set_complete();
00209
00212 void state_genbuchi_muller_accept(const char * name);
00213
00216 void accept_rabin_streett_pair_complete();
00217
00220 void accept_rabin_streett_first_complete();
00221
00224 void state_rabin_streett_accept(const char * name);
00225
00227 void state_commit(const char * name);
00230 void state_list_done();
00231
00233 void assertion_create(const char * state_name);
00234
00236 void trans_create(const char * name1, const char * name2,
00237 const bool has_guard, const int sync, const int effect_count);
00239 void trans_effect_list_begin();
00241 void trans_effect_list_end();
00243 void trans_effect_list_cancel();
00245
00248 void trans_effect_part();
00250 void trans_sync(const char * name, const int sync, const bool sync_val);
00252 void trans_guard_expr();
00253
00254
00256 void channel_decl(const char * name);
00258 void typed_channel_decl(const char * name, const int buffer_size);
00259
00261 void type_list_add(const int type_nbr);
00264 void type_list_clear();
00265
00267 void expression_list_store();
00268
00269
00271 void system_synchronicity(const int sync, const bool prop = false);
00273 void system_property(const char * name);
00274
00276 void prob_trans_create(const char * name);
00277
00279 void prob_transition_part(const char * name, const int weight);
00281
00282 private:
00284 void initialise(dve_system_t * const pointer_to_system);
00286
00291 bool add_channel(const char * name, const bool typed = false,
00292 const int buffer_size = 0);
00294 size_int_t add_process(const char * name,
00295 const bool only_temporary=false);
00298 size_int_t add_state
00299 (const char * const name, const size_int_t proc_id,
00300 const bool only_temporary = false);
00303 bool add_variable
00304 (const char * name, const size_int_t proc_id, const bool initialized,
00305 const bool isvector=false);
00307 void add_transition(dve_transition_t * const transition);
00308
00310 void add_prob_transition(dve_prob_transition_t * const prob_trans);
00311 public:
00313
00316 dve_expression_t * get_expression() const;
00318 void set_current_process(size_int_t process_gid)
00319 { current_process = process_gid; }
00321 size_int_t get_current_process() const { return current_process; }
00323
00325 parser_mode_t get_mode() { return mode; }
00327 void set_mode(const parser_mode_t new_mode) { mode = new_mode; }
00329 dve_system_t * get_dve_system_to_fill() { return dve_system_to_fill; }
00331 void set_dve_system_to_fill(dve_system_t * const sys);
00333 dve_process_t * get_dve_process_to_fill() { return dve_process_to_fill; }
00335 void set_dve_process_to_fill(dve_process_t * const proc);
00337 dve_transition_t * get_dve_transition_to_fill() { return dve_transition_to_fill; }
00339 void set_dve_transition_to_fill(dve_transition_t * const trans);
00341 dve_prob_transition_t * get_dve_prob_transition_to_fill() { return dve_prob_transition_to_fill; }
00343 void set_dve_prob_transition_to_fill(dve_prob_transition_t * const trans);
00345 dve_expression_t * get_dve_expression_to_fill() { return dve_expression_to_fill; }
00347 void set_dve_expression_to_fill(dve_expression_t * const expr);
00350 void check_restrictions_put_on_property();
00351
00352
00353 private:
00355 typedef size_int_t bound_t;
00356
00357
00358
00359 struct prop_req_t { bool is_set;
00360 size_int_t process;
00361 unsigned int l1; unsigned int l2;
00362 unsigned int c1; unsigned int c2;
00363 };
00367 void compute_glob_count_according_to_symbol_table();
00368
00374 void register_requirement_for_being_property_process(
00375 const size_int_t proc_id);
00376
00377
00378
00379 void add_sub_op(int expr_op, short int ar = 0);
00380 void add_sub_id(size_int_t sid, int expr_op = T_ID, short int ar = 0);
00381 void add_sub_num(int nbr);
00382
00383 dve_process_t * get_current_process_pointer() const;
00384
00386
00387 bool probabilistic;
00388
00389
00390
00391 size_int_t current_process;
00392
00393
00394 std::stack<dve_expression_t *> subexpr_stack;
00395
00396 bound_t current_bound;
00397 int current_vartype;
00398 bool current_const;
00399 bool last_init_was_field;
00400 dve_expression_t * current_guard;
00401 std::list<dve_expression_t *> current_sync_expr_list;
00402 std::vector<dve_expression_t *> current_effects;
00403 size_int_t current_channel_gid;
00404 std::vector<dve_expression_t *> current_field;
00405 size_int_t current_first_state_gid;
00406 std::list<size_int_t> glob_used;
00407 std::list<dve_expression_t *> current_expression_list;
00408 std::list<dve_var_type_t> current_type_list;
00409 prop_req_t prop_req;
00410 size_int_t glob_count;
00411 bool save_glob_used;
00412 error_vector_t & terr;
00413
00414 parser_mode_t mode;
00415
00416
00417 dve_system_t * dve_system_to_fill;
00418 dve_process_t * dve_process_to_fill;
00419 dve_transition_t * dve_transition_to_fill;
00420 dve_expression_t * dve_expression_to_fill;
00421 dve_prob_transition_t * dve_prob_transition_to_fill;
00422
00423
00424 dve_symbol_table_t * psymbol_table;
00425 dve_system_t * psystem;
00426
00427
00428 int firstline;
00429 int lastline;
00430 int firstcol;
00431 int lastcol;
00432
00433
00434 struct prob_trans_part_t{ std::string name; int weight; };
00435
00436 std::list<prob_trans_part_t> prob_trans_parts;
00437 std::list<transition_t *> prob_trans_trans;
00438 typedef std::list<prob_trans_part_t>::const_iterator prob_trans_part_iter_t;
00439 typedef std::list<transition_t *>::const_iterator prob_trans_trans_iter_t;
00440
00441
00442 size_int_t accepting_groups;
00443 bool new_accepting_set;
00444 std::list< std::list<size_int_t> > accepting_sets;
00445
00446 };
00447
00448
00449 #ifndef DOXYGEN_PROCESSING
00450 }
00451
00452 #endif //DOXYGEN_PROCESSING
00453
00454 #endif