1 /* methods for implementation of automaton from promela description */
3 /* Copyright (c) 2011-2018. 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 "src/internal_config.h"
9 #include "xbt/automaton.h"
11 #include <string.h> /* strerror */
13 # include <unistd.h> /* isatty */
16 #include <xbt/sysdep.h>
18 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_automaton);
20 static xbt_automaton_t parsed_automaton;
23 static void new_state(char* id, int src){
24 char* saveptr = NULL; // for strtok_r()
25 char* id_copy = xbt_strdup(id);
26 char* first_part = strtok_r(id_copy, "_", &saveptr);
27 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
29 if(strcmp(first_part,"accept")==0){
32 char* second_part = strtok_r(NULL, "_", &saveptr);
33 if(strcmp(second_part,"init")==0){
39 xbt_automaton_state_t state = xbt_automaton_state_exists(parsed_automaton, id);
41 state = xbt_automaton_state_new(parsed_automaton, type, id);
45 parsed_automaton->current_state = state;
48 xbt_free(state_id_src);
49 state_id_src = xbt_strdup(id);
53 static void new_transition(char* id, xbt_automaton_exp_label_t label)
56 xbt_automaton_state_t 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);
96 XBT_DEBUG("Invalid type: %d", type);
103 #include "parserPromela.tab.cacc"
105 void xbt_automaton_load(xbt_automaton_t a, const char *file)
107 parsed_automaton = a;
108 yyin = fopen(file, "r");
110 xbt_die("Failed to open automaton file `%s': %s", file, strerror(errno));