1
2
3 import sys
4 from antlr3 import *
5 from antlr3.compat import set, frozenset
6
7
8 __doc__ = """Parser for reading FCL by the pyfuzzy package."""
9 __revision__ = "$Id: FCLParser.py,v 1.9 2013-01-09 20:10:19 rliebscher Exp $"
10
11 import fuzzy.System
12 import fuzzy.InputVariable
13 import fuzzy.OutputVariable
14 import fuzzy.Adjective
15 import fuzzy.set.Polygon
16 import fuzzy.set.Singleton
17 import fuzzy.defuzzify
18 import fuzzy.defuzzify.Dict
19 import fuzzy.fuzzify
20 import fuzzy.fuzzify.Plain
21 import fuzzy.fuzzify.Dict
22 import fuzzy.operator.Not
23 import fuzzy.operator.Input
24 import fuzzy.operator.Compound
25 import fuzzy.Rule
26 import fuzzy.norm.Min
27 import fuzzy.norm.Max
28
30 """Get an instance of a fuzzy norm with given name.
31 Normally looks into the fuzzy.norm package for a suitable class.
32 """
33 m = __import__("fuzzy.norm."+name, fromlist=[name])
34 c = m.__dict__[name]
35 if p is None:
36 return c()
37 else:
38 return c(p)
39
41 """Get an instance of a fuzzy set with given name.
42 Normally looks into the fuzzy.set package for a suitable class.
43 """
44 m = __import__("fuzzy.set."+name, fromlist=[name])
45 c = m.__dict__[name]
46 return c(*params)
47
49 """Get an instance of a defuzzification method with given name.
50 Normally looks into the fuzzy.defuzzify package for a suitable class.
51 """
52 m = __import__("fuzzy.defuzzify."+name, fromlist=[name])
53 c = m.__dict__[name]
54 return c()
55
56
57 _operators = {
58 "AND":fuzzy.norm.Min.Min(),
59 "OR":fuzzy.norm.Max.Max()
60 }
61
63 """Defines a operator (AND,OR,...) to use a given norm."""
64 _operators[name] = norm
65
66
68 """Get the norm for previous defined operator name."""
69
70 import copy
71 return copy.deepcopy(_operators[name])
72
73 _structs = {}
74
76 """Remember name of a struct definition"""
77 _structs[name] = []
78
80 """Add a struct element"""
81 _structs[name].append(elem)
82
84 """Get list of elements of a struct definition"""
85 return _structs[name]
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 HIDDEN = BaseRecognizer.HIDDEN
108
109
110 T__29=29
111 T__28=28
112 Real_literal=9
113 OR_=6
114 T__27=27
115 T__26=26
116 T__25=25
117 T__24=24
118 LETTER=10
119 T__23=23
120 T__22=22
121 T__21=21
122 T__20=20
123 AND_=7
124 EOF=-1
125 Identifier=4
126 T__55=55
127 T__56=56
128 T__19=19
129 T__57=57
130 T__58=58
131 T__16=16
132 T__51=51
133 T__15=15
134 T__52=52
135 T__18=18
136 T__53=53
137 T__54=54
138 T__17=17
139 Integer_literal_wo_sign=11
140 T__14=14
141 T__59=59
142 DIGIT=5
143 COMMENT=13
144 T__50=50
145 T__42=42
146 T__43=43
147 T__40=40
148 T__41=41
149 T__46=46
150 T__47=47
151 T__44=44
152 T__45=45
153 T__48=48
154 T__49=49
155 T__30=30
156 T__31=31
157 T__32=32
158 WS=12
159 T__33=33
160 T__34=34
161 Integer_literal=8
162 T__35=35
163 T__36=36
164 T__37=37
165 T__38=38
166 T__39=39
167
168
169 tokenNames = [
170 "<invalid>", "<EOR>", "<DOWN>", "<UP>",
171 "Identifier", "DIGIT", "OR_", "AND_", "Integer_literal", "Real_literal",
172 "LETTER", "Integer_literal_wo_sign", "WS", "COMMENT", "'FUNCTION_BLOCK'",
173 "'END_FUNCTION_BLOCK'", "'STRUCT'", "'END_STRUCT'", "':'", "'REAL'",
174 "';'", "'VAR_INPUT'", "'END_VAR'", "'VAR_OUTPUT'", "'FUZZIFY'", "'END_FUZZIFY'",
175 "'DEFUZZIFY'", "'END_DEFUZZIFY'", "'RULEBLOCK'", "'END_RULEBLOCK'",
176 "'OPTION'", "'END_OPTION'", "'TERM'", "':='", "'('", "','", "')'", "'METHOD'",
177 "'DEFAULT'", "'NC'", "'RANGE'", "'..'", "'['", "']'", "'MIN'", "'PROD'",
178 "'BDIF'", "'MAX'", "'ASUM'", "'BSUM'", "'ACT'", "'ACCU'", "'NSUM'",
179 "'NOT'", "'IS'", "'.'", "'RULE'", "'IF'", "'THEN'", "'WITH'"
180 ]
181
182
183
184
186 grammarFileName = "/work/projects/pyfuzzy/pyfuzzy/fuzzy/storage/fcl/FCL.g"
187 antlr_version = version_str_to_tuple("3.1.2")
188 antlr_version_str = "3.1.2"
189 tokenNames = tokenNames
190
192 if state is None:
193 state = RecognizerSharedState()
194
195 Parser.__init__(self, input, state)
196
197
198
199
200
201 self.System = None
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
219
220 system = None
221
222 try:
223 try:
224
225
226 pass
227
228 self.System = None;
229
230 self._state.following.append(self.FOLLOW_function_block_declaration_in_main55)
231 self.function_block_declaration()
232
233 self._state.following.pop()
234
235 system = self.System
236
237
238
239
240
241 except RecognitionException:
242 re = sys.exc_info()[1]
243 self.reportError(re)
244 self.recover(self.input, re)
245 finally:
246
247 pass
248
249 return system
250
251
252
253
254
255
337
338
339
340
341
342
344
345 Identifier2 = None
346
347 try:
348 try:
349
350
351 pass
352 self.match(self.input, 16, self.FOLLOW_16_in_type_definition126)
353 Identifier2=self.match(self.input, Identifier, self.FOLLOW_Identifier_in_type_definition128)
354
355 defineStructType(Identifier2.text);
356
357
358 cnt3 = 0
359 while True:
360 alt3 = 2
361 LA3_0 = self.input.LA(1)
362
363 if (LA3_0 == Identifier) :
364 alt3 = 1
365
366
367 if alt3 == 1:
368
369 pass
370 self._state.following.append(self.FOLLOW_struct_element_in_type_definition132)
371 self.struct_element(Identifier2.text)
372
373 self._state.following.pop()
374
375
376 else:
377 if cnt3 >= 1:
378 break
379
380 eee = EarlyExitException(3, self.input)
381 raise eee
382
383 cnt3 += 1
384
385
386 self.match(self.input, 17, self.FOLLOW_17_in_type_definition136)
387
388
389
390
391 except RecognitionException:
392 re = sys.exc_info()[1]
393 self.reportError(re)
394 self.recover(self.input, re)
395 finally:
396
397 pass
398
399 return
400
401
402
403
404
405
407
408 Identifier3 = None
409
410 try:
411 try:
412
413
414 pass
415 Identifier3=self.match(self.input, Identifier, self.FOLLOW_Identifier_in_struct_element151)
416 self.match(self.input, 18, self.FOLLOW_18_in_struct_element153)
417 self.match(self.input, 19, self.FOLLOW_19_in_struct_element155)
418 self.match(self.input, 20, self.FOLLOW_20_in_struct_element157)
419
420 defineStructTypeElement(struct_name, Identifier3.text);
421
422
423
424
425
426 except RecognitionException:
427 re = sys.exc_info()[1]
428 self.reportError(re)
429 self.recover(self.input, re)
430 finally:
431
432 pass
433
434 return
435
436
437
438
439
440
442
443 try:
444 try:
445
446 alt4 = 2
447 LA4_0 = self.input.LA(1)
448
449 if (LA4_0 == 21) :
450 alt4 = 1
451 elif (LA4_0 == 23) :
452 alt4 = 2
453 else:
454 nvae = NoViableAltException("", 4, 0, self.input)
455
456 raise nvae
457
458 if alt4 == 1:
459
460 pass
461 self._state.following.append(self.FOLLOW_input_declarations_in_fb_io_var_declarations172)
462 self.input_declarations()
463
464 self._state.following.pop()
465
466
467 elif alt4 == 2:
468
469 pass
470 self._state.following.append(self.FOLLOW_output_declarations_in_fb_io_var_declarations178)
471 self.output_declarations()
472
473 self._state.following.pop()
474
475
476
477 except RecognitionException:
478 re = sys.exc_info()[1]
479 self.reportError(re)
480 self.recover(self.input, re)
481 finally:
482
483 pass
484
485 return
486
487
488
489
490
491
543
544
545
546
547
548
550
551 try:
552 try:
553
554
555 pass
556 self.match(self.input, 23, self.FOLLOW_23_in_output_declarations203)
557
558 cnt6 = 0
559 while True:
560 alt6 = 2
561 LA6_0 = self.input.LA(1)
562
563 if (LA6_0 == Identifier) :
564 alt6 = 1
565
566
567 if alt6 == 1:
568
569 pass
570 self._state.following.append(self.FOLLOW_var_decl_in_output_declarations205)
571 self.var_decl(1)
572
573 self._state.following.pop()
574
575
576 else:
577 if cnt6 >= 1:
578 break
579
580 eee = EarlyExitException(6, self.input)
581 raise eee
582
583 cnt6 += 1
584
585
586 self.match(self.input, 22, self.FOLLOW_22_in_output_declarations209)
587
588
589
590
591 except RecognitionException:
592 re = sys.exc_info()[1]
593 self.reportError(re)
594 self.recover(self.input, re)
595 finally:
596
597 pass
598
599 return
600
601
602
603
604
605
661
662
663
664
665
666
668
669 struct_type = None
670
671 Identifier6 = None
672
673 try:
674 try:
675
676 alt7 = 2
677 LA7_0 = self.input.LA(1)
678
679 if (LA7_0 == 19) :
680 alt7 = 1
681 elif (LA7_0 == Identifier) :
682 alt7 = 2
683 else:
684 nvae = NoViableAltException("", 7, 0, self.input)
685
686 raise nvae
687
688 if alt7 == 1:
689
690 pass
691 self.match(self.input, 19, self.FOLLOW_19_in_type254)
692
693 struct_type = None
694
695
696
697 elif alt7 == 2:
698
699 pass
700 Identifier6=self.match(self.input, Identifier, self.FOLLOW_Identifier_in_type264)
701
702 struct_type = getStructType(Identifier6.text)
703
704
705
706
707 except RecognitionException:
708 re = sys.exc_info()[1]
709 self.reportError(re)
710 self.recover(self.input, re)
711 finally:
712
713 pass
714
715 return struct_type
716
717
718
719
720
721
723
724 try:
725 try:
726
727
728 pass
729
730 while True:
731 alt8 = 2
732 LA8_0 = self.input.LA(1)
733
734 if (LA8_0 == 24) :
735 alt8 = 1
736
737
738 if alt8 == 1:
739
740 pass
741 self._state.following.append(self.FOLLOW_fuzzify_block_in_function_block_body286)
742 self.fuzzify_block()
743
744 self._state.following.pop()
745
746
747 else:
748 break
749
750
751
752 while True:
753 alt9 = 2
754 LA9_0 = self.input.LA(1)
755
756 if (LA9_0 == 26) :
757 alt9 = 1
758
759
760 if alt9 == 1:
761
762 pass
763 self._state.following.append(self.FOLLOW_defuzzify_block_in_function_block_body293)
764 self.defuzzify_block()
765
766 self._state.following.pop()
767
768
769 else:
770 break
771
772
773
774 while True:
775 alt10 = 2
776 LA10_0 = self.input.LA(1)
777
778 if (LA10_0 == 28) :
779 alt10 = 1
780
781
782 if alt10 == 1:
783
784 pass
785 self._state.following.append(self.FOLLOW_rule_block_in_function_block_body300)
786 self.rule_block()
787
788 self._state.following.pop()
789
790
791 else:
792 break
793
794
795
796 while True:
797 alt11 = 2
798 LA11_0 = self.input.LA(1)
799
800 if (LA11_0 == 30) :
801 alt11 = 1
802
803
804 if alt11 == 1:
805
806 pass
807 self._state.following.append(self.FOLLOW_option_block_in_function_block_body307)
808 self.option_block()
809
810 self._state.following.pop()
811
812
813 else:
814 break
815
816
817
818
819
820
821 except RecognitionException:
822 re = sys.exc_info()[1]
823 self.reportError(re)
824 self.recover(self.input, re)
825 finally:
826
827 pass
828
829 return
830
831
832
833
834
835
837
838 variable_name7 = None
839
840
841 try:
842 try:
843
844
845 pass
846 self.match(self.input, 24, self.FOLLOW_24_in_fuzzify_block325)
847 self._state.following.append(self.FOLLOW_variable_name_in_fuzzify_block331)
848 variable_name7 = self.variable_name()
849
850 self._state.following.pop()
851
852 while True:
853 alt12 = 2
854 LA12_0 = self.input.LA(1)
855
856 if (LA12_0 == 32) :
857 alt12 = 1
858
859
860 if alt12 == 1:
861
862 pass
863 self._state.following.append(self.FOLLOW_linguistic_term_in_fuzzify_block337)
864 self.linguistic_term(((variable_name7 is not None) and [self.input.toString(variable_name7.start,variable_name7.stop)] or [None])[0])
865
866 self._state.following.pop()
867
868
869 else:
870 break
871
872
873 self.match(self.input, 25, self.FOLLOW_25_in_fuzzify_block345)
874
875
876
877
878 except RecognitionException:
879 re = sys.exc_info()[1]
880 self.reportError(re)
881 self.recover(self.input, re)
882 finally:
883
884 pass
885
886 return
887
888
889
890
891
892
894
895 f_variable_name8 = None
896
897
898 try:
899 try:
900
901
902 pass
903 self.match(self.input, 26, self.FOLLOW_26_in_defuzzify_block362)
904 self._state.following.append(self.FOLLOW_f_variable_name_in_defuzzify_block368)
905 f_variable_name8 = self.f_variable_name()
906
907 self._state.following.pop()
908
909 while True:
910 alt13 = 2
911 LA13_0 = self.input.LA(1)
912
913 if (LA13_0 == 32) :
914 alt13 = 1
915
916
917 if alt13 == 1:
918
919 pass
920 self._state.following.append(self.FOLLOW_linguistic_term_in_defuzzify_block374)
921 self.linguistic_term(((f_variable_name8 is not None) and [self.input.toString(f_variable_name8.start,f_variable_name8.stop)] or [None])[0])
922
923 self._state.following.pop()
924
925
926 else:
927 break
928
929
930 self._state.following.append(self.FOLLOW_accumulation_method_in_defuzzify_block382)
931 self.accumulation_method()
932
933 self._state.following.pop()
934 self._state.following.append(self.FOLLOW_defuzzification_method_in_defuzzify_block388)
935 self.defuzzification_method(((f_variable_name8 is not None) and [self.input.toString(f_variable_name8.start,f_variable_name8.stop)] or [None])[0])
936
937 self._state.following.pop()
938
939 alt14 = 2
940 LA14_0 = self.input.LA(1)
941
942 if (LA14_0 == 38) :
943 alt14 = 1
944 if alt14 == 1:
945
946 pass
947 self._state.following.append(self.FOLLOW_default_value_in_defuzzify_block395)
948 self.default_value(((f_variable_name8 is not None) and [self.input.toString(f_variable_name8.start,f_variable_name8.stop)] or [None])[0])
949
950 self._state.following.pop()
951
952
953
954
955 alt15 = 2
956 LA15_0 = self.input.LA(1)
957
958 if (LA15_0 == 40) :
959 alt15 = 1
960 if alt15 == 1:
961
962 pass
963 self._state.following.append(self.FOLLOW_range_in_defuzzify_block403)
964 self.range()
965
966 self._state.following.pop()
967
968
969
970 self.match(self.input, 27, self.FOLLOW_27_in_defuzzify_block410)
971
972
973
974
975 except RecognitionException:
976 re = sys.exc_info()[1]
977 self.reportError(re)
978 self.recover(self.input, re)
979 finally:
980
981 pass
982
983 return
984
985
986
987
988
989
991
992 rule_block_name9 = None
993
994
995 try:
996 try:
997
998
999 pass
1000 self.match(self.input, 28, self.FOLLOW_28_in_rule_block427)
1001 self._state.following.append(self.FOLLOW_rule_block_name_in_rule_block435)
1002 rule_block_name9 = self.rule_block_name()
1003
1004 self._state.following.pop()
1005
1006 while True:
1007 alt16 = 2
1008 LA16_0 = self.input.LA(1)
1009
1010 if ((OR_ <= LA16_0 <= AND_)) :
1011 alt16 = 1
1012
1013
1014 if alt16 == 1:
1015
1016 pass
1017 self._state.following.append(self.FOLLOW_operator_definition_in_rule_block443)
1018 self.operator_definition()
1019
1020 self._state.following.pop()
1021
1022
1023 else:
1024 break
1025
1026
1027
1028 alt17 = 2
1029 LA17_0 = self.input.LA(1)
1030
1031 if (LA17_0 == 50) :
1032 alt17 = 1
1033 if alt17 == 1:
1034
1035 pass
1036 self._state.following.append(self.FOLLOW_activation_method_in_rule_block452)
1037 self.activation_method()
1038
1039 self._state.following.pop()
1040
1041
1042
1043
1044 while True:
1045 alt18 = 2
1046 LA18_0 = self.input.LA(1)
1047
1048 if (LA18_0 == 56) :
1049 alt18 = 1
1050
1051
1052 if alt18 == 1:
1053
1054 pass
1055 self._state.following.append(self.FOLLOW_rule_in_rule_block461)
1056 self.rule(((rule_block_name9 is not None) and [self.input.toString(rule_block_name9.start,rule_block_name9.stop)] or [None])[0])
1057
1058 self._state.following.pop()
1059
1060
1061 else:
1062 break
1063
1064
1065 self.match(self.input, 29, self.FOLLOW_29_in_rule_block469)
1066
1067
1068
1069
1070 except RecognitionException:
1071 re = sys.exc_info()[1]
1072 self.reportError(re)
1073 self.recover(self.input, re)
1074 finally:
1075
1076 pass
1077
1078 return
1079
1080
1081
1082
1083
1084
1086
1087 try:
1088 try:
1089
1090
1091 pass
1092 self.match(self.input, 30, self.FOLLOW_30_in_option_block477)
1093 self.match(self.input, 31, self.FOLLOW_31_in_option_block481)
1094
1095
1096
1097
1098 except RecognitionException:
1099 re = sys.exc_info()[1]
1100 self.reportError(re)
1101 self.recover(self.input, re)
1102 finally:
1103
1104 pass
1105
1106 return
1107
1108
1109
1110
1111
1112
1154
1155
1156
1157
1158
1159
1161
1162 set = None
1163
1164 singleton12 = None
1165
1166 points13 = None
1167
1168 pyfuzzy_set14 = None
1169
1170
1171 try:
1172 try:
1173
1174 alt19 = 3
1175 LA19 = self.input.LA(1)
1176 if LA19 == Integer_literal or LA19 == Real_literal:
1177 alt19 = 1
1178 elif LA19 == Identifier:
1179 LA19_2 = self.input.LA(2)
1180
1181 if (LA19_2 == 34) :
1182 alt19 = 3
1183 elif (LA19_2 == 20) :
1184 alt19 = 1
1185 else:
1186 nvae = NoViableAltException("", 19, 2, self.input)
1187
1188 raise nvae
1189
1190 elif LA19 == 20 or LA19 == 34:
1191 alt19 = 2
1192 else:
1193 nvae = NoViableAltException("", 19, 0, self.input)
1194
1195 raise nvae
1196
1197 if alt19 == 1:
1198
1199 pass
1200 self._state.following.append(self.FOLLOW_singleton_in_membership_function526)
1201 singleton12 = self.singleton()
1202
1203 self._state.following.pop()
1204
1205 set = singleton12
1206
1207
1208
1209 elif alt19 == 2:
1210
1211 pass
1212 self._state.following.append(self.FOLLOW_points_in_membership_function538)
1213 points13 = self.points()
1214
1215 self._state.following.pop()
1216
1217 set = points13
1218
1219
1220
1221 elif alt19 == 3:
1222
1223 pass
1224 self._state.following.append(self.FOLLOW_pyfuzzy_set_in_membership_function550)
1225 pyfuzzy_set14 = self.pyfuzzy_set()
1226
1227 self._state.following.pop()
1228
1229 set = pyfuzzy_set14
1230
1231
1232
1233
1234 except RecognitionException:
1235 re = sys.exc_info()[1]
1236 self.reportError(re)
1237 self.recover(self.input, re)
1238 finally:
1239
1240 pass
1241
1242 return set
1243
1244
1245
1246
1247
1248
1250
1251 set = None
1252
1253 numeric_literal15 = None
1254
1255
1256 try:
1257 try:
1258
1259 alt20 = 2
1260 LA20_0 = self.input.LA(1)
1261
1262 if ((Integer_literal <= LA20_0 <= Real_literal)) :
1263 alt20 = 1
1264 elif (LA20_0 == Identifier) :
1265 alt20 = 2
1266 else:
1267 nvae = NoViableAltException("", 20, 0, self.input)
1268
1269 raise nvae
1270
1271 if alt20 == 1:
1272
1273 pass
1274 self._state.following.append(self.FOLLOW_numeric_literal_in_singleton573)
1275 numeric_literal15 = self.numeric_literal()
1276
1277 self._state.following.pop()
1278
1279 set = fuzzy.set.Singleton.Singleton(float(((numeric_literal15 is not None) and [self.input.toString(numeric_literal15.start,numeric_literal15.stop)] or [None])[0]))
1280
1281
1282
1283 elif alt20 == 2:
1284
1285 pass
1286 self._state.following.append(self.FOLLOW_variable_name_in_singleton585)
1287 self.variable_name()
1288
1289 self._state.following.pop()
1290
1291
1292
1293 except RecognitionException:
1294 re = sys.exc_info()[1]
1295 self.reportError(re)
1296 self.recover(self.input, re)
1297 finally:
1298
1299 pass
1300
1301 return set
1302
1303
1304
1305
1306
1307
1309
1310 set = None
1311
1312 x = None
1313
1314 y = None
1315
1316
1317
1318 p = []
1319
1320 try:
1321 try:
1322
1323
1324 pass
1325
1326 while True:
1327 alt22 = 2
1328 LA22_0 = self.input.LA(1)
1329
1330 if (LA22_0 == 34) :
1331 alt22 = 1
1332
1333
1334 if alt22 == 1:
1335
1336 pass
1337 self.match(self.input, 34, self.FOLLOW_34_in_points617)
1338
1339 alt21 = 2
1340 LA21_0 = self.input.LA(1)
1341
1342 if ((Integer_literal <= LA21_0 <= Real_literal)) :
1343 alt21 = 1
1344 elif (LA21_0 == Identifier) :
1345 alt21 = 2
1346 else:
1347 nvae = NoViableAltException("", 21, 0, self.input)
1348
1349 raise nvae
1350
1351 if alt21 == 1:
1352
1353 pass
1354 self._state.following.append(self.FOLLOW_numeric_literal_in_points627)
1355 x = self.numeric_literal()
1356
1357 self._state.following.pop()
1358
1359
1360 elif alt21 == 2:
1361
1362 pass
1363 self._state.following.append(self.FOLLOW_variable_name_in_points631)
1364 self.variable_name()
1365
1366 self._state.following.pop()
1367
1368
1369
1370 self.match(self.input, 35, self.FOLLOW_35_in_points639)
1371 self._state.following.append(self.FOLLOW_numeric_literal_in_points648)
1372 y = self.numeric_literal()
1373
1374 self._state.following.pop()
1375 self.match(self.input, 36, self.FOLLOW_36_in_points655)
1376
1377 p.append((float(((x is not None) and [self.input.toString(x.start,x.stop)] or [None])[0]), float(((y is not None) and [self.input.toString(y.start,y.stop)] or [None])[0])));
1378
1379
1380
1381 else:
1382 break
1383
1384
1385
1386 set = fuzzy.set.Polygon.Polygon(p)
1387
1388
1389
1390
1391
1392 except RecognitionException:
1393 re = sys.exc_info()[1]
1394 self.reportError(re)
1395 self.recover(self.input, re)
1396 finally:
1397
1398 pass
1399
1400 return set
1401
1402
1403
1404
1405
1406
1408
1409 set = None
1410
1411 Identifier16 = None
1412 p1 = None
1413
1414 pn = None
1415
1416
1417
1418 p = []
1419
1420 try:
1421 try:
1422
1423
1424 pass
1425 Identifier16=self.match(self.input, Identifier, self.FOLLOW_Identifier_in_pyfuzzy_set699)
1426 self.match(self.input, 34, self.FOLLOW_34_in_pyfuzzy_set704)
1427
1428 alt24 = 2
1429 LA24_0 = self.input.LA(1)
1430
1431 if ((Integer_literal <= LA24_0 <= Real_literal)) :
1432 alt24 = 1
1433 if alt24 == 1:
1434
1435 pass
1436 self._state.following.append(self.FOLLOW_numeric_literal_in_pyfuzzy_set716)
1437 p1 = self.numeric_literal()
1438
1439 self._state.following.pop()
1440
1441 p.append(float(((p1 is not None) and [self.input.toString(p1.start,p1.stop)] or [None])[0]));
1442
1443
1444 while True:
1445 alt23 = 2
1446 LA23_0 = self.input.LA(1)
1447
1448 if (LA23_0 == 35) :
1449 alt23 = 1
1450
1451
1452 if alt23 == 1:
1453
1454 pass
1455 self.match(self.input, 35, self.FOLLOW_35_in_pyfuzzy_set732)
1456 self._state.following.append(self.FOLLOW_numeric_literal_in_pyfuzzy_set742)
1457 pn = self.numeric_literal()
1458
1459 self._state.following.pop()
1460
1461 p.append(float(((pn is not None) and [self.input.toString(pn.start,pn.stop)] or [None])[0]));
1462
1463
1464
1465 else:
1466 break
1467
1468
1469
1470
1471
1472 self.match(self.input, 36, self.FOLLOW_36_in_pyfuzzy_set762)
1473
1474 set = getSet(Identifier16.text,p)
1475
1476
1477
1478
1479
1480 except RecognitionException:
1481 re = sys.exc_info()[1]
1482 self.reportError(re)
1483 self.recover(self.input, re)
1484 finally:
1485
1486 pass
1487
1488 return set
1489
1490
1491
1492
1493
1494
1524
1525
1526
1527
1528
1529
1531
1532 numeric_literal18 = None
1533
1534
1535 try:
1536 try:
1537
1538
1539 pass
1540 self.match(self.input, 38, self.FOLLOW_38_in_default_value812)
1541 self.match(self.input, 33, self.FOLLOW_33_in_default_value814)
1542
1543 alt25 = 2
1544 LA25_0 = self.input.LA(1)
1545
1546 if ((Integer_literal <= LA25_0 <= Real_literal)) :
1547 alt25 = 1
1548 elif (LA25_0 == 39) :
1549 alt25 = 2
1550 else:
1551 nvae = NoViableAltException("", 25, 0, self.input)
1552
1553 raise nvae
1554
1555 if alt25 == 1:
1556
1557 pass
1558 self._state.following.append(self.FOLLOW_numeric_literal_in_default_value824)
1559 numeric_literal18 = self.numeric_literal()
1560
1561 self._state.following.pop()
1562
1563 self.System.variables[var_name].defuzzify.failsafe = float(((numeric_literal18 is not None) and [self.input.toString(numeric_literal18.start,numeric_literal18.stop)] or [None])[0]);
1564
1565
1566
1567 elif alt25 == 2:
1568
1569 pass
1570 self.match(self.input, 39, self.FOLLOW_39_in_default_value836)
1571
1572 self.System.variables[var_name].defuzzify.failsafe = None;
1573
1574
1575
1576
1577 self.match(self.input, 20, self.FOLLOW_20_in_default_value846)
1578
1579
1580
1581
1582 except RecognitionException:
1583 re = sys.exc_info()[1]
1584 self.reportError(re)
1585 self.recover(self.input, re)
1586 finally:
1587
1588 pass
1589
1590 return
1591
1592
1593
1594
1595
1596
1598
1599 try:
1600 try:
1601
1602
1603 pass
1604 self.match(self.input, 40, self.FOLLOW_40_in_range857)
1605 self.match(self.input, 33, self.FOLLOW_33_in_range859)
1606 self.match(self.input, 34, self.FOLLOW_34_in_range861)
1607 self._state.following.append(self.FOLLOW_numeric_literal_in_range863)
1608 self.numeric_literal()
1609
1610 self._state.following.pop()
1611 self.match(self.input, 41, self.FOLLOW_41_in_range865)
1612 self._state.following.append(self.FOLLOW_numeric_literal_in_range867)
1613 self.numeric_literal()
1614
1615 self._state.following.pop()
1616 self.match(self.input, 36, self.FOLLOW_36_in_range869)
1617 self.match(self.input, 20, self.FOLLOW_20_in_range871)
1618
1619
1620
1621
1622 except RecognitionException:
1623 re = sys.exc_info()[1]
1624 self.reportError(re)
1625 self.recover(self.input, re)
1626 finally:
1627
1628 pass
1629
1630 return
1631
1632
1633
1634
1635
1636
1638
1639 op = None
1640
1641 i1 = None
1642 param = None
1643
1644
1645 try:
1646 try:
1647
1648
1649 pass
1650 i1=self.match(self.input, Identifier, self.FOLLOW_Identifier_in_operator_name_any890)
1651
1652 alt26 = 2
1653 LA26_0 = self.input.LA(1)
1654
1655 if (LA26_0 == 42) :
1656 alt26 = 1
1657 if alt26 == 1:
1658
1659 pass
1660 self.match(self.input, 42, self.FOLLOW_42_in_operator_name_any893)
1661 self._state.following.append(self.FOLLOW_numeric_literal_in_operator_name_any897)
1662 param = self.numeric_literal()
1663
1664 self._state.following.pop()
1665 self.match(self.input, 43, self.FOLLOW_43_in_operator_name_any899)
1666
1667
1668
1669
1670
1671 if ((param is not None) and [self.input.toString(param.start,param.stop)] or [None])[0] is not None:
1672 p = float(((param is not None) and [self.input.toString(param.start,param.stop)] or [None])[0])
1673 else:
1674 p = None
1675 op = getNorm(i1.text, p)
1676
1677
1678
1679
1680
1681
1682 except RecognitionException:
1683 re = sys.exc_info()[1]
1684 self.reportError(re)
1685 self.recover(self.input, re)
1686 finally:
1687
1688 pass
1689
1690 return op
1691
1692
1693
1694
1695
1696
1698
1699 op = None
1700
1701 norm = None
1702
1703
1704 try:
1705 try:
1706
1707 alt27 = 4
1708 LA27 = self.input.LA(1)
1709 if LA27 == 44:
1710 alt27 = 1
1711 elif LA27 == 45:
1712 alt27 = 2
1713 elif LA27 == 46:
1714 alt27 = 3
1715 elif LA27 == Identifier:
1716 alt27 = 4
1717 else:
1718 nvae = NoViableAltException("", 27, 0, self.input)
1719
1720 raise nvae
1721
1722 if alt27 == 1:
1723
1724 pass
1725
1726
1727 pass
1728 self.match(self.input, 44, self.FOLLOW_44_in_operator_name_AND922)
1729
1730 op = getNorm("Min")
1731
1732
1733
1734
1735
1736
1737 elif alt27 == 2:
1738
1739 pass
1740
1741
1742 pass
1743 self.match(self.input, 45, self.FOLLOW_45_in_operator_name_AND932)
1744
1745 op = getNorm("AlgebraicProduct")
1746
1747
1748
1749
1750
1751
1752 elif alt27 == 3:
1753
1754 pass
1755
1756
1757 pass
1758 self.match(self.input, 46, self.FOLLOW_46_in_operator_name_AND942)
1759
1760 op = getNorm("BoundedDifference")
1761
1762
1763
1764
1765
1766
1767 elif alt27 == 4:
1768
1769 pass
1770
1771
1772 pass
1773 self._state.following.append(self.FOLLOW_operator_name_any_in_operator_name_AND955)
1774 norm = self.operator_name_any()
1775
1776 self._state.following.pop()
1777
1778 op = norm
1779
1780
1781
1782
1783
1784
1785
1786 except RecognitionException:
1787 re = sys.exc_info()[1]
1788 self.reportError(re)
1789 self.recover(self.input, re)
1790 finally:
1791
1792 pass
1793
1794 return op
1795
1796
1797
1798
1799
1800
1802
1803 op = None
1804
1805 norm = None
1806
1807
1808 try:
1809 try:
1810
1811 alt28 = 4
1812 LA28 = self.input.LA(1)
1813 if LA28 == 47:
1814 alt28 = 1
1815 elif LA28 == 48:
1816 alt28 = 2
1817 elif LA28 == 49:
1818 alt28 = 3
1819 elif LA28 == Identifier:
1820 alt28 = 4
1821 else:
1822 nvae = NoViableAltException("", 28, 0, self.input)
1823
1824 raise nvae
1825
1826 if alt28 == 1:
1827
1828 pass
1829
1830
1831 pass
1832 self.match(self.input, 47, self.FOLLOW_47_in_operator_name_OR976)
1833
1834 op = getNorm("Max")
1835
1836
1837
1838
1839
1840
1841 elif alt28 == 2:
1842
1843 pass
1844
1845
1846 pass
1847 self.match(self.input, 48, self.FOLLOW_48_in_operator_name_OR986)
1848
1849 op = getNorm("AlgebraicSum")
1850
1851
1852
1853
1854
1855
1856 elif alt28 == 3:
1857
1858 pass
1859
1860
1861 pass
1862 self.match(self.input, 49, self.FOLLOW_49_in_operator_name_OR996)
1863
1864 op = getNorm("BoundedSum")
1865
1866
1867
1868
1869
1870
1871 elif alt28 == 4:
1872
1873 pass
1874
1875
1876 pass
1877 self._state.following.append(self.FOLLOW_operator_name_any_in_operator_name_OR1009)
1878 norm = self.operator_name_any()
1879
1880 self._state.following.pop()
1881
1882 op = norm
1883
1884
1885
1886
1887
1888
1889
1890 except RecognitionException:
1891 re = sys.exc_info()[1]
1892 self.reportError(re)
1893 self.recover(self.input, re)
1894 finally:
1895
1896 pass
1897
1898 return op
1899
1900
1901
1902
1903
1904
1906
1907 or_name = None
1908 and_name = None
1909 or_op = None
1910
1911 and_op = None
1912
1913
1914 try:
1915 try:
1916
1917
1918 pass
1919
1920 alt29 = 2
1921 LA29_0 = self.input.LA(1)
1922
1923 if (LA29_0 == OR_) :
1924 alt29 = 1
1925 elif (LA29_0 == AND_) :
1926 alt29 = 2
1927 else:
1928 nvae = NoViableAltException("", 29, 0, self.input)
1929
1930 raise nvae
1931
1932 if alt29 == 1:
1933
1934 pass
1935
1936
1937 pass
1938 or_name=self.match(self.input, OR_, self.FOLLOW_OR__in_operator_definition1053)
1939 self.match(self.input, 18, self.FOLLOW_18_in_operator_definition1055)
1940 self._state.following.append(self.FOLLOW_operator_name_OR_in_operator_definition1059)
1941 or_op = self.operator_name_OR()
1942
1943 self._state.following.pop()
1944
1945 defineOperator(or_name.text, or_op);
1946
1947
1948
1949
1950
1951
1952 elif alt29 == 2:
1953
1954 pass
1955
1956
1957 pass
1958 and_name=self.match(self.input, AND_, self.FOLLOW_AND__in_operator_definition1070)
1959 self.match(self.input, 18, self.FOLLOW_18_in_operator_definition1072)
1960 self._state.following.append(self.FOLLOW_operator_name_AND_in_operator_definition1076)
1961 and_op = self.operator_name_AND()
1962
1963 self._state.following.pop()
1964
1965 defineOperator(and_name.text, and_op);
1966
1967
1968
1969
1970
1971
1972
1973 self.match(self.input, 20, self.FOLLOW_20_in_operator_definition1085)
1974
1975
1976
1977
1978 except RecognitionException:
1979 re = sys.exc_info()[1]
1980 self.reportError(re)
1981 self.recover(self.input, re)
1982 finally:
1983
1984 pass
1985
1986 return
1987
1988
1989
1990
1991
1992
1994
1995 try:
1996 try:
1997
1998
1999 pass
2000 self.match(self.input, 50, self.FOLLOW_50_in_activation_method1094)
2001 self.match(self.input, 18, self.FOLLOW_18_in_activation_method1096)
2002 if (44 <= self.input.LA(1) <= 45):
2003 self.input.consume()
2004 self._state.errorRecovery = False
2005
2006 else:
2007 mse = MismatchedSetException(None, self.input)
2008 raise mse
2009
2010
2011 self.match(self.input, 20, self.FOLLOW_20_in_activation_method1106)
2012
2013
2014
2015
2016 except RecognitionException:
2017 re = sys.exc_info()[1]
2018 self.reportError(re)
2019 self.recover(self.input, re)
2020 finally:
2021
2022 pass
2023
2024 return
2025
2026
2027
2028
2029
2030
2032
2033 try:
2034 try:
2035
2036
2037 pass
2038 self.match(self.input, 51, self.FOLLOW_51_in_accumulation_method1114)
2039 self.match(self.input, 18, self.FOLLOW_18_in_accumulation_method1116)
2040 if self.input.LA(1) == 47 or self.input.LA(1) == 49 or self.input.LA(1) == 52:
2041 self.input.consume()
2042 self._state.errorRecovery = False
2043
2044 else:
2045 mse = MismatchedSetException(None, self.input)
2046 raise mse
2047
2048
2049 self.match(self.input, 20, self.FOLLOW_20_in_accumulation_method1130)
2050
2051
2052
2053
2054 except RecognitionException:
2055 re = sys.exc_info()[1]
2056 self.reportError(re)
2057 self.recover(self.input, re)
2058 finally:
2059
2060 pass
2061
2062 return
2063
2064
2065
2066
2067
2068
2070
2071 input = None
2072
2073 op = None
2074 s1 = None
2075
2076 s2 = None
2077
2078
2079
2080 op_name = None;
2081
2082 try:
2083 try:
2084
2085
2086 pass
2087
2088
2089 pass
2090 self._state.following.append(self.FOLLOW_subcondition_in_condition1161)
2091 s1 = self.subcondition()
2092
2093 self._state.following.pop()
2094
2095 input = s1
2096
2097
2098
2099
2100
2101 while True:
2102 alt30 = 2
2103 LA30_0 = self.input.LA(1)
2104
2105 if ((OR_ <= LA30_0 <= AND_)) :
2106 alt30 = 1
2107
2108
2109 if alt30 == 1:
2110
2111 pass
2112
2113
2114 pass
2115 op = self.input.LT(1)
2116 if (OR_ <= self.input.LA(1) <= AND_):
2117 self.input.consume()
2118 self._state.errorRecovery = False
2119
2120 else:
2121 mse = MismatchedSetException(None, self.input)
2122 raise mse
2123
2124
2125
2126
2127 if op_name is not None and op_name != op.text:
2128 raise Exception("Don't mix different operations in an expression.")
2129 else:
2130 op_name = op.text
2131
2132
2133 self._state.following.append(self.FOLLOW_subcondition_in_condition1211)
2134 s2 = self.subcondition()
2135
2136 self._state.following.pop()
2137
2138
2139 input = fuzzy.operator.Compound.Compound(getOperator(op.text), input, s2)
2140
2141
2142
2143
2144
2145
2146
2147 else:
2148 break
2149
2150
2151
2152
2153
2154
2155 except RecognitionException:
2156 re = sys.exc_info()[1]
2157 self.reportError(re)
2158 self.recover(self.input, re)
2159 finally:
2160
2161 pass
2162
2163 return input
2164
2165
2166
2167
2168
2169
2171
2172 input = None
2173
2174 condition19 = None
2175
2176 subcondition220 = None
2177
2178
2179 try:
2180 try:
2181
2182 alt31 = 2
2183 LA31_0 = self.input.LA(1)
2184
2185 if (LA31_0 == 53) :
2186 alt31 = 1
2187 elif (LA31_0 == Identifier or LA31_0 == 34) :
2188 alt31 = 2
2189 else:
2190 nvae = NoViableAltException("", 31, 0, self.input)
2191
2192 raise nvae
2193
2194 if alt31 == 1:
2195
2196 pass
2197
2198
2199 pass
2200 self.match(self.input, 53, self.FOLLOW_53_in_subcondition1251)
2201 self.match(self.input, 34, self.FOLLOW_34_in_subcondition1253)
2202 self._state.following.append(self.FOLLOW_condition_in_subcondition1255)
2203 condition19 = self.condition()
2204
2205 self._state.following.pop()
2206 self.match(self.input, 36, self.FOLLOW_36_in_subcondition1257)
2207
2208 input = fuzzy.operator.Not.Not(condition19)
2209
2210
2211
2212
2213
2214
2215 elif alt31 == 2:
2216
2217 pass
2218
2219
2220 pass
2221 self._state.following.append(self.FOLLOW_subcondition2_in_subcondition1269)
2222 subcondition220 = self.subcondition2()
2223
2224 self._state.following.pop()
2225
2226 input = subcondition220
2227
2228
2229
2230
2231
2232
2233
2234 except RecognitionException:
2235 re = sys.exc_info()[1]
2236 self.reportError(re)
2237 self.recover(self.input, re)
2238 finally:
2239
2240 pass
2241
2242 return input
2243
2244
2245
2246
2247
2248
2250
2251 input = None
2252
2253 x = None
2254 c1 = None
2255
2256 norm = None
2257
2258 c4 = None
2259
2260 c5 = None
2261
2262 variable_name21 = None
2263
2264 term_name22 = None
2265
2266
2267 try:
2268 try:
2269
2270 alt34 = 3
2271 LA34_0 = self.input.LA(1)
2272
2273 if (LA34_0 == 34) :
2274 alt34 = 1
2275 elif (LA34_0 == Identifier) :
2276 LA34_2 = self.input.LA(2)
2277
2278 if (LA34_2 == 34 or LA34_2 == 42) :
2279 alt34 = 3
2280 elif ((54 <= LA34_2 <= 55)) :
2281 alt34 = 2
2282 else:
2283 nvae = NoViableAltException("", 34, 2, self.input)
2284
2285 raise nvae
2286
2287 else:
2288 nvae = NoViableAltException("", 34, 0, self.input)
2289
2290 raise nvae
2291
2292 if alt34 == 1:
2293
2294 pass
2295
2296
2297 pass
2298 self.match(self.input, 34, self.FOLLOW_34_in_subcondition21296)
2299 self._state.following.append(self.FOLLOW_condition_in_subcondition21300)
2300 c1 = self.condition()
2301
2302 self._state.following.pop()
2303 self.match(self.input, 36, self.FOLLOW_36_in_subcondition21302)
2304
2305
2306 input = c1
2307
2308
2309
2310
2311
2312
2313
2314 elif alt34 == 2:
2315
2316 pass
2317
2318
2319 pass
2320 self._state.following.append(self.FOLLOW_variable_name_in_subcondition21322)
2321 variable_name21 = self.variable_name()
2322
2323 self._state.following.pop()
2324
2325 alt33 = 2
2326 LA33_0 = self.input.LA(1)
2327
2328 if (LA33_0 == 54) :
2329 alt33 = 1
2330 elif (LA33_0 == 55) :
2331 alt33 = 2
2332 else:
2333 nvae = NoViableAltException("", 33, 0, self.input)
2334
2335 raise nvae
2336
2337 if alt33 == 1:
2338
2339 pass
2340 self.match(self.input, 54, self.FOLLOW_54_in_subcondition21325)
2341
2342 alt32 = 2
2343 LA32_0 = self.input.LA(1)
2344
2345 if (LA32_0 == 53) :
2346 alt32 = 1
2347 if alt32 == 1:
2348
2349 pass
2350 x=self.match(self.input, 53, self.FOLLOW_53_in_subcondition21329)
2351
2352
2353
2354
2355
2356 elif alt33 == 2:
2357
2358 pass
2359 self.match(self.input, 55, self.FOLLOW_55_in_subcondition21334)
2360
2361
2362
2363 self._state.following.append(self.FOLLOW_term_name_in_subcondition21338)
2364 term_name22 = self.term_name()
2365
2366 self._state.following.pop()
2367
2368
2369 input = fuzzy.operator.Input.Input(self.System.variables[((variable_name21 is not None) and [self.input.toString(variable_name21.start,variable_name21.stop)] or [None])[0]].adjectives[((term_name22 is not None) and [self.input.toString(term_name22.start,term_name22.stop)] or [None])[0]])
2370 if x is not None:
2371 input = fuzzy.operator.Not.Not(input)
2372
2373
2374
2375
2376
2377
2378
2379 elif alt34 == 3:
2380
2381 pass
2382
2383
2384 pass
2385 self._state.following.append(self.FOLLOW_operator_name_any_in_subcondition21360)
2386 norm = self.operator_name_any()
2387
2388 self._state.following.pop()
2389 self.match(self.input, 34, self.FOLLOW_34_in_subcondition21362)
2390 self._state.following.append(self.FOLLOW_condition_in_subcondition21366)
2391 c4 = self.condition()
2392
2393 self._state.following.pop()
2394 self.match(self.input, 35, self.FOLLOW_35_in_subcondition21368)
2395 self._state.following.append(self.FOLLOW_condition_in_subcondition21372)
2396 c5 = self.condition()
2397
2398 self._state.following.pop()
2399 self.match(self.input, 36, self.FOLLOW_36_in_subcondition21374)
2400
2401
2402 input = fuzzy.operator.Compound.Compound(norm, c4, c5)
2403
2404
2405
2406
2407
2408
2409
2410
2411 except RecognitionException:
2412 re = sys.exc_info()[1]
2413 self.reportError(re)
2414 self.recover(self.input, re)
2415 finally:
2416
2417 pass
2418
2419 return input
2420
2421
2422
2423
2424
2425
2427
2428 adjs = None
2429
2430 c1 = None
2431
2432 c2 = None
2433
2434
2435
2436 _adjs = []
2437
2438 try:
2439 try:
2440
2441
2442 pass
2443
2444
2445 pass
2446
2447
2448 pass
2449 self._state.following.append(self.FOLLOW_conclusion2_in_conclusion1422)
2450 c1 = self.conclusion2()
2451
2452 self._state.following.pop()
2453
2454 _adjs.append(c1);
2455
2456
2457
2458
2459
2460 while True:
2461 alt35 = 2
2462 LA35_0 = self.input.LA(1)
2463
2464 if (LA35_0 == 35) :
2465 alt35 = 1
2466
2467
2468 if alt35 == 1:
2469
2470 pass
2471 self.match(self.input, 35, self.FOLLOW_35_in_conclusion1436)
2472 self._state.following.append(self.FOLLOW_conclusion2_in_conclusion1440)
2473 c2 = self.conclusion2()
2474
2475 self._state.following.pop()
2476
2477 _adjs.append(c2);
2478
2479
2480
2481 else:
2482 break
2483
2484
2485
2486
2487
2488
2489 adjs = _adjs
2490
2491
2492
2493
2494
2495 except RecognitionException:
2496 re = sys.exc_info()[1]
2497 self.reportError(re)
2498 self.recover(self.input, re)
2499 finally:
2500
2501 pass
2502
2503 return adjs
2504
2505
2506
2507
2508
2509
2511
2512 adj = None
2513
2514 c2 = None
2515
2516 c1 = None
2517
2518
2519 try:
2520 try:
2521
2522 alt36 = 2
2523 LA36_0 = self.input.LA(1)
2524
2525 if (LA36_0 == 34) :
2526 alt36 = 1
2527 elif (LA36_0 == Identifier) :
2528 alt36 = 2
2529 else:
2530 nvae = NoViableAltException("", 36, 0, self.input)
2531
2532 raise nvae
2533
2534 if alt36 == 1:
2535
2536 pass
2537
2538
2539 pass
2540 self.match(self.input, 34, self.FOLLOW_34_in_conclusion21474)
2541 self._state.following.append(self.FOLLOW_conclusion3_in_conclusion21478)
2542 c2 = self.conclusion3()
2543
2544 self._state.following.pop()
2545 self.match(self.input, 36, self.FOLLOW_36_in_conclusion21481)
2546
2547 adj = c2
2548
2549
2550
2551
2552
2553
2554 elif alt36 == 2:
2555
2556 pass
2557
2558
2559 pass
2560 self._state.following.append(self.FOLLOW_conclusion3_in_conclusion21501)
2561 c1 = self.conclusion3()
2562
2563 self._state.following.pop()
2564
2565 adj = c1
2566
2567
2568
2569
2570
2571
2572
2573 except RecognitionException:
2574 re = sys.exc_info()[1]
2575 self.reportError(re)
2576 self.recover(self.input, re)
2577 finally:
2578
2579 pass
2580
2581 return adj
2582
2583
2584
2585
2586
2587
2589
2590 adj = None
2591
2592 v2 = None
2593
2594 t2 = None
2595
2596
2597 try:
2598 try:
2599
2600
2601 pass
2602
2603
2604 pass
2605
2606
2607 pass
2608 self._state.following.append(self.FOLLOW_variable_name_in_conclusion31538)
2609 v2 = self.variable_name()
2610
2611 self._state.following.pop()
2612 self.match(self.input, 54, self.FOLLOW_54_in_conclusion31540)
2613 self._state.following.append(self.FOLLOW_term_name_in_conclusion31544)
2614 t2 = self.term_name()
2615
2616 self._state.following.pop()
2617
2618 adj = self.System.variables[((v2 is not None) and [self.input.toString(v2.start,v2.stop)] or [None])[0]].adjectives[((t2 is not None) and [self.input.toString(t2.start,t2.stop)] or [None])[0]]
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630 except RecognitionException:
2631 re = sys.exc_info()[1]
2632 self.reportError(re)
2633 self.recover(self.input, re)
2634 finally:
2635
2636 pass
2637
2638 return adj
2639
2640
2641
2642
2643
2644
2645 - def rule(self, block_name):
2646
2647 Integer_literal26 = None
2648 weighting_factor23 = None
2649
2650 condition24 = None
2651
2652 conclusion25 = None
2653
2654
2655
2656 certainty = 1.0
2657
2658 try:
2659 try:
2660
2661
2662 pass
2663 self.match(self.input, 56, self.FOLLOW_56_in_rule1568)
2664 Integer_literal26=self.match(self.input, Integer_literal, self.FOLLOW_Integer_literal_in_rule1570)
2665 self.match(self.input, 18, self.FOLLOW_18_in_rule1572)
2666 self.match(self.input, 57, self.FOLLOW_57_in_rule1574)
2667 self._state.following.append(self.FOLLOW_condition_in_rule1576)
2668 condition24 = self.condition()
2669
2670 self._state.following.pop()
2671 self.match(self.input, 58, self.FOLLOW_58_in_rule1578)
2672 self._state.following.append(self.FOLLOW_conclusion_in_rule1580)
2673 conclusion25 = self.conclusion()
2674
2675 self._state.following.pop()
2676
2677 alt37 = 2
2678 LA37_0 = self.input.LA(1)
2679
2680 if (LA37_0 == 59) :
2681 alt37 = 1
2682 if alt37 == 1:
2683
2684 pass
2685 self.match(self.input, 59, self.FOLLOW_59_in_rule1583)
2686 self._state.following.append(self.FOLLOW_weighting_factor_in_rule1585)
2687 weighting_factor23 = self.weighting_factor()
2688
2689 self._state.following.pop()
2690
2691 certainty = float(((weighting_factor23 is not None) and [self.input.toString(weighting_factor23.start,weighting_factor23.stop)] or [None])[0]);
2692
2693
2694
2695
2696 self.match(self.input, 20, self.FOLLOW_20_in_rule1591)
2697
2698
2699 input = condition24
2700 adjective = conclusion25
2701 self.System.rules[block_name+'.'+Integer_literal26.text] = fuzzy.Rule.Rule(adjective, input, certainty=certainty)
2702
2703
2704
2705
2706
2707
2708 except RecognitionException:
2709 re = sys.exc_info()[1]
2710 self.reportError(re)
2711 self.recover(self.input, re)
2712 finally:
2713
2714 pass
2715
2716 return
2717
2718
2719
2722 ParserRuleReturnScope.__init__(self)
2723
2724
2725
2726
2727
2728
2729
2731
2732 retval = self.weighting_factor_return()
2733 retval.start = self.input.LT(1)
2734
2735 try:
2736 try:
2737
2738
2739 pass
2740 self._state.following.append(self.FOLLOW_numeric_literal_in_weighting_factor1606)
2741 self.numeric_literal()
2742
2743 self._state.following.pop()
2744
2745
2746
2747 retval.stop = self.input.LT(-1)
2748
2749
2750 except RecognitionException:
2751 re = sys.exc_info()[1]
2752 self.reportError(re)
2753 self.recover(self.input, re)
2754 finally:
2755
2756 pass
2757
2758 return retval
2759
2760
2761
2764 ParserRuleReturnScope.__init__(self)
2765
2766
2767
2768
2769
2770
2771
2773
2774 retval = self.function_block_name_return()
2775 retval.start = self.input.LT(1)
2776
2777 try:
2778 try:
2779
2780
2781 pass
2782 self.match(self.input, Identifier, self.FOLLOW_Identifier_in_function_block_name1617)
2783
2784
2785
2786 retval.stop = self.input.LT(-1)
2787
2788
2789 except RecognitionException:
2790 re = sys.exc_info()[1]
2791 self.reportError(re)
2792 self.recover(self.input, re)
2793 finally:
2794
2795 pass
2796
2797 return retval
2798
2799
2800
2803 ParserRuleReturnScope.__init__(self)
2804
2805
2806
2807
2808
2809
2810
2812
2813 retval = self.rule_block_name_return()
2814 retval.start = self.input.LT(1)
2815
2816 try:
2817 try:
2818
2819
2820 pass
2821 self.match(self.input, Identifier, self.FOLLOW_Identifier_in_rule_block_name1625)
2822
2823
2824
2825 retval.stop = self.input.LT(-1)
2826
2827
2828 except RecognitionException:
2829 re = sys.exc_info()[1]
2830 self.reportError(re)
2831 self.recover(self.input, re)
2832 finally:
2833
2834 pass
2835
2836 return retval
2837
2838
2839
2842 ParserRuleReturnScope.__init__(self)
2843
2844
2845
2846
2847
2848
2849
2851
2852 retval = self.term_name_return()
2853 retval.start = self.input.LT(1)
2854
2855 try:
2856 try:
2857
2858
2859 pass
2860 self.match(self.input, Identifier, self.FOLLOW_Identifier_in_term_name1633)
2861
2862
2863
2864 retval.stop = self.input.LT(-1)
2865
2866
2867 except RecognitionException:
2868 re = sys.exc_info()[1]
2869 self.reportError(re)
2870 self.recover(self.input, re)
2871 finally:
2872
2873 pass
2874
2875 return retval
2876
2877
2878
2881 ParserRuleReturnScope.__init__(self)
2882
2883
2884
2885
2886
2887
2888
2890
2891 retval = self.f_variable_name_return()
2892 retval.start = self.input.LT(1)
2893
2894 try:
2895 try:
2896
2897
2898 pass
2899 self.match(self.input, Identifier, self.FOLLOW_Identifier_in_f_variable_name1641)
2900
2901
2902
2903 retval.stop = self.input.LT(-1)
2904
2905
2906 except RecognitionException:
2907 re = sys.exc_info()[1]
2908 self.reportError(re)
2909 self.recover(self.input, re)
2910 finally:
2911
2912 pass
2913
2914 return retval
2915
2916
2917
2920 ParserRuleReturnScope.__init__(self)
2921
2922
2923
2924
2925
2926
2927
2929
2930 retval = self.variable_name_return()
2931 retval.start = self.input.LT(1)
2932
2933 try:
2934 try:
2935
2936
2937 pass
2938 self.match(self.input, Identifier, self.FOLLOW_Identifier_in_variable_name1649)
2939
2940
2941
2942 retval.stop = self.input.LT(-1)
2943
2944
2945 except RecognitionException:
2946 re = sys.exc_info()[1]
2947 self.reportError(re)
2948 self.recover(self.input, re)
2949 finally:
2950
2951 pass
2952
2953 return retval
2954
2955
2956
2959 ParserRuleReturnScope.__init__(self)
2960
2961
2962
2963
2964
2965
2966
2968
2969 retval = self.numeric_literal_return()
2970 retval.start = self.input.LT(1)
2971
2972 try:
2973 try:
2974
2975
2976 pass
2977 if (Integer_literal <= self.input.LA(1) <= Real_literal):
2978 self.input.consume()
2979 self._state.errorRecovery = False
2980
2981 else:
2982 mse = MismatchedSetException(None, self.input)
2983 raise mse
2984
2985
2986
2987
2988
2989 retval.stop = self.input.LT(-1)
2990
2991
2992 except RecognitionException:
2993 re = sys.exc_info()[1]
2994 self.reportError(re)
2995 self.recover(self.input, re)
2996 finally:
2997
2998 pass
2999
3000 return retval
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010 FOLLOW_function_block_declaration_in_main55 = frozenset([1])
3011 FOLLOW_14_in_function_block_declaration71 = frozenset([4])
3012 FOLLOW_function_block_name_in_function_block_declaration77 = frozenset([15, 16, 21, 23, 24, 26, 28, 30])
3013 FOLLOW_type_definition_in_function_block_declaration85 = frozenset([15, 16, 21, 23, 24, 26, 28, 30])
3014 FOLLOW_fb_io_var_declarations_in_function_block_declaration92 = frozenset([15, 21, 23, 24, 26, 28, 30])
3015 FOLLOW_function_block_body_in_function_block_declaration100 = frozenset([15])
3016 FOLLOW_15_in_function_block_declaration106 = frozenset([])
3017 FOLLOW_EOF_in_function_block_declaration112 = frozenset([1])
3018 FOLLOW_16_in_type_definition126 = frozenset([4])
3019 FOLLOW_Identifier_in_type_definition128 = frozenset([4])
3020 FOLLOW_struct_element_in_type_definition132 = frozenset([4, 17])
3021 FOLLOW_17_in_type_definition136 = frozenset([1])
3022 FOLLOW_Identifier_in_struct_element151 = frozenset([18])
3023 FOLLOW_18_in_struct_element153 = frozenset([19])
3024 FOLLOW_19_in_struct_element155 = frozenset([20])
3025 FOLLOW_20_in_struct_element157 = frozenset([1])
3026 FOLLOW_input_declarations_in_fb_io_var_declarations172 = frozenset([1])
3027 FOLLOW_output_declarations_in_fb_io_var_declarations178 = frozenset([1])
3028 FOLLOW_21_in_input_declarations189 = frozenset([4])
3029 FOLLOW_var_decl_in_input_declarations191 = frozenset([4, 22])
3030 FOLLOW_22_in_input_declarations195 = frozenset([1])
3031 FOLLOW_23_in_output_declarations203 = frozenset([4])
3032 FOLLOW_var_decl_in_output_declarations205 = frozenset([4, 22])
3033 FOLLOW_22_in_output_declarations209 = frozenset([1])
3034 FOLLOW_Identifier_in_var_decl223 = frozenset([18])
3035 FOLLOW_18_in_var_decl227 = frozenset([4, 19])
3036 FOLLOW_type_in_var_decl231 = frozenset([20])
3037 FOLLOW_20_in_var_decl235 = frozenset([1])
3038 FOLLOW_19_in_type254 = frozenset([1])
3039 FOLLOW_Identifier_in_type264 = frozenset([1])
3040 FOLLOW_fuzzify_block_in_function_block_body286 = frozenset([1, 24, 26, 28, 30])
3041 FOLLOW_defuzzify_block_in_function_block_body293 = frozenset([1, 26, 28, 30])
3042 FOLLOW_rule_block_in_function_block_body300 = frozenset([1, 28, 30])
3043 FOLLOW_option_block_in_function_block_body307 = frozenset([1, 30])
3044 FOLLOW_24_in_fuzzify_block325 = frozenset([4])
3045 FOLLOW_variable_name_in_fuzzify_block331 = frozenset([25, 32])
3046 FOLLOW_linguistic_term_in_fuzzify_block337 = frozenset([25, 32])
3047 FOLLOW_25_in_fuzzify_block345 = frozenset([1])
3048 FOLLOW_26_in_defuzzify_block362 = frozenset([4])
3049 FOLLOW_f_variable_name_in_defuzzify_block368 = frozenset([32, 51])
3050 FOLLOW_linguistic_term_in_defuzzify_block374 = frozenset([32, 51])
3051 FOLLOW_accumulation_method_in_defuzzify_block382 = frozenset([37])
3052 FOLLOW_defuzzification_method_in_defuzzify_block388 = frozenset([27, 38, 40])
3053 FOLLOW_default_value_in_defuzzify_block395 = frozenset([27, 40])
3054 FOLLOW_range_in_defuzzify_block403 = frozenset([27])
3055 FOLLOW_27_in_defuzzify_block410 = frozenset([1])
3056 FOLLOW_28_in_rule_block427 = frozenset([4])
3057 FOLLOW_rule_block_name_in_rule_block435 = frozenset([6, 7, 29, 50, 56])
3058 FOLLOW_operator_definition_in_rule_block443 = frozenset([6, 7, 29, 50, 56])
3059 FOLLOW_activation_method_in_rule_block452 = frozenset([29, 56])
3060 FOLLOW_rule_in_rule_block461 = frozenset([29, 56])
3061 FOLLOW_29_in_rule_block469 = frozenset([1])
3062 FOLLOW_30_in_option_block477 = frozenset([31])
3063 FOLLOW_31_in_option_block481 = frozenset([1])
3064 FOLLOW_32_in_linguistic_term496 = frozenset([4])
3065 FOLLOW_term_name_in_linguistic_term498 = frozenset([33])
3066 FOLLOW_33_in_linguistic_term500 = frozenset([4, 8, 9, 34])
3067 FOLLOW_membership_function_in_linguistic_term502 = frozenset([20])
3068 FOLLOW_20_in_linguistic_term504 = frozenset([1])
3069 FOLLOW_singleton_in_membership_function526 = frozenset([1])
3070 FOLLOW_points_in_membership_function538 = frozenset([1])
3071 FOLLOW_pyfuzzy_set_in_membership_function550 = frozenset([1])
3072 FOLLOW_numeric_literal_in_singleton573 = frozenset([1])
3073 FOLLOW_variable_name_in_singleton585 = frozenset([1])
3074 FOLLOW_34_in_points617 = frozenset([4, 8, 9])
3075 FOLLOW_numeric_literal_in_points627 = frozenset([35])
3076 FOLLOW_variable_name_in_points631 = frozenset([35])
3077 FOLLOW_35_in_points639 = frozenset([8, 9])
3078 FOLLOW_numeric_literal_in_points648 = frozenset([36])
3079 FOLLOW_36_in_points655 = frozenset([1, 34])
3080 FOLLOW_Identifier_in_pyfuzzy_set699 = frozenset([34])
3081 FOLLOW_34_in_pyfuzzy_set704 = frozenset([8, 9, 36])
3082 FOLLOW_numeric_literal_in_pyfuzzy_set716 = frozenset([35, 36])
3083 FOLLOW_35_in_pyfuzzy_set732 = frozenset([8, 9])
3084 FOLLOW_numeric_literal_in_pyfuzzy_set742 = frozenset([35, 36])
3085 FOLLOW_36_in_pyfuzzy_set762 = frozenset([1])
3086 FOLLOW_37_in_defuzzification_method785 = frozenset([18])
3087 FOLLOW_18_in_defuzzification_method787 = frozenset([4])
3088 FOLLOW_Identifier_in_defuzzification_method791 = frozenset([20])
3089 FOLLOW_20_in_defuzzification_method797 = frozenset([1])
3090 FOLLOW_38_in_default_value812 = frozenset([33])
3091 FOLLOW_33_in_default_value814 = frozenset([8, 9, 39])
3092 FOLLOW_numeric_literal_in_default_value824 = frozenset([20])
3093 FOLLOW_39_in_default_value836 = frozenset([20])
3094 FOLLOW_20_in_default_value846 = frozenset([1])
3095 FOLLOW_40_in_range857 = frozenset([33])
3096 FOLLOW_33_in_range859 = frozenset([34])
3097 FOLLOW_34_in_range861 = frozenset([8, 9])
3098 FOLLOW_numeric_literal_in_range863 = frozenset([41])
3099 FOLLOW_41_in_range865 = frozenset([8, 9])
3100 FOLLOW_numeric_literal_in_range867 = frozenset([36])
3101 FOLLOW_36_in_range869 = frozenset([20])
3102 FOLLOW_20_in_range871 = frozenset([1])
3103 FOLLOW_Identifier_in_operator_name_any890 = frozenset([1, 42])
3104 FOLLOW_42_in_operator_name_any893 = frozenset([8, 9])
3105 FOLLOW_numeric_literal_in_operator_name_any897 = frozenset([43])
3106 FOLLOW_43_in_operator_name_any899 = frozenset([1])
3107 FOLLOW_44_in_operator_name_AND922 = frozenset([1])
3108 FOLLOW_45_in_operator_name_AND932 = frozenset([1])
3109 FOLLOW_46_in_operator_name_AND942 = frozenset([1])
3110 FOLLOW_operator_name_any_in_operator_name_AND955 = frozenset([1])
3111 FOLLOW_47_in_operator_name_OR976 = frozenset([1])
3112 FOLLOW_48_in_operator_name_OR986 = frozenset([1])
3113 FOLLOW_49_in_operator_name_OR996 = frozenset([1])
3114 FOLLOW_operator_name_any_in_operator_name_OR1009 = frozenset([1])
3115 FOLLOW_OR__in_operator_definition1053 = frozenset([18])
3116 FOLLOW_18_in_operator_definition1055 = frozenset([4, 47, 48, 49])
3117 FOLLOW_operator_name_OR_in_operator_definition1059 = frozenset([20])
3118 FOLLOW_AND__in_operator_definition1070 = frozenset([18])
3119 FOLLOW_18_in_operator_definition1072 = frozenset([4, 44, 45, 46, 47, 48, 49])
3120 FOLLOW_operator_name_AND_in_operator_definition1076 = frozenset([20])
3121 FOLLOW_20_in_operator_definition1085 = frozenset([1])
3122 FOLLOW_50_in_activation_method1094 = frozenset([18])
3123 FOLLOW_18_in_activation_method1096 = frozenset([44, 45])
3124 FOLLOW_set_in_activation_method1098 = frozenset([20])
3125 FOLLOW_20_in_activation_method1106 = frozenset([1])
3126 FOLLOW_51_in_accumulation_method1114 = frozenset([18])
3127 FOLLOW_18_in_accumulation_method1116 = frozenset([47, 49, 52])
3128 FOLLOW_set_in_accumulation_method1118 = frozenset([20])
3129 FOLLOW_20_in_accumulation_method1130 = frozenset([1])
3130 FOLLOW_subcondition_in_condition1161 = frozenset([1, 6, 7])
3131 FOLLOW_set_in_condition1189 = frozenset([4, 34, 47, 48, 49, 53])
3132 FOLLOW_subcondition_in_condition1211 = frozenset([1, 6, 7])
3133 FOLLOW_53_in_subcondition1251 = frozenset([34])
3134 FOLLOW_34_in_subcondition1253 = frozenset([4, 34, 47, 48, 49, 53])
3135 FOLLOW_condition_in_subcondition1255 = frozenset([36])
3136 FOLLOW_36_in_subcondition1257 = frozenset([1])
3137 FOLLOW_subcondition2_in_subcondition1269 = frozenset([1])
3138 FOLLOW_34_in_subcondition21296 = frozenset([4, 34, 47, 48, 49, 53])
3139 FOLLOW_condition_in_subcondition21300 = frozenset([36])
3140 FOLLOW_36_in_subcondition21302 = frozenset([1])
3141 FOLLOW_variable_name_in_subcondition21322 = frozenset([54, 55])
3142 FOLLOW_54_in_subcondition21325 = frozenset([4, 53])
3143 FOLLOW_53_in_subcondition21329 = frozenset([4])
3144 FOLLOW_55_in_subcondition21334 = frozenset([4])
3145 FOLLOW_term_name_in_subcondition21338 = frozenset([1])
3146 FOLLOW_operator_name_any_in_subcondition21360 = frozenset([34])
3147 FOLLOW_34_in_subcondition21362 = frozenset([4, 34, 47, 48, 49, 53])
3148 FOLLOW_condition_in_subcondition21366 = frozenset([35])
3149 FOLLOW_35_in_subcondition21368 = frozenset([4, 34, 47, 48, 49, 53])
3150 FOLLOW_condition_in_subcondition21372 = frozenset([36])
3151 FOLLOW_36_in_subcondition21374 = frozenset([1])
3152 FOLLOW_conclusion2_in_conclusion1422 = frozenset([1, 35])
3153 FOLLOW_35_in_conclusion1436 = frozenset([4, 34])
3154 FOLLOW_conclusion2_in_conclusion1440 = frozenset([1, 35])
3155 FOLLOW_34_in_conclusion21474 = frozenset([4, 34])
3156 FOLLOW_conclusion3_in_conclusion21478 = frozenset([36])
3157 FOLLOW_36_in_conclusion21481 = frozenset([1])
3158 FOLLOW_conclusion3_in_conclusion21501 = frozenset([1])
3159 FOLLOW_variable_name_in_conclusion31538 = frozenset([54])
3160 FOLLOW_54_in_conclusion31540 = frozenset([4])
3161 FOLLOW_term_name_in_conclusion31544 = frozenset([1])
3162 FOLLOW_56_in_rule1568 = frozenset([8])
3163 FOLLOW_Integer_literal_in_rule1570 = frozenset([18])
3164 FOLLOW_18_in_rule1572 = frozenset([57])
3165 FOLLOW_57_in_rule1574 = frozenset([4, 34, 47, 48, 49, 53])
3166 FOLLOW_condition_in_rule1576 = frozenset([58])
3167 FOLLOW_58_in_rule1578 = frozenset([4, 34])
3168 FOLLOW_conclusion_in_rule1580 = frozenset([20, 59])
3169 FOLLOW_59_in_rule1583 = frozenset([8, 9])
3170 FOLLOW_weighting_factor_in_rule1585 = frozenset([20])
3171 FOLLOW_20_in_rule1591 = frozenset([1])
3172 FOLLOW_numeric_literal_in_weighting_factor1606 = frozenset([1])
3173 FOLLOW_Identifier_in_function_block_name1617 = frozenset([1])
3174 FOLLOW_Identifier_in_rule_block_name1625 = frozenset([1])
3175 FOLLOW_Identifier_in_term_name1633 = frozenset([1])
3176 FOLLOW_Identifier_in_f_variable_name1641 = frozenset([1])
3177 FOLLOW_Identifier_in_variable_name1649 = frozenset([1])
3178 FOLLOW_set_in_numeric_literal0 = frozenset([1])
3179
3180
3181
3182 -def main(argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
3183 from antlr3.main import ParserMain
3184 main = ParserMain("FCLLexer", FCLParser)
3185 main.stdin = stdin
3186 main.stdout = stdout
3187 main.stderr = stderr
3188 main.execute(argv)
3189
3190
3191 if __name__ == '__main__':
3192 main(sys.argv)
3193