-
Notifications
You must be signed in to change notification settings - Fork 0
/
prp.y
298 lines (280 loc) · 5.25 KB
/
prp.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
%{
#include <iostream>
#include <fstream>
using namespace std;
#include <stdio.h>
//#include <sys/time.h>
extern "C" {
int yyparse(void);
int yylex(void);
int yywrap() {
return 1;
}
}
//#include "prParseUtils.h"
#include "prExt.h"
#define DBG(X) X
%}
%union {
char str[8192];
int intval;
}
%token <str> COMMENT
%token <str> VAR
%token <str> MULTIQUOTE
%token <str> '('
%token <str> ')'
%token <str> ','
%token CASE FUNCTIONCALL INPUT
%token SERVICE ENDSERVICE START STATE ENDSTATE CALL ALTERNATIVE ENDALTERNATIVE TASK JOIN DECISION ENDDECISION CONNECTION ENDCONNECTION STOP NEXTSTATE ELSE
%type <str> args
%type <str> function
%type <str> altstart
%type <str> mqs
%%
file: service
;
service: servicestart validblocks ENDSERVICE ';' {
prTail();
}
| servicestart startblk validblocks ENDSERVICE ';' {
prTail();
}
;
validblocks: states
| connections
| validblocks state
| validblocks connection
;
startblk: starttoken ';' validstmts nextstatestmt {
fend();
}
| starttoken ';' nextstatestmt {
fend();
}
;
starttoken: START {
addStartFuncStart();
fstart();
}
;
servicestart: SERVICE VAR ';' {
svcInit(string($2));
addCommHdr();
}
;
states: state
| states state
;
state: statestart inputs ENDSTATE ';' {
handleEndState();
}
| statestart commentstmt inputs ENDSTATE ';'
;
connections: connection
| connections connection
;
connection: connectionstart validstmts ENDCONNECTION ';' {
fend();
}
;
connectionstart: CONNECTION VAR ':' {
handleNewConn(string($2));
}
;
statestart: STATE VAR ';' {
handleNewState(string($2));
}
| STATE VAR commentstmt {
handleNewState(string($2));
// Comment for state is skipped - TBC where to use.
}
;
inputs: input
| inputs input
;
input: inputstart validstmts {
fend();
}
;
inputstart: INPUT VAR ';' {
handleNewInput(string($2));
}
| INPUT VAR commentstmt {
handleNewInput(string($2));
// Comment for state is skipped - TBC where to use.
}
;
validstmts: validstmt
| validstmts validstmt
;
validstmt: callstmt
| alternativestmt
| nextstatestmt
| commentstmt
| decisionstmt
| joinstmt
| taskstmt
| stopstmt
;
stopstmt: STOP ';' {
handleStop();
}
;
taskstmt: TASK mqs ';' {
handleTask(string($2));
}
| TASK mqs commentstmt {
handleTask(string($2));
}
;
joinstmt: JOIN VAR ';' {
handleJoinStmt(string($2));
}
| JOIN VAR commentstmt {
handleJoinStmt(string($2));
// Comment for Join is skipped - TBC where to use.
}
;
decisionstmt: decisionstart cases elsecase ENDDECISION ';' {
decend();
}
| decisionstart commentstmt cases elsecase ENDDECISION ';' {
decend();
}
;
decisionstart: DECISION mqs {
handleDecisionStart(string($2));
}
| DECISION mqs ';' {
handleDecisionStart(string($2));
}
;
commentstmt: COMMENT mqs ';'
;
nextstatestmt: NEXTSTATE VAR ';' {
handleNextState(string($2).c_str());
}
| NEXTSTATE VAR commentstmt {
handleNextState(string($2).c_str());
}
| NEXTSTATE '-' ';' {
handleNextState(string("-").c_str());
}
| NEXTSTATE '-' commentstmt {
handleNextState(string("-").c_str());
}
;
alternativestmt: altstart cases ENDALTERNATIVE ';' {
altend();
}
| altstart commentstmt cases ENDALTERNATIVE ';' {
altend();
}
| altstart cases elsecase ENDALTERNATIVE ';' {
altend();
}
| altstart commentstmt cases elsecase ENDALTERNATIVE ';' {
altend();
}
;
cases: onecase
| cases onecase
;
onecase: onecasestart validstmts {
handleCaseEnd();
}
;
onecasestart: '(' VAR ')' ':' {
handleCaseStart(string("(")+string($2)+string(")"));
PR("Case start");
}
;
elsecase: elsecasestart validstmts {
handleElseCaseEnd();
}
;
elsecasestart: ELSE ':' {
handleElseCaseStart();
}
;
altstart: ALTERNATIVE mqs ';' {
handleAltStart(string($2));
}
| ALTERNATIVE mqs /* allow for syntax errors! */ {
handleAltStart(string($2));
}
| ALTERNATIVE VAR ';' /* allow for syntax errors! */ {
handleAltStart(string($2));
}
;
callstmt: CALL function ';' {
handleCallStmt(0,string($2));
}
| CALL function commentstmt {
handleCallStmt(2,string($2));
}
| CALL '@' function ';' {
handleCallStmt(1,string($3));
}
| CALL '@' function commentstmt {
handleCallStmt(3,string($3));
}
;
function: VAR '(' ')' { strcpy($$,string(string($1)+string("()")).c_str());}
/*{ strcpy($$,scat((string[]){string($1),string($2),string($3)});}*/
| VAR '(' args ')' {
strcpy($$,string(string($1)+string("(")+string($3)+string(")")).c_str());
DBG(cout << "Func call" << $$ << endl;)
}
;
args: VAR {
// strcpy($$,string(string($1)).c_str());
}
| args ',' VAR {
strcpy($$,string(string($1)+string(",")+string($3)).c_str());
DBG(cout << "Args: " << $$ << endl;)
}
;
mqs: MULTIQUOTE {
strcpy($$,string($1).c_str());
}
| mqs MULTIQUOTE {
strcpy($$,string(string($1)+string($2)).c_str());
}
;
%%
extern FILE *yyin;
extern char* yytext;
#include <string>
void PR(string s) {
cout << s << endl;
}
/*
string scat(string *vals) {
string out;
while(*vals!=NULL) {
out=out+vals++;
}
return out;
}
*/
ofstream f_fsmCCOut, f_fsmHOut, f_tmp;
int main(int ac, char **av) {
f_tmp.open("tmp123");
if(ac>1 && (yyin=fopen(av[1],"r"))==NULL) {
perror(av[1]);
exit(1);
}
if(!yyparse())
printf("Parser worked.\n");
else
printf("Parser failed.\n");
// cout << *commonHdr << endl;
f_tmp.close();
return 0;
}
void yyerror(char* s)
{
fprintf(stderr,"%s: %s\n",s, yytext);
}