-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.mly
175 lines (130 loc) · 7.68 KB
/
parser.mly
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
/* File parser.mly */
%{
open Functionannexe;;
let nodelist = ref [] ;;
let transition = ref [];;
%}
%token <string> ID
%token <string> NUM
%token <string> LABELN
%token <string> LIST
%token SHOW ISRECONNU ISDETERMINISTIC COMPLETE ISCOMPLETE CREATENODE CREATEFROM AT LABEL COLOR SIZE TO INITIAL FINAL BGCOLOR DUMP REMOVE REMOVEEDGE MOVE RENAME WITH EDIT EDITEDGE PATH
%token EOL N S E O NW NE SW SE DETERMINISTIC DELETEALL TRANSPOSE
%start main /* the entry point */
%type <unit > main
%type <unit> noeud
%%
main:
|noeud EOL { }
|display EOL { }
|lasf EOL { }
;
display:
| DUMP { printlist (!nodelist @ !transition) }
| DUMP vrailabel { createfile $2 !nodelist !transition}
| DUMP vrailabel WITH vrailabel {dumpwithstring $2 !nodelist !transition $4}
;
lasf :
| ISCOMPLETE {Printf.printf "%b\n " (is_complete !nodelist !transition)}
| COMPLETE WITH labelnoeud AT numero numero {nodelist := completeaux $3 $5 $6 !nodelist !transition;transition:= complete $3 !nodelist !transition;}
| ISDETERMINISTIC {Printf.printf "%b\n " (is_deterministic !nodelist !transition)}
| ISRECONNU vrailabel {Printf.printf "%b\n " (is_accepted !nodelist !transition $2)}
| SHOW vrailabel {Printf.printf "%s\n " (getchemin !nodelist !transition $2)}
| SHOW COMPLETE vrailabel {nodelist:= showcomplet $3 !nodelist !transition }
| SHOW DETERMINISTIC vrailabel {nodelist := showcompletd $3 !nodelist !transition}
numero:
NUM {$1}
;
labelnoeud:
ID {$1}
;
vrailabel:
LABELN {String.sub $1 1 ((String.length $1) -2) } ;
glist :
LIST { python_split ',' (String.sub $1 1 ((String.length $1) -2)) } ;
attribut:
| LABEL vrailabel {" LABEL: " ^ $2 }
| COLOR vrailabel {" COLOR: " ^ $2 }
| BGCOLOR vrailabel {" BGCOLOR: " ^ $2 }
| INITIAL direction {" INITIAL: " ^ $2 }
| FINAL direction {" FINAL: " ^ $2 }
| INITIAL {" INITIAL: " ^ "none" }
| FINAL {" FINAL: " ^ "none" }
| SIZE numero {" SIZE: " ^ $2}
| LABEL vrailabel attribut {" LABEL: " ^ $2 ^ $3 }
| COLOR vrailabel attribut {" COLOR: " ^ $2 ^ $3 }
| SIZE numero attribut {" SIZE: " ^ $2 ^ $3 }
| BGCOLOR vrailabel attribut {" BGCOLOR: " ^ $2 ^ $3 }
| INITIAL direction attribut { " INITIAL: " ^ $2 ^ $3 }
| FINAL direction attribut { " FINAL: " ^ $2 ^ $3 }
| INITIAL attribut { " INITIAL: " ^ "none" ^ $2 }
| FINAL attribut { " FINAL: " ^ "none" ^ $2}
;
direction :
| N {"Nord"}
| S {"Sud"}
| E {"Est"}
| O {"Ouest"}
| NW {"Nord-West"}
| NE {"Nord-Est"}
| SW {"Sud-Ouest"}
| SE {"Sud-Est"}
attributf:
| COLOR vrailabel {" COLOR: " ^ $2 }
| PATH vrailabel {" PATH: " ^ ( String.concat "_" (String.split_on_char ' ' $2))}
| AT numero numero {" POSITION: " ^ $2^":"^ $3}
| COLOR vrailabel attributf {" COLOR: " ^ $2 ^ $3 }
| PATH vrailabel attributf {" PATH: " ^ ( String.concat "_" (String.split_on_char ' ' $2)) ^ $3}
| AT numero numero attributf {" POSITION: " ^ $2^":"^ $3 ^ $4}
;
attributet:
| LABEL vrailabel {" LABEL: " ^ $2 }
| COLOR vrailabel {" COLOR: " ^ $2 }
| PATH vrailabel {" PATH: " ^ ( String.concat "_" (String.split_on_char ' ' $2))}
| LABEL vrailabel AT numero numero {" POSITION: " ^ $4^":"^ $5}
| COLOR vrailabel attributet {" COLOR: " ^ $2 ^ $3 }
| PATH vrailabel attributet {" PATH: " ^ ( String.concat "_" (String.split_on_char ' ' $2)) ^ $3}
| LABEL vrailabel attributet {" LABEL: " ^ $2 ^ $3 }
| LABEL vrailabel AT numero numero attributet {" POSITION: " ^ $4^":"^ $5 ^ $6}
;
attributen:
| LABEL vrailabel {" LABEL: " ^ $2 }
| COLOR vrailabel {" COLOR: " ^ $2 }
| BGCOLOR vrailabel {" BGCOLOR: " ^ $2 }
| INITIAL direction {" INITIAL: " ^ $2 }
| FINAL direction {" FINAL: " ^ $2 }
| INITIAL {" INITIAL: " ^ "none" }
| FINAL {" FINAL: " ^ "none" }
| SIZE numero {" SIZE: " ^ $2}
| AT numero numero {" X: " ^ $2 ^ " Y: " ^ $3 }
| LABEL vrailabel attributen {" LABEL: " ^ $2 ^ $3}
| COLOR vrailabel attributen {" COLOR: " ^ $2 ^ $3 }
| BGCOLOR vrailabel attributen {" BGCOLOR: " ^ $2 ^ $3 }
| INITIAL direction attributen{" INITIAL: " ^ $2 ^ $3 }
| FINAL direction attributen{" FINAL: " ^ $2 ^ $3 }
| INITIAL attributen{" INITIAL: " ^ "none" ^ $2 }
| FINAL attributen{" FINAL: " ^ "none" ^ $2 }
| SIZE numero attributen {" SIZE: " ^ $2 ^ $3}
| AT numero numero attributen {" X: " ^ $2 ^ " Y: " ^ $3 ^ $4}
;
noeud:
| CREATENODE ID AT numero numero attribut { nodelist := !nodelist @ (add (Noeud(createid $2, ( $4), ( $5),$6)) !nodelist !transition) }
| CREATENODE ID attribut AT numero numero { nodelist := !nodelist @ ( add (Noeud(createid $2, ( $5), ( $6),$3)) !nodelist !transition) }
| CREATENODE ID attribut AT numero numero attribut { nodelist := !nodelist @ ( add (Noeud( createid $2, ( $5), ( $6),$3 ^ (" " ^ $7))) !nodelist !transition) }
| CREATENODE ID AT numero numero { nodelist := !nodelist @ ( add (Noeud(createid $2, ( $4), ( $5),"")) !nodelist !transition)}
| CREATEFROM ID TO ID LABEL vrailabel { transition := !transition @ (add (Edge(createid $2,createid $4,$6,"")) !nodelist !transition ) }
| CREATEFROM ID TO ID LABEL vrailabel attributf { transition := !transition @ (add (Edge(createid $2,createid $4,$6,$7)) !nodelist !transition) }
| CREATEFROM ID TO ID attributf LABEL vrailabel { transition := !transition @ ( add (Edge(createid $2,createid $4,$7,$5)) !nodelist !transition) }
| CREATEFROM ID TO ID attributf LABEL vrailabel attributf { transition := !transition @ (add (Edge(createid $2,createid $4,$7,$5 ^ (" "^ $8))) !nodelist !transition) }
| EDITEDGE ID TO ID WITH attributet { Printf.printf "Il faut rajouter le label de la transition :o \n"}
| EDITEDGE ID TO ID LABEL vrailabel WITH attributet { transition := editt (createid $2) ( createid $4) $8 $6 !transition }
| EDIT ID WITH attributen {nodelist := editn (createid $2) $4 !nodelist }
| REMOVE ID { nodelist := removenoeud (createid $2) !nodelist ; transition:= removetransitionafternode (createid $2) !transition; }
| REMOVEEDGE ID TO ID { transition := removetransition (createid $2) (createid $4) !transition }
| MOVE numero numero {nodelist := moveall $2 $3 !nodelist}
| MOVE ID numero numero {nodelist := moveallid_aux (createid $2) $3 $4 !nodelist}
| MOVE glist numero numero {nodelist := movelistid $2 $3 $4 !nodelist}
| RENAME ID WITH ID {nodelist:= renamen (createid $2) (createid $4) !nodelist ; transition:= renamet (createid $2) (createid $4) !transition ;}
| DELETEALL {nodelist:= [] ; transition:= [];}
| TRANSPOSE {nodelist:= transpoenode !nodelist;transition:= transpoeedge !transition;}
;