RdPMonteur.y 4.13 KB
Newer Older
Jaime Arias's avatar
Jaime Arias committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
%{

/* .......... Declarations C ........*/

#include <string>
#include <stdio.h>
#include "RdPMonteur.h"

static	RdPMonteur *R;
static  string t;

extern	FILE *yyin;
extern char yytext[];

/*........... Code C additionnel ....*/
extern "C" {
  int yylex();
Jaime Arias's avatar
Jaime Arias committed
18

Jaime Arias's avatar
Jaime Arias committed
19
20
21
22
  int yyerror(const char* s){
    printf("parsing error\n");
    return (1);
  }
Jaime Arias's avatar
Jaime Arias committed
23

Jaime Arias's avatar
Jaime Arias committed
24
25
26
27
28
29
30
31
  int yywrap(){
    return (1);
  }
}

%}

/*........... Declarations Yacc .....*/
Jaime Arias's avatar
Jaime Arias committed
32
%union {
Jaime Arias's avatar
Jaime Arias committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  int i;
  char *s;
}

%token IN, OUT, MK, CP, PLACE, QUEUE, TRANS, ENDTR, TOKEN, RESET, LOSS, INHIBITOR
%token <i> ENTIER
%token <s> VARIABLE

%type <i> marquage

%start reseau

%%
/*........... Regles de grammaire ...*/

	/*********************/
	/* lecture du reseau */
	/*********************/

reseau	        : noeud | reseau noeud
		;

Jaime Arias's avatar
Jaime Arias committed
55
noeud		: place | queue | transition
Jaime Arias's avatar
Jaime Arias committed
56
57
58
59
60
61
		;

 	/***********************/
	/* lecture d'une place */
	/***********************/

Jaime Arias's avatar
Jaime Arias committed
62
63
place		: PLACE VARIABLE
		{
Jaime Arias's avatar
Jaime Arias committed
64
		  if(!R->addPlace($2))
Jaime Arias's avatar
Jaime Arias committed
65
		  {
Jaime Arias's avatar
Jaime Arias committed
66
67
68
69
		    yyerror("");return(1);
		  }
		}
                | PLACE VARIABLE MK '(' marquage ')'
Jaime Arias's avatar
Jaime Arias committed
70
		{
Jaime Arias's avatar
Jaime Arias committed
71
		  if(!R->addPlace($2,$5))
Jaime Arias's avatar
Jaime Arias committed
72
		  {
Jaime Arias's avatar
Jaime Arias committed
73
74
75
76
		    yyerror("");return(1);
		  }
		}
                | PLACE VARIABLE CP '(' ENTIER ')'
Jaime Arias's avatar
Jaime Arias committed
77
		{
Jaime Arias's avatar
Jaime Arias committed
78
		  if(!R->addPlace($2,0,$5))
Jaime Arias's avatar
Jaime Arias committed
79
		  {
Jaime Arias's avatar
Jaime Arias committed
80
81
82
83
		    yyerror("");return(1);
		  }
		}
                | PLACE VARIABLE MK '(' marquage ')' CP '(' ENTIER ')'
Jaime Arias's avatar
Jaime Arias committed
84
		{
Jaime Arias's avatar
Jaime Arias committed
85
		  if(!R->addPlace($2,$5,$9))
Jaime Arias's avatar
Jaime Arias committed
86
		  {
Jaime Arias's avatar
Jaime Arias committed
87
88
89
90
		    yyerror("");return(1);
		  }
		}
                | PLACE VARIABLE CP '(' ENTIER ')' MK '(' marquage ')'
Jaime Arias's avatar
Jaime Arias committed
91
		{
Jaime Arias's avatar
Jaime Arias committed
92
		  if(!R->addPlace($2,$9,$5))
Jaime Arias's avatar
Jaime Arias committed
93
		  {
Jaime Arias's avatar
Jaime Arias committed
94
95
96
97
98
99
100
101
102
		    yyerror("");return(1);
		  }
		}
		;

 	/***********************/
	/* lecture d'une queue */
	/***********************/

Jaime Arias's avatar
Jaime Arias committed
103
104
queue		: QUEUE VARIABLE
		{
Jaime Arias's avatar
Jaime Arias committed
105
		  if(!R->addQueue($2))
Jaime Arias's avatar
Jaime Arias committed
106
		  {
Jaime Arias's avatar
Jaime Arias committed
107
108
109
110
		    yyerror("");return(1);
		  }
		}
        | QUEUE VARIABLE CP '(' ENTIER ')'
Jaime Arias's avatar
Jaime Arias committed
111
		{
Jaime Arias's avatar
Jaime Arias committed
112
		  if(!R->addQueue($2,$5))
Jaime Arias's avatar
Jaime Arias committed
113
		  {
Jaime Arias's avatar
Jaime Arias committed
114
115
116
		    yyerror("");return(1);
		  }
		}
Jaime Arias's avatar
Jaime Arias committed
117
118
        | QUEUE VARIABLE LOSS
		{
Jaime Arias's avatar
Jaime Arias committed
119
		  if(!R->addLossQueue($2))
Jaime Arias's avatar
Jaime Arias committed
120
		  {
Jaime Arias's avatar
Jaime Arias committed
121
122
123
124
		    yyerror("");return(1);
		  }
		}
        | QUEUE VARIABLE LOSS CP '(' ENTIER ')'
Jaime Arias's avatar
Jaime Arias committed
125
		{
Jaime Arias's avatar
Jaime Arias committed
126
		  if(!R->addLossQueue($2,$6))
Jaime Arias's avatar
Jaime Arias committed
127
		  {
Jaime Arias's avatar
Jaime Arias committed
128
129
130
131
		    yyerror("");return(1);
		  }
		}
        | QUEUE VARIABLE CP '(' ENTIER ')' LOSS
Jaime Arias's avatar
Jaime Arias committed
132
		{
Jaime Arias's avatar
Jaime Arias committed
133
		  if(!R->addLossQueue($2,$5))
Jaime Arias's avatar
Jaime Arias committed
134
		  {
Jaime Arias's avatar
Jaime Arias committed
135
136
137
138
139
140
141
142
143
144
145
		    yyerror("");return(1);
		  }
		}
		;
	/***********************/
	/* lecture d'une trans */
	/***********************/

nomtransition   : TRANS VARIABLE
                {
		  if(!R->addTrans($2))
Jaime Arias's avatar
Jaime Arias committed
146
		  {
Jaime Arias's avatar
Jaime Arias committed
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
		    yyerror("");return(1);
		  }
		  t=$2;
		}
                ;

transition	: nomtransition entree sortie ENDTR
		;
	/***************************************/
	/* lecture des entrees d'une transition*/
	/***************************************/

entree		: IN '{' listearcin '}'
		|
		;
	/***************************************/
	/* lecture des sorties d'une transition*/
	/***************************************/

sortie		: OUT '{' listearcout '}'
		|
		;

	/***************************************/
	/* lecture d'un arc			*/
	/***************************************/

Jaime Arias's avatar
Jaime Arias committed
174
175
listearcin	: listearcin VARIABLE ':' marquage ';'
		{
Jaime Arias's avatar
Jaime Arias committed
176
		  if(!R->addPre($2,t,$4))
Jaime Arias's avatar
Jaime Arias committed
177
		  {
Jaime Arias's avatar
Jaime Arias committed
178
		    yyerror("");return(1);
Jaime Arias's avatar
Jaime Arias committed
179
		  }
Jaime Arias's avatar
Jaime Arias committed
180
		}
Jaime Arias's avatar
Jaime Arias committed
181
182
		| listearcin VARIABLE ':' '[' ENTIER ']' ';'
		{
Jaime Arias's avatar
Jaime Arias committed
183
		  if(!R->addPreQueue($2,t,$5))
Jaime Arias's avatar
Jaime Arias committed
184
		  {
Jaime Arias's avatar
Jaime Arias committed
185
		    yyerror("");return(1);
Jaime Arias's avatar
Jaime Arias committed
186
		  }
Jaime Arias's avatar
Jaime Arias committed
187
		}
Jaime Arias's avatar
Jaime Arias committed
188
189
		| listearcin VARIABLE ':' RESET ';'
		{
Jaime Arias's avatar
Jaime Arias committed
190
		  if(!R->addReset($2,t))
Jaime Arias's avatar
Jaime Arias committed
191
		  {
Jaime Arias's avatar
Jaime Arias committed
192
		    yyerror("");return(1);
Jaime Arias's avatar
Jaime Arias committed
193
		  }
Jaime Arias's avatar
Jaime Arias committed
194
		}
Jaime Arias's avatar
Jaime Arias committed
195
196
		| listearcin VARIABLE INHIBITOR ENTIER ';'
		{
Jaime Arias's avatar
Jaime Arias committed
197
		  if(!R->addInhibitor($2,t,$4))
Jaime Arias's avatar
Jaime Arias committed
198
		  {
Jaime Arias's avatar
Jaime Arias committed
199
		    yyerror("");return(1);
Jaime Arias's avatar
Jaime Arias committed
200
		  }
Jaime Arias's avatar
Jaime Arias committed
201
		}
Jaime Arias's avatar
Jaime Arias committed
202
203
		| listearcin VARIABLE ':' VARIABLE ';'
		{
Jaime Arias's avatar
Jaime Arias committed
204
		  if(!R->addPreAuto($2,t,$4))
Jaime Arias's avatar
Jaime Arias committed
205
		  {
Jaime Arias's avatar
Jaime Arias committed
206
		    yyerror("");return(1);
Jaime Arias's avatar
Jaime Arias committed
207
		  }
Jaime Arias's avatar
Jaime Arias committed
208
209
210
211
212
		}
		|
		;

listearcout	: listearcout VARIABLE ':' marquage ';'
Jaime Arias's avatar
Jaime Arias committed
213
		{
Jaime Arias's avatar
Jaime Arias committed
214
		  if(!R->addPost($2,t,$4))
Jaime Arias's avatar
Jaime Arias committed
215
		  {
Jaime Arias's avatar
Jaime Arias committed
216
217
218
		    yyerror("");return(1);
		  }
		}
Jaime Arias's avatar
Jaime Arias committed
219
220
		| listearcout VARIABLE ':' '[' ENTIER ']' ';'
		{
Jaime Arias's avatar
Jaime Arias committed
221
		  if(!R->addPostQueue($2,t,$5))
Jaime Arias's avatar
Jaime Arias committed
222
		  {
Jaime Arias's avatar
Jaime Arias committed
223
		    yyerror("");return(1);
Jaime Arias's avatar
Jaime Arias committed
224
		  }
Jaime Arias's avatar
Jaime Arias committed
225
226
		}
		| listearcout VARIABLE ':' VARIABLE ';'
Jaime Arias's avatar
Jaime Arias committed
227
		{
Jaime Arias's avatar
Jaime Arias committed
228
		  if(!R->addPostAuto($2,t,$4))
Jaime Arias's avatar
Jaime Arias committed
229
		  {
Jaime Arias's avatar
Jaime Arias committed
230
231
232
233
234
235
		    yyerror("");return(1);
		  }
		}
		|
		;

Jaime Arias's avatar
Jaime Arias committed
236
marquage	: TOKEN {$$=1;}
Jaime Arias's avatar
Jaime Arias committed
237
238
239
240
241
		|
		ENTIER TOKEN {$$=$1;}
		;
%%

Jaime Arias's avatar
Jaime Arias committed
242
bool RdPMonteur::create(const char *f){
Jaime Arias's avatar
Jaime Arias committed
243
244
245
246
247
248
249
250
  int i;
  if ((yyin=fopen(f,"r"))==NULL)
    return false;
  R=this;
  i=(int) yyparse();
  fclose(yyin);
  return (i==0);
}