1 /* methods for implementation of automaton from promela description */
3 /* Copyright (c) 2011-2015. 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 #include <string.h> /* strerror */
13 static xbt_automaton_t parsed_automaton;
16 static void new_state(char* id, int src){
18 char* id_state = xbt_strdup(id);
19 char* first_part = strtok(id,"_");
20 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
22 if(strcmp(first_part,"accept")==0){
25 char* second_part = strtok(NULL,"_");
26 if(strcmp(second_part,"init")==0){
31 xbt_automaton_state_t state = NULL;
32 state = xbt_automaton_state_exists(parsed_automaton, id_state);
34 state = xbt_automaton_state_new(parsed_automaton, type, id_state);
38 parsed_automaton->current_state = state;
41 state_id_src = xbt_strdup(id_state);
45 static void new_transition(char* id, xbt_automaton_exp_label_t label){
47 char* id_state = xbt_strdup(id);
48 xbt_automaton_state_t state_dst = NULL;
50 state_dst = xbt_automaton_state_exists(parsed_automaton, id_state);
51 xbt_automaton_state_t state_src = xbt_automaton_state_exists(parsed_automaton, state_id_src);
53 //xbt_transition_t trans = NULL;
54 xbt_automaton_transition_new(parsed_automaton, state_src, state_dst, label);
58 static xbt_automaton_exp_label_t new_label(int type, ...){
59 xbt_automaton_exp_label_t label = NULL;
64 xbt_automaton_exp_label_t left = va_arg(ap, xbt_automaton_exp_label_t);
65 xbt_automaton_exp_label_t right = va_arg(ap, xbt_automaton_exp_label_t);
66 label = xbt_automaton_exp_label_new(type, left, right);
70 xbt_automaton_exp_label_t left = va_arg(ap, xbt_automaton_exp_label_t);
71 xbt_automaton_exp_label_t right = va_arg(ap, xbt_automaton_exp_label_t);
72 label = xbt_automaton_exp_label_new(type, left, right);
76 xbt_automaton_exp_label_t exp_not = va_arg(ap, xbt_automaton_exp_label_t);
77 label = xbt_automaton_exp_label_new(type, exp_not);
81 char* p = va_arg(ap, char*);
82 label = xbt_automaton_exp_label_new(type, p);
86 label = xbt_automaton_exp_label_new(type);
95 #include "parserPromela.tab.cacc"
97 void xbt_automaton_load(xbt_automaton_t a, const char *file)
100 yyin = fopen(file, "r");
102 xbt_die("Failed to open automaton file `%s': %s", file, strerror(errno));