Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / xbt / automaton / parserPromela.yacc
1 /* Copyright (c) 2012-2022. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 %{
8 #include "simgrid/config.h"
9 #if !HAVE_UNISTD_H
10 #define YY_NO_UNISTD_H /* hello Windows */
11 #endif
12
13 #include "automaton_lexer.yy.c"
14 #include <xbt/automaton.h>
15
16 void yyerror(const char *s);
17
18 static void new_state(const char* id, int src);
19 static void new_transition(const char* id, xbt_automaton_exp_label_t label);
20
21 %}
22
23 %union{
24   double real;
25   int integer;
26   char* string;
27   xbt_automaton_exp_label_t label;
28 }
29
30 %token NEVER
31 %token IF
32 %token FI
33 %token IMPLIES
34 %token GOTO
35 %token AND
36 %token OR
37 %token NOT
38 %token LEFT_PAR
39 %token RIGHT_PAR
40 %token CASE
41 %token COLON
42 %token SEMI_COLON
43 %token CASE_TRUE
44 %token LEFT_BRACE
45 %token RIGHT_BRACE
46 %token <integer> LITT_ENT
47 %token <string> LITT_CHAINE
48 %token <real> LITT_REEL
49 %token <string> ID
50
51 %type <label> exp;
52
53 %start automaton
54
55 %left AND OR
56 %nonassoc NOT
57
58 %%
59
60 automaton : NEVER LEFT_BRACE stateseq RIGHT_BRACE
61           ;
62
63 stateseq :
64          | ID COLON { new_state($1, 1);} IF option FI SEMI_COLON stateseq
65          ;
66
67 option :
68        | CASE exp IMPLIES GOTO ID option { new_transition($5, $2);}
69        ;
70
71 exp : LEFT_PAR exp RIGHT_PAR { $$ = $2; }
72     | exp OR exp { $$ = xbt_automaton_exp_label_new_or($1, $3); }
73     | exp AND exp { $$ = xbt_automaton_exp_label_new_and($1, $3); }
74     | NOT exp { $$ = xbt_automaton_exp_label_new_not($2); }
75     | CASE_TRUE { $$ = xbt_automaton_exp_label_new_one(); }
76     | ID { $$ = xbt_automaton_exp_label_new_predicat($1); }
77     ;
78
79 %%
80
81
82
83 void yyerror(const char *s){
84   fprintf (stderr, "%s\n", s);
85 }
86
87
88