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 "src/internal_config.h"
10 #include "xbt/automaton.h"
12 #include <string.h> /* strerror */
14 # include <unistd.h> /* isatty */
17 static xbt_automaton_t parsed_automaton;
20 static void new_state(char* id, int src){
22 char* id_copy = xbt_strdup(id);
23 char* first_part = strtok(id_copy,"_");
24 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
26 if(strcmp(first_part,"accept")==0){
29 char* second_part = strtok(NULL,"_");
30 if(strcmp(second_part,"init")==0){
36 xbt_automaton_state_t state = NULL;
37 state = xbt_automaton_state_exists(parsed_automaton, id);
39 state = xbt_automaton_state_new(parsed_automaton, type, id);
43 parsed_automaton->current_state = state;
48 state_id_src = xbt_strdup(id);
52 static void new_transition(char* id, xbt_automaton_exp_label_t label)
54 xbt_automaton_state_t state_dst = NULL;
56 state_dst = xbt_automaton_state_exists(parsed_automaton, id);
57 xbt_automaton_state_t state_src = xbt_automaton_state_exists(parsed_automaton, state_id_src);
59 //xbt_transition_t trans = NULL;
60 xbt_automaton_transition_new(parsed_automaton, state_src, state_dst, label);
64 static xbt_automaton_exp_label_t new_label(int type, ...){
65 xbt_automaton_exp_label_t label = NULL;
66 xbt_automaton_exp_label_t left;
67 xbt_automaton_exp_label_t right;
68 xbt_automaton_exp_label_t exp_not;
75 left = va_arg(ap, xbt_automaton_exp_label_t);
76 right = va_arg(ap, xbt_automaton_exp_label_t);
77 label = xbt_automaton_exp_label_new(type, left, right);
80 left = va_arg(ap, xbt_automaton_exp_label_t);
81 right = va_arg(ap, xbt_automaton_exp_label_t);
82 label = xbt_automaton_exp_label_new(type, left, right);
85 exp_not = va_arg(ap, xbt_automaton_exp_label_t);
86 label = xbt_automaton_exp_label_new(type, exp_not);
89 p = va_arg(ap, char*);
90 label = xbt_automaton_exp_label_new(type, p);
93 label = xbt_automaton_exp_label_new(type);
100 #include "parserPromela.tab.cacc"
102 void xbt_automaton_load(xbt_automaton_t a, const char *file)
104 parsed_automaton = a;
105 yyin = fopen(file, "r");
107 xbt_die("Failed to open automaton file `%s': %s", file, strerror(errno));