1 /* methods for implementation of automaton from promela description */
3 /* Copyright (c) 2011-2012. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/automaton.h"
10 static xbt_automaton_t parsed_automaton;
13 static void new_state(char* id, int src){
15 char* id_state = strdup(id);
16 char* first_part = strtok(id,"_");
17 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
19 if(strcmp(first_part,"accept")==0){
22 char* second_part = strtok(NULL,"_");
23 if(strcmp(second_part,"init")==0){
28 xbt_state_t state = NULL;
29 state = xbt_automaton_state_exists(parsed_automaton, id_state);
31 state = xbt_automaton_new_state(parsed_automaton, type, id_state);
35 parsed_automaton->current_state = state;
38 state_id_src = strdup(id_state);
42 static void new_transition(char* id, xbt_exp_label_t label){
44 char* id_state = strdup(id);
45 xbt_state_t state_dst = NULL;
47 state_dst = xbt_automaton_state_exists(parsed_automaton, id_state);
48 xbt_state_t state_src = xbt_automaton_state_exists(parsed_automaton, state_id_src);
50 //xbt_transition_t trans = NULL;
51 xbt_automaton_new_transition(parsed_automaton, state_src, state_dst, label);
55 static xbt_exp_label_t new_label(int type, ...){
56 xbt_exp_label_t label = NULL;
61 xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
62 xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
63 label = xbt_automaton_new_label(type, left, right);
67 xbt_exp_label_t left = va_arg(ap, xbt_exp_label_t);
68 xbt_exp_label_t right = va_arg(ap, xbt_exp_label_t);
69 label = xbt_automaton_new_label(type, left, right);
73 xbt_exp_label_t exp_not = va_arg(ap, xbt_exp_label_t);
74 label = xbt_automaton_new_label(type, exp_not);
78 char* p = va_arg(ap, char*);
79 label = xbt_automaton_new_label(type, p);
83 label = xbt_automaton_new_label(type);
92 #include "parserPromela.tab.cacc"
94 void xbt_automaton_load(xbt_automaton_t a, const char *file){
96 yyin = fopen(file, "r");