1 /* methods for implementation of automaton from promela description */
3 /* Copyright (c) 2011-2013. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/automaton.h"
11 static xbt_automaton_t parsed_automaton;
14 static void new_state(char* id, int src){
16 char* id_state = strdup(id);
17 char* first_part = strtok(id,"_");
18 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
20 if(strcmp(first_part,"accept")==0){
23 char* second_part = strtok(NULL,"_");
24 if(strcmp(second_part,"init")==0){
29 xbt_automaton_state_t state = NULL;
30 state = xbt_automaton_state_exists(parsed_automaton, id_state);
32 state = xbt_automaton_state_new(parsed_automaton, type, id_state);
36 parsed_automaton->current_state = state;
39 state_id_src = strdup(id_state);
43 static void new_transition(char* id, xbt_automaton_exp_label_t label){
45 char* id_state = strdup(id);
46 xbt_automaton_state_t state_dst = NULL;
48 state_dst = xbt_automaton_state_exists(parsed_automaton, id_state);
49 xbt_automaton_state_t state_src = xbt_automaton_state_exists(parsed_automaton, state_id_src);
51 //xbt_transition_t trans = NULL;
52 xbt_automaton_transition_new(parsed_automaton, state_src, state_dst, label);
56 static xbt_automaton_exp_label_t new_label(int type, ...){
57 xbt_automaton_exp_label_t label = NULL;
62 xbt_automaton_exp_label_t left = va_arg(ap, xbt_automaton_exp_label_t);
63 xbt_automaton_exp_label_t right = va_arg(ap, xbt_automaton_exp_label_t);
64 label = xbt_automaton_exp_label_new(type, left, right);
68 xbt_automaton_exp_label_t left = va_arg(ap, xbt_automaton_exp_label_t);
69 xbt_automaton_exp_label_t right = va_arg(ap, xbt_automaton_exp_label_t);
70 label = xbt_automaton_exp_label_new(type, left, right);
74 xbt_automaton_exp_label_t exp_not = va_arg(ap, xbt_automaton_exp_label_t);
75 label = xbt_automaton_exp_label_new(type, exp_not);
79 char* p = va_arg(ap, char*);
80 label = xbt_automaton_exp_label_new(type, p);
84 label = xbt_automaton_exp_label_new(type);
93 #include "parserPromela.tab.cacc"
95 void xbt_automaton_load(xbt_automaton_t a, const char *file){
97 yyin = fopen(file, "r");