-
Notifications
You must be signed in to change notification settings - Fork 50
/
pddl+.y
1615 lines (1378 loc) · 48.7 KB
/
pddl+.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2019 - University of Strathclyde, King's College London and Schlumberger Ltd
// This source code is licensed under the BSD license found in the LICENSE file in the root directory of this source tree.
/**
* PDDL2.1 grammar file for bison.
*/
%start mystartsymbol
%{
/*
Error reporting:
Intention is to provide error token on most bracket expressions,
so synchronisation can occur on next CLOSE_BRAC.
Hence error should be generated for innermost expression containing error.
Expressions which cause errors return a NULL values, and parser
always attempts to carry on.
This won't behave so well if CLOSE_BRAC is missing.
Naming conventions:
Generally, the names should be similar to the PDDL2.1 spec.
During development, they have also been based on older PDDL specs,
older PDDL+ and TIM parsers, and this shows in places.
All the names of fields in the semantic value type begin with t_
Corresponding categories in the grammar begin with c_
Corresponding classes have no prefix.
PDDL grammar yacc grammar type of corresponding semantic val.
thing+ c_things thing_list
(thing+) c_thing_list thing_list
*/
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <ctype.h>
// This is now copied locally to avoid relying on installation
// of flex++.
//#include "FlexLexer.h"
//#include <FlexLexer.h>
#include "ptree.h"
#include "parse_error.h"
#define YYDEBUG 1
int yyerror(char *);
#ifndef YY_
# if YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
# define YY_(msgid) dgettext ("bison-runtime", ((char *)msgid))
# endif
# endif
# ifndef YY_
# define YY_(msgid) ((char *) msgid)
# endif
#endif
extern int yylex();
using namespace VAL;
%}
%union {
parse_category* t_parse_category;
effect_lists* t_effect_lists;
effect* t_effect;
simple_effect* t_simple_effect;
cond_effect* t_cond_effect;
forall_effect* t_forall_effect;
timed_effect* t_timed_effect;
supplied_effect* t_supplied_effect;
quantifier t_quantifier;
metric_spec* t_metric;
optimization t_optimization;
symbol* t_symbol;
var_symbol* t_var_symbol;
pddl_type* t_type;
pred_symbol* t_pred_symbol;
func_symbol* t_func_symbol;
const_symbol* t_const_symbol;
class_symbol* t_class;
parameter_symbol_list* t_parameter_symbol_list;
var_symbol_list* t_var_symbol_list;
const_symbol_list* t_const_symbol_list;
pddl_type_list* t_type_list;
proposition* t_proposition;
pred_decl* t_pred_decl;
pred_decl_list* t_pred_decl_list;
func_decl* t_func_decl;
func_decl_list* t_func_decl_list;
goal* t_goal;
con_goal * t_con_goal;
goal_list* t_goal_list;
func_term* t_func_term;
assignment* t_assignment;
expression* t_expression;
num_expression* t_num_expression;
assign_op t_assign_op;
comparison_op t_comparison_op;
structure_def* t_structure_def;
structure_store* t_structure_store;
action* t_action_def;
event* t_event_def;
process* t_process_def;
durative_action* t_durative_action_def;
derivation_rule* t_derivation_rule;
problem* t_problem;
length_spec* t_length_spec;
domain* t_domain;
pddl_req_flag t_pddl_req_flag;
plan* t_plan;
plan_step* t_step;
int ival;
double fval;
char* cp;
int t_dummy;
var_symbol_table * vtab;
class_def * t_class_def;
// classes_list* t_classes;
};
%type <t_effect_lists> c_effects c_conj_effect c_effect c_initial_state
c_a_effect c_p_effects c_p_effect c_da_effect c_da_effects c_da_cts_only_effect c_da_cts_only_effects
c_a_effect_da c_p_effect_da c_p_effects_da
c_init_els c_proc_effect c_proc_effects
%type <t_simple_effect> c_pos_simple_effect c_neg_simple_effect
c_init_pos_simple_effect c_init_neg_simple_effect
%type <t_cond_effect> c_cond_effect
%type <t_forall_effect> c_forall_effect
%type <t_timed_effect> c_timed_effect c_cts_only_timed_effect c_timed_initial_literal
%type <t_supplied_effect> c_supply_demand c_demand
//%type <t_parameter_symbol> c_parameter_symbol
%type <t_type> /* c_type */ c_primitive_type c_new_primitive_type
%type <t_pred_symbol> c_pred_symbol c_new_pred_symbol c_init_pred_symbol
%type <t_func_symbol> /* c_func_symbol */ c_new_func_symbol
%type <t_const_symbol> c_const_symbol c_new_const_symbol
%type <t_var_symbol> c_var_symbol c_declaration_var_symbol
%type <t_proposition> c_proposition c_derived_proposition c_init_proposition
%type <t_pred_decl> c_pred_decl
%type <t_pred_decl_list> c_pred_decls c_predicates
%type <t_func_decl> c_func_decl
%type <t_func_decl_list> c_func_decls c_functions_def
%type <t_parameter_symbol_list> c_parameter_symbols
%type <t_var_symbol_list> c_var_symbol_list c_typed_var_list c_control c_control_params_list
%type <t_const_symbol_list> c_const_symbols c_new_const_symbols c_typed_consts c_domain_constants c_objects
%type <t_type_list> c_primitive_types c_new_primitive_types c_typed_types c_type_names c_either_type
%type <t_goal> c_goal_descriptor c_pre_goal_descriptor c_pref_goal_descriptor c_goal_spec c_duration_constraint c_da_gd c_timed_gd c_name_or_goal_descriptor /* c_f_comp */
%type <t_con_goal> c_constraints_def c_constraints_probdef c_constraint_goal c_pref_con_goal c_pref_goal
%type <t_goal_list> c_goal_list c_pre_goal_descriptor_list c_duration_constraints c_da_gds c_constraint_goal_list c_pref_con_goal_list
%type <t_quantifier> /*c_quantifier*/ c_forall c_exists
%type <t_func_term> c_f_head /* c_new_f_head */ c_ground_f_head
%type <t_assignment> c_assignment c_f_assign_da
%type <t_expression> c_f_exp c_ground_f_exp c_binary_ground_f_exp c_f_exp_da c_f_exp_t c_binary_expr_da c_d_value c_binary_ground_f_pexps c_binary_ground_f_mexps
%type <t_num_expression> c_number
%type <t_comparison_op> c_comparison_op c_d_op
%type <t_structure_def> c_structure_def
%type <t_class_def> c_class_def
%type <t_action_def> c_action_def
%type <t_event_def> c_event_def
%type <t_process_def> c_process_def
%type <t_durative_action_def> c_durative_action_def c_da_def_body
%type <t_derivation_rule> c_derivation_rule
%type <t_structure_store> c_structure_defs
%type <t_pddl_req_flag> c_domain_require_def c_require_key c_reqs
%type <t_problem> c_problem c_problem_body
%type <t_length_spec> c_length_spec
%type <t_class> c_class c_new_class
%type <t_domain> c_domain c_preamble
%type <t_dummy> /*c_action_kind*/ c_args_head c_rule_head c_ntype c_classes c_class_seq
%type <t_optimization> c_optimization
%type <t_metric> c_metric_spec
%type <t_plan> c_plan
%type <t_step> c_step c_step_t_d c_step_d
%type <cp> c_domain_name
%type <fval> c_float
%type <vtab> c_goals;
%token <punct> OPEN_BRAC CLOSE_BRAC MODULES
OPEN_SQ CLOSE_SQ DOT CLASSES CLASS
DEFINE PDDLDOMAIN REQS EQUALITY STRIPS ADL NEGATIVE_PRECONDITIONS
TYPING DISJUNCTIVE_PRECONDS EXT_PRECS UNIV_PRECS QUANT_PRECS COND_EFFS
FLUENTS OBJECTFLUENTS NUMERICFLUENTS ACTIONCOSTS
TIME DURATIVE_ACTIONS DURATION_INEQUALITIES CONTINUOUS_EFFECTS
DERIVED_PREDICATES TIMED_INITIAL_LITERALS PREFERENCES CONSTRAINTS
ACTION PROCESS EVENT DURATIVE_ACTION DERIVED
CONSTANTS PREDS FUNCTIONS TYPES ARGS PRE CONDITION PREFERENCE
START_PRE END_PRE /* Redundant */
EFFECTS
INITIAL_EFFECT FINAL_EFFECT INVARIANT DURATION /* Redundant */
AT_START AT_END OVER_ALL
AND OR EXISTS FORALL IMPLY NOT WHEN WHENEVER EITHER
PROBLEM FORDOMAIN INITIALLY
OBJECTS GOALS EQ LENGTH SERIAL PARALLEL METRIC
MINIMIZE MAXIMIZE
HASHT DURATION_VAR TOTAL_TIME
INCREASE DECREASE SCALE_UP SCALE_DOWN ASSIGN
GREATER GREATEQ LESS LESSEQ /* EQUALS */ Q COLON NUMBER
ALWAYS SOMETIME WITHIN ATMOSTONCE SOMETIMEAFTER SOMETIMEBEFORE
ALWAYSWITHIN HOLDDURING HOLDAFTER ISVIOLATED AFTER
BOGUS CONTROL SUPPLYDEMAND SUPPLYDEMAND_REQ NAMETAG
%token <cp> NAME FUNCTION_SYMBOL
%token <ival> INTVAL
%token <fval> FLOATVAL AT_TIME
%left HYPHEN PLUS
%left MUL DIV
%left UMINUS
%%
mystartsymbol :
c_domain {top_thing= $1; current_analysis->the_domain= $1;}
| c_problem {top_thing= $1; current_analysis->the_problem= $1;}
| c_plan {top_thing = $1;}
;
c_domain :
OPEN_BRAC DEFINE
c_domain_name c_preamble CLOSE_BRAC
{$$= $4; $$->name= $3;delete [] $3;
if (types_used && !types_defined) {
yyerrok; log_error(E_FATAL,"Syntax error in domain - no :types section, but types used in definitions.");
}
}
| OPEN_BRAC DEFINE
c_domain_name error
{yyerrok; $$=static_cast<domain*>(NULL);
log_error(E_FATAL,"Syntax error in domain"); } // Helpful?
;
// Assumes operators defns are last, and at least one of them present.
c_preamble :
c_domain_require_def c_preamble {$$= $2; $$->req= $1;}
| c_type_names c_preamble {types_defined = true; $$= $2; $$->types= $1;}
| c_domain_constants c_preamble {$$= $2; $$->constants= $1;}
| c_predicates c_preamble {$$= $2;
$$->predicates= $1; }
| c_functions_def c_preamble {$$= $2;
$$->functions= $1; }
| c_constraints_def c_preamble {$$= $2;
$$->constraints = $1;}
| c_classes c_preamble {$$ = $2;}
| c_structure_defs {$$= new domain($1); }
;
c_domain_name : OPEN_BRAC PDDLDOMAIN NAME CLOSE_BRAC {$$=$3;}
;
c_new_class : NAME { $$=current_analysis->classes_tab.new_symbol_put($1);
delete [] $1; };
c_class : NAME { $$ = current_analysis->classes_tab.symbol_get($1); delete [] $1;};
c_classes : OPEN_BRAC CLASSES c_class_seq CLOSE_BRAC {$$ = 0;};
c_class_seq : c_new_class c_class_seq {$$ = 0;}|
/* empty */ {$$ = 0;}
;
c_domain_require_def :
OPEN_BRAC REQS c_reqs CLOSE_BRAC
{
// Stash in analysis object --- we need to refer to it during parse
// but domain object is not created yet,
current_analysis->req |= $3;
$$=$3;
}
| OPEN_BRAC REQS error CLOSE_BRAC
{yyerrok;
log_error(E_FATAL,"Syntax error in requirements declaration.");
$$= 0; }
;
c_reqs :
c_reqs c_require_key { $$= $1 | $2; }
| /* empty */ { $$= 0; }
;
c_pred_decls :
c_pred_decl c_pred_decls
{$$=$2; $$->push_front($1);}
| c_pred_decl
{ $$=new pred_decl_list;
$$->push_front($1); };
c_pred_decl :
OPEN_BRAC c_new_pred_symbol c_typed_var_list CLOSE_BRAC
{$$= new pred_decl($2,$3,current_analysis->var_tab_stack.pop());}
| OPEN_BRAC error CLOSE_BRAC
{yyerrok;
// hope someone makes this error someday
log_error(E_FATAL,"Syntax error in predicate declaration.");
$$= static_cast<pred_decl*>(NULL); }
;
c_new_pred_symbol :
NAME
{ $$=current_analysis->pred_tab.new_symbol_put($1);
current_analysis->var_tab_stack.push(
current_analysis->buildPredTab());
delete [] $1; }
;
c_pred_symbol :
EQ { $$=current_analysis->pred_tab.symbol_ref("=");
requires(E_EQUALITY); }
| NAME { $$=current_analysis->pred_tab.symbol_get($1); delete [] $1; }
;
c_init_pred_symbol :
// We have a different pred_symbol rule for the initial state
// so as to exclude EQ,
// which must be parsed as assignment in initial state.
NAME { $$=current_analysis->pred_tab.symbol_get($1); delete [] $1;}
;
c_func_decls :
c_func_decls c_func_decl
{$$=$1; $$->push_back($2);}
| /* empty */ { $$=new func_decl_list; }
;
c_func_decl :
OPEN_BRAC c_new_func_symbol c_typed_var_list CLOSE_BRAC c_ntype
{$$= new func_decl($2,$3,current_analysis->var_tab_stack.pop());}
| OPEN_BRAC error CLOSE_BRAC
{yyerrok;
log_error(E_FATAL,"Syntax error in functor declaration.");
$$= NULL; }
;
c_ntype :
HYPHEN NUMBER {$$ = (int) NULL;}| /* empty */ {$$= (int) NULL;};
c_new_func_symbol :
NAME
{ $$=current_analysis->func_tab.new_symbol_put($1);
current_analysis->var_tab_stack.push(
current_analysis->buildFuncTab());
delete [] $1; }
;
//c_func_symbol :
// NAME { $$=current_analysis->func_tab.symbol_get($1); }
//;
// variables, possibly with types
c_typed_var_list : /* Type specified */
c_var_symbol_list HYPHEN c_primitive_type c_typed_var_list
{
$$= $1;
$$->set_types($3); /* Set types for variables */
$$->splice($$->end(),*$4); /* Join lists */
delete $4; /* Delete (now empty) list */
requires(E_TYPING);
types_used = true;
}
| c_var_symbol_list HYPHEN c_either_type c_typed_var_list
{
$$= $1;
$$->set_either_types($3); /* Set types for variables */
$$->splice($$->end(),*$4); /* Join lists */
delete $4; /* Delete (now empty) list */
requires(E_TYPING);
types_used = true;
}
| c_var_symbol_list /* No type specified */
{
$$= $1;
}
;
c_control_params_list : /* Currently only NUMBER types */
c_var_symbol_list HYPHEN NUMBER c_control_params_list
{
$$= $1;
$$->set_types(0); /* Set types for variables */
$$->splice($$->end(),*$4); /* Join lists */
delete $4; /* Delete (now empty) list */
} | /* Empty */ {$$ = new var_symbol_list;}
;
// a list of variables (excluding type declaration)
// Semantic value is a list of symbols
c_var_symbol_list :
Q c_declaration_var_symbol c_var_symbol_list
{$$=$3; $3->push_front($2); }
| /* Empty */ {$$= new var_symbol_list; }
;
// A list of constants (object names or types), possibly with parent types
c_typed_consts :
/* Type specified */
c_new_const_symbols HYPHEN c_primitive_type c_typed_consts
{
$$= $1;
$1->set_types($3); /* Set types for constants */
$1->splice($1->end(),*$4); /* Join lists */
delete $4; /* Delete (now empty) list */
requires(E_TYPING);
types_used = true;
}
| c_new_const_symbols HYPHEN c_either_type c_typed_consts
{
$$= $1;
$1->set_either_types($3);
$1->splice($1->end(),*$4);
delete $4;
requires(E_TYPING);
types_used = true;
}
| /* No type specified */
c_new_const_symbols {$$= $1;}
;
// A list of object names without parent types
c_const_symbols :
c_const_symbol c_const_symbols {$$=$2; $2->push_front($1);}
| /* Empty */ {$$=new const_symbol_list;}
;
c_new_const_symbols :
c_new_const_symbol c_new_const_symbols {$$=$2; $2->push_front($1);}
| /* Empty */ {$$=new const_symbol_list;}
;
// As above, but for PDDL types
// possibly with parent types
c_typed_types :
// Type specified
c_new_primitive_types HYPHEN c_primitive_type c_typed_types
{
$$= $1;
$$->set_types($3); /* Set types for constants */
$$->splice($$->end(),*$4); /* Join lists */
delete $4; /* Delete (now empty) list */
}
| c_new_primitive_types HYPHEN c_either_type c_typed_types
{
// This parse needs to be excluded, we think (DPL&MF: 6/9/01)
$$= $1;
$$->set_either_types($3);
$$->splice($1->end(),*$4);
delete $4;
}
| // No parent type specified
c_new_primitive_types
{ $$= $1; }
;
// constants or variables (excluding type declaration)
c_parameter_symbols :
c_parameter_symbols c_const_symbol
{$$=$1; $$->push_back($2); }
| c_parameter_symbols Q c_var_symbol
{$$=$1; $$->push_back($3); }
| /* Empty */ {$$= new parameter_symbol_list;}
;
// Used in declaration of variable
// - var symbol is added to var table at top of stack
c_declaration_var_symbol :
NAME { $$= current_analysis->var_tab_stack.top()->symbol_put($1); delete [] $1; }
;
// Used when variable is expected to have already been declared.
// The lookup is an operation on the whole stack of variable tables.
c_var_symbol :
NAME { $$= current_analysis->var_tab_stack.symbol_get($1); delete [] $1; }
| AFTER { $$ = current_analysis->var_tab_stack.symbol_get("after");} // Oddity to deal with "after" as a variable name
;
c_const_symbol :
NAME { $$= current_analysis->const_tab.symbol_get($1); delete [] $1; }
;
c_new_const_symbol :
NAME { $$= current_analysis->const_tab.new_symbol_put($1); delete [] $1;}
;
c_either_type :
OPEN_BRAC EITHER c_primitive_types CLOSE_BRAC
{ $$= $3; }
;
c_new_primitive_type :
NAME
{ $$= current_analysis->pddl_type_tab.symbol_ref($1); delete [] $1;}
// We use symbol ref here in order to support multiple declarations of
// a type symbol - this is required for multiple inheritance.
;
c_primitive_type :
NAME
{ $$= current_analysis->pddl_type_tab.symbol_ref($1); delete [] $1;}
;
c_new_primitive_types :
c_new_primitive_types c_new_primitive_type
{$$= $1; $$->push_back($2);}
| /* empty */ {$$= new pddl_type_list;}
;
c_primitive_types :
c_primitive_types c_primitive_type
{$$= $1; $$->push_back($2);}
| /* empty */ {$$= new pddl_type_list;}
;
c_init_els :
c_init_els OPEN_BRAC EQ c_f_head c_number CLOSE_BRAC
{ $$=$1;
$$->assign_effects.push_back(new assignment($4,E_ASSIGN,$5));
if($4->getFunction()->getName()=="total-cost")
{
requires(E_ACTIONCOSTS);
// Should also check that $5 is 0...
}
else
{
requires(E_NFLUENTS);
}
}
| c_init_els c_init_pos_simple_effect
{ $$=$1; $$->add_effects.push_back($2); }
| c_init_els c_init_neg_simple_effect
{ $$=$1; $$->del_effects.push_back($2); }
| c_init_els c_timed_initial_literal
{ $$=$1; $$->timed_effects.push_back($2); }
| c_init_els c_supply_demand
{$$ = $1; $$->supplied_effects.push_back($2); }
| /* empty */
{ $$= new effect_lists;}
;
c_supply_demand :
OPEN_BRAC SUPPLYDEMAND NAME c_goal_descriptor c_demand
{$$ = $5; $5->sup = $4; $5->name = current_analysis->op_tab.symbol_put($3);
delete [] $3; requires(E_SUPPLYDEMAND);}
;
c_demand :
c_timed_gd c_number c_effects CLOSE_BRAC
{$$ = new supplied_effect(0,$1,$2->double_value(),$3); delete $2;}
| c_number c_effects CLOSE_BRAC
{$$ = new supplied_effect(0,0,$1->double_value(),$2); delete $1;}
;
c_timed_initial_literal :
OPEN_BRAC AT_TIME c_init_els CLOSE_BRAC
{ requires(E_TIMED_INITIAL_LITERALS);
$$=new timed_initial_literal($3,$2);}
;
c_effects :
c_a_effect c_effects {$$=$2; $$->append_effects($1); delete $1;}
| c_cond_effect c_effects {$$=$2; $$->cond_effects.push_front($1);
requires(E_COND_EFFS);}
| c_forall_effect c_effects {$$=$2; $$->forall_effects.push_front($1);
requires(E_COND_EFFS);}
| /* nothing */ {$$=new effect_lists(); }
;
// Parse a single effect as effect_lists
// Wasteful, but we get the benefit of categorising effect, and
// we will often need the lists when normalising the contained effects.
// e.g. conjunctive effects will immediately collapse into this structure.
c_effect :
c_conj_effect {$$= $1;}
| c_pos_simple_effect {$$=new effect_lists; $$->add_effects.push_front($1);}
| c_neg_simple_effect {$$=new effect_lists; $$->del_effects.push_front($1);}
| c_cond_effect {$$=new effect_lists; $$->cond_effects.push_front($1);}
| c_forall_effect {$$=new effect_lists; $$->forall_effects.push_front($1);}
;
c_a_effect :
OPEN_BRAC AND c_p_effects CLOSE_BRAC {$$= $3;}
| c_p_effect {$$= $1;}
;
c_p_effect :
c_neg_simple_effect
{$$=new effect_lists; $$->del_effects.push_front($1);}
| c_pos_simple_effect
{$$=new effect_lists; $$->add_effects.push_front($1);}
| c_assignment
{$$=new effect_lists; $$->assign_effects.push_front($1);
requires(E_NFLUENTS);}
;
c_p_effects :
c_p_effects c_neg_simple_effect {$$= $1; $$->del_effects.push_back($2);}
| c_p_effects c_pos_simple_effect {$$= $1; $$->add_effects.push_back($2);}
| c_p_effects c_assignment {$$= $1; $$->assign_effects.push_back($2);
requires(E_NFLUENTS); }
| /* empty */ { $$= new effect_lists; }
;
c_conj_effect :
OPEN_BRAC AND c_effects CLOSE_BRAC
{ $$=$3; }
| OPEN_BRAC AND error CLOSE_BRAC
{yyerrok; $$=NULL;
log_error(E_FATAL,"Syntax error in (and ...)");
}
;
c_da_effect :
OPEN_BRAC AND c_da_effects CLOSE_BRAC
{ $$=$3; }
| OPEN_BRAC c_forall
OPEN_BRAC c_typed_var_list CLOSE_BRAC
c_da_effect
CLOSE_BRAC
{ $$= new effect_lists;
$$->forall_effects.push_back(
new forall_effect($6, $4, current_analysis->var_tab_stack.pop()));
requires(E_COND_EFFS);}
| OPEN_BRAC WHEN c_da_gd c_da_effect CLOSE_BRAC
{ $$= new effect_lists;
$$->cond_effects.push_back(
new cond_effect($3,$4));
requires(E_COND_EFFS); }
| OPEN_BRAC WHENEVER c_goal_descriptor c_da_cts_only_effect CLOSE_BRAC
{ $$= new effect_lists;
$$->cond_assign_effects.push_back(
new cond_effect($3,$4));
requires(E_COND_EFFS); }
| c_timed_effect
{ $$=new effect_lists;
$$->timed_effects.push_back($1); }
| c_assignment
{ $$= new effect_lists;
$$->assign_effects.push_front($1);
requires(E_NFLUENTS); }
;
c_da_effects :
c_da_effects c_da_effect { $$=$1; $1->append_effects($2); delete $2; }
| /* empty */ { $$= new effect_lists; }
;
c_timed_effect :
OPEN_BRAC AT_START c_a_effect_da CLOSE_BRAC
{$$=new timed_effect($3,E_AT_START);}
| OPEN_BRAC AT_END c_a_effect_da CLOSE_BRAC
{$$=new timed_effect($3,E_AT_END);}
| OPEN_BRAC INCREASE c_f_head c_f_exp_t CLOSE_BRAC
{$$=new timed_effect(new effect_lists,E_CONTINUOUS);
$$->effs->assign_effects.push_front(
new assignment($3,E_INCREASE,$4)); }
| OPEN_BRAC DECREASE c_f_head c_f_exp_t CLOSE_BRAC
{$$=new timed_effect(new effect_lists,E_CONTINUOUS);
$$->effs->assign_effects.push_front(
new assignment($3,E_DECREASE,$4)); }
| OPEN_BRAC error CLOSE_BRAC
{yyerrok; $$=NULL;
log_error(E_FATAL,"Syntax error in timed effect"); }
;
c_cts_only_timed_effect :
OPEN_BRAC INCREASE c_f_head c_f_exp_t CLOSE_BRAC
{$$=new timed_effect(new effect_lists,E_CONTINUOUS);
$$->effs->assign_effects.push_front(
new assignment($3,E_INCREASE,$4)); }
| OPEN_BRAC DECREASE c_f_head c_f_exp_t CLOSE_BRAC
{$$=new timed_effect(new effect_lists,E_CONTINUOUS);
$$->effs->assign_effects.push_front(
new assignment($3,E_DECREASE,$4)); }
| OPEN_BRAC error CLOSE_BRAC
{yyerrok; $$=NULL;
log_error(E_FATAL,"Syntax error in conditional continuous effect"); }
;
c_da_cts_only_effect :
OPEN_BRAC AND c_da_cts_only_effects CLOSE_BRAC
{ $$=$3; }
| OPEN_BRAC c_forall
OPEN_BRAC c_typed_var_list CLOSE_BRAC
c_da_cts_only_effect
CLOSE_BRAC
{ $$= new effect_lists;
$$->forall_effects.push_back(
new forall_effect($6, $4, current_analysis->var_tab_stack.pop()));
requires(E_COND_EFFS);}
| OPEN_BRAC WHENEVER c_goal_descriptor c_da_cts_only_effect CLOSE_BRAC
{ $$= new effect_lists;
$$->cond_assign_effects.push_back(
new cond_effect($3,$4));
requires(E_COND_EFFS); }
| c_cts_only_timed_effect
{ $$=new effect_lists;
$$->timed_effects.push_back($1); }
;
c_da_cts_only_effects :
c_da_cts_only_effects c_da_cts_only_effect { $$=$1; $1->append_effects($2); delete $2; }
| /* empty */ { $$= new effect_lists; }
;
c_a_effect_da :
OPEN_BRAC AND c_p_effects_da CLOSE_BRAC {$$= $3;}
| c_p_effect_da {$$= $1;}
;
c_p_effect_da :
c_neg_simple_effect
{$$=new effect_lists; $$->del_effects.push_front($1);}
| c_pos_simple_effect
{$$=new effect_lists; $$->add_effects.push_front($1);}
| c_f_assign_da
{$$=new effect_lists; $$->assign_effects.push_front($1);
requires(E_NFLUENTS);}
;
c_p_effects_da :
c_p_effects_da c_neg_simple_effect {$$= $1; $$->del_effects.push_back($2);}
| c_p_effects_da c_pos_simple_effect {$$= $1; $$->add_effects.push_back($2);}
| c_p_effects_da c_f_assign_da {$$= $1; $$->assign_effects.push_back($2);
requires(E_NFLUENTS); }
| /* empty */ { $$= new effect_lists; }
;
c_f_assign_da :
OPEN_BRAC ASSIGN c_f_head c_f_exp_da CLOSE_BRAC
{ $$= new assignment($3,E_ASSIGN,$4); }
| OPEN_BRAC INCREASE c_f_head c_f_exp_da CLOSE_BRAC
{ $$= new assignment($3,E_INCREASE,$4); }
| OPEN_BRAC DECREASE c_f_head c_f_exp_da CLOSE_BRAC
{ $$= new assignment($3,E_DECREASE,$4); }
| OPEN_BRAC SCALE_UP c_f_head c_f_exp_da CLOSE_BRAC
{ $$= new assignment($3,E_SCALE_UP,$4); }
| OPEN_BRAC SCALE_DOWN c_f_head c_f_exp_da CLOSE_BRAC
{ $$= new assignment($3,E_SCALE_DOWN,$4); }
;
c_proc_effect :
OPEN_BRAC INCREASE c_f_head c_f_exp_t CLOSE_BRAC
{$$=new effect_lists;
timed_effect * te = new timed_effect(new effect_lists,E_CONTINUOUS);
$$->timed_effects.push_front(te);
te->effs->assign_effects.push_front(
new assignment($3,E_INCREASE,$4)); }
| OPEN_BRAC DECREASE c_f_head c_f_exp_t CLOSE_BRAC
{$$=new effect_lists;
timed_effect * te = new timed_effect(new effect_lists,E_CONTINUOUS);
$$->timed_effects.push_front(te);
te->effs->assign_effects.push_front(
new assignment($3,E_DECREASE,$4)); }
| OPEN_BRAC AND c_proc_effects CLOSE_BRAC
{$$ = $3;}
;
c_proc_effects :
c_proc_effects c_proc_effect { $$=$1; $1->append_effects($2); delete $2; }
| /* empty */ { $$= new effect_lists; }
;
c_f_exp_da :
c_binary_expr_da {$$= $1;}
| Q DURATION_VAR {$$= new special_val_expr(E_DURATION_VAR);
requires( E_DURATION_INEQUALITIES );}
| c_number { $$=$1; }
| c_f_head { $$= $1; }
| Q NAME { $$ = current_analysis->getControlParam($2); delete [] $2;}
;
c_binary_expr_da :
OPEN_BRAC PLUS c_f_exp_da c_f_exp_da CLOSE_BRAC
{ $$= new plus_expression($3,$4); }
| OPEN_BRAC HYPHEN c_f_exp_da c_f_exp_da CLOSE_BRAC
{ $$= new minus_expression($3,$4); }
| OPEN_BRAC MUL c_f_exp_da c_f_exp_da CLOSE_BRAC
{ $$= new mul_expression($3,$4); }
| OPEN_BRAC DIV c_f_exp_da c_f_exp_da CLOSE_BRAC
{ $$= new div_expression($3,$4); }
;
c_duration_constraint :
OPEN_BRAC AND c_duration_constraints CLOSE_BRAC
{ $$= new conj_goal($3); }
| OPEN_BRAC c_d_op Q DURATION_VAR c_d_value CLOSE_BRAC
{ $$= new timed_goal(new comparison($2,
new special_val_expr(E_DURATION_VAR),$5),E_AT_START); }
| OPEN_BRAC AT_START OPEN_BRAC c_d_op Q DURATION_VAR c_d_value CLOSE_BRAC CLOSE_BRAC
{ $$ = new timed_goal(new comparison($4,
new special_val_expr(E_DURATION_VAR),$7),E_AT_START);}
| OPEN_BRAC AT_END OPEN_BRAC c_d_op Q DURATION_VAR c_d_value CLOSE_BRAC CLOSE_BRAC
{ $$ = new timed_goal(new comparison($4,
new special_val_expr(E_DURATION_VAR),$7),E_AT_END);}
;
c_d_op :
LESSEQ {$$= E_LESSEQ; requires(E_DURATION_INEQUALITIES);}
| GREATEQ {$$= E_GREATEQ; requires(E_DURATION_INEQUALITIES);}
| EQ {$$= E_EQUALS; }
;
c_d_value :
// Fix: c_number doesn't apparently require E_FLUENTS
// some needs to be included as separate item.
// c_number {$$= $1;}
//|
c_f_exp {$$= $1; }
;
c_duration_constraints :
c_duration_constraints c_duration_constraint
{ $$=$1; $$->push_back($2); }
| /* empty */
{ $$= new goal_list; }
;
c_neg_simple_effect :
OPEN_BRAC NOT c_proposition CLOSE_BRAC
{ $$= new simple_effect($3); }
;
c_pos_simple_effect :
c_proposition
{ $$= new simple_effect($1); }
;
/* init versions disallow equality as a predicate */
c_init_neg_simple_effect :
OPEN_BRAC NOT c_init_proposition CLOSE_BRAC
{ $$= new simple_effect($3); }
;
c_init_pos_simple_effect :
c_init_proposition
{ $$= new simple_effect($1); }
;
c_forall_effect :
OPEN_BRAC c_forall OPEN_BRAC c_typed_var_list CLOSE_BRAC c_effect CLOSE_BRAC
{ $$= new forall_effect($6, $4, current_analysis->var_tab_stack.pop());}
;
c_cond_effect :
OPEN_BRAC WHEN c_goal_descriptor c_effects CLOSE_BRAC
{ $$= new cond_effect($3,$4); }
;
c_assignment :
OPEN_BRAC ASSIGN c_f_head c_f_exp CLOSE_BRAC
{ $$= new assignment($3,E_ASSIGN,$4); }
| OPEN_BRAC INCREASE c_f_head c_f_exp CLOSE_BRAC
{ $$= new assignment($3,E_INCREASE,$4); }
| OPEN_BRAC DECREASE c_f_head c_f_exp CLOSE_BRAC
{ $$= new assignment($3,E_DECREASE,$4); }
| OPEN_BRAC SCALE_UP c_f_head c_f_exp CLOSE_BRAC
{ $$= new assignment($3,E_SCALE_UP,$4); }
| OPEN_BRAC SCALE_DOWN c_f_head c_f_exp CLOSE_BRAC
{ $$= new assignment($3,E_SCALE_DOWN,$4); }
;
c_f_exp :
OPEN_BRAC HYPHEN c_f_exp CLOSE_BRAC %prec UMINUS
{ $$= new uminus_expression($3); requires(E_NFLUENTS); }
| OPEN_BRAC PLUS c_f_exp c_f_exp CLOSE_BRAC
{ $$= new plus_expression($3,$4); requires(E_NFLUENTS); }
| OPEN_BRAC HYPHEN c_f_exp c_f_exp CLOSE_BRAC
{ $$= new minus_expression($3,$4); requires(E_NFLUENTS); }
| OPEN_BRAC MUL c_f_exp c_f_exp CLOSE_BRAC
{ $$= new mul_expression($3,$4); requires(E_NFLUENTS); }
| OPEN_BRAC DIV c_f_exp c_f_exp CLOSE_BRAC
{ $$= new div_expression($3,$4); requires(E_NFLUENTS); }
| c_number { $$=$1; }
| Q NAME { $$ = current_analysis->getControlParam($2); delete [] $2;}
| c_f_head { $$= $1; requires(E_NFLUENTS); }
;
c_f_exp_t :
OPEN_BRAC MUL HASHT c_f_exp CLOSE_BRAC
{ $$= new mul_expression(new special_val_expr(E_HASHT),$4); }
| OPEN_BRAC MUL c_f_exp HASHT CLOSE_BRAC
{ $$= new mul_expression($3, new special_val_expr(E_HASHT)); }
| HASHT
{ $$= new special_val_expr(E_HASHT); }
;
c_number :
INTVAL { $$=new int_expression($1); }
| FLOATVAL { $$=new float_expression($1); };
c_f_head :
OPEN_BRAC FUNCTION_SYMBOL c_parameter_symbols CLOSE_BRAC
{ $$=new func_term( current_analysis->func_tab.symbol_get($2), $3); delete [] $2; }
// "Undeclared function symbol" case
| OPEN_BRAC NAME c_parameter_symbols CLOSE_BRAC
{ $$=new func_term( current_analysis->func_tab.symbol_get($2), $3); delete [] $2; }
| FUNCTION_SYMBOL
{ $$=new func_term( current_analysis->func_tab.symbol_get($1),
new parameter_symbol_list); delete [] $1;}
| OPEN_BRAC c_class DOT FUNCTION_SYMBOL c_parameter_symbols CLOSE_BRAC
{ $$ = new class_func_term( $2, current_analysis->func_tab.symbol_get($4), $5); delete [] $4;}
;
// c_new_f_head :
// OPEN_BRAC NAME c_parameter_symbol_list CLOSE_BRAC
// { $$=new func_term( current_analysis->func_tab.symbol_put($2), $3); }
// | NAME
// { $$=new func_term( current_analysis->func_tab.symbol_put($1),
// new parameter_symbol_list); }
// ;
c_ground_f_head :
/* Fix: Should restrict to constants, as in: */
/* NAME c_const_symbols */
/* ... but don't want to return a thing of type const list */
OPEN_BRAC FUNCTION_SYMBOL c_parameter_symbols CLOSE_BRAC
{ $$=new func_term( current_analysis->func_tab.symbol_get($2), $3); delete [] $2; }
| OPEN_BRAC NAME c_parameter_symbols CLOSE_BRAC
{ $$=new func_term( current_analysis->func_tab.symbol_get($2), $3); delete [] $2; }
| FUNCTION_SYMBOL
{ $$=new func_term( current_analysis->func_tab.symbol_get($1),
new parameter_symbol_list); delete [] $1;}
;
c_comparison_op :
GREATER { $$= E_GREATER; }
| GREATEQ { $$= E_GREATEQ; }
| LESS { $$= E_LESS; }
| LESSEQ { $$= E_LESSEQ; }
| EQ { $$= E_EQUALS; }
;
//c_f_comp :
// OPEN_BRAC c_comparison_op c_f_exp c_f_exp CLOSE_BRAC
// Goals
// FIX: PDDL BNF distinguishes between -ve literals and general -ve goals.
// (different reqs)
c_pre_goal_descriptor :
c_pref_goal_descriptor
{$$= $1;}
/*| c_goal_descriptor