1 /* methods for implementation of automaton from promela description */
3 /* Copyright (c) 2011-2017. 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 static xbt_automaton_t parsed_automaton;
19 static void new_state(char* id, int src){
20 char* saveptr = NULL; // for strtok_r()
21 char* id_copy = xbt_strdup(id);
22 char* first_part = strtok_r(id_copy, "_", &saveptr);
23 int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
25 if(strcmp(first_part,"accept")==0){
28 char* second_part = strtok_r(NULL, "_", &saveptr);
29 if(strcmp(second_part,"init")==0){
35 xbt_automaton_state_t state = xbt_automaton_state_exists(parsed_automaton, id);
37 state = xbt_automaton_state_new(parsed_automaton, type, id);
41 parsed_automaton->current_state = state;
46 state_id_src = xbt_strdup(id);
50 static void new_transition(char* id, xbt_automaton_exp_label_t label)
53 xbt_automaton_state_t state_dst = xbt_automaton_state_exists(parsed_automaton, id);
54 xbt_automaton_state_t state_src = xbt_automaton_state_exists(parsed_automaton, state_id_src);
56 //xbt_transition_t trans = NULL;
57 xbt_automaton_transition_new(parsed_automaton, state_src, state_dst, label);
61 static xbt_automaton_exp_label_t new_label(int type, ...){
62 xbt_automaton_exp_label_t label = NULL;
63 xbt_automaton_exp_label_t left;
64 xbt_automaton_exp_label_t right;
65 xbt_automaton_exp_label_t exp_not;
72 left = va_arg(ap, xbt_automaton_exp_label_t);
73 right = va_arg(ap, xbt_automaton_exp_label_t);
74 label = xbt_automaton_exp_label_new(type, left, right);
77 left = va_arg(ap, xbt_automaton_exp_label_t);
78 right = va_arg(ap, xbt_automaton_exp_label_t);
79 label = xbt_automaton_exp_label_new(type, left, right);
82 exp_not = va_arg(ap, xbt_automaton_exp_label_t);
83 label = xbt_automaton_exp_label_new(type, exp_not);
86 p = va_arg(ap, char*);
87 label = xbt_automaton_exp_label_new(type, p);
90 label = xbt_automaton_exp_label_new(type);
97 #include "parserPromela.tab.cacc"
99 void xbt_automaton_load(xbt_automaton_t a, const char *file)
101 parsed_automaton = a;
102 yyin = fopen(file, "r");
104 xbt_die("Failed to open automaton file `%s': %s", file, strerror(errno));