-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.y
3080 lines (2883 loc) · 82.7 KB
/
parser.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 (C) 2006 Universitat Pompeu Fabra
*
* Permission is hereby granted to distribute this software for
* non-commercial research purposes, provided that this copyright
* notice is included with any such distribution.
*
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
* SOFTWARE IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU
* ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
*
* Blai Bonet, [email protected]
* Hector Palacios, [email protected], [email protected]
*
*/
#include <stdio.h>
#include <assert.h>
#include <iostream>
#include <map>
#include <nnf.h>
#include "parser.h"
#include "planner.h"
#ifdef USE_CLAUSE
#include "clauses.hpp"
#endif
// Sometimes it use a lot the stack...
#define YYINITDEPTH 5000
extern int yylex(void);
using namespace std;
/*******************************************************************************
**
** Global Data
**
******************************************************************************/
int _low_numberSchema = 0;
char* _low_yyfile = NULL;
char* _low_problemName = NULL;
char* _low_domainName = NULL;
char** _low_schemaName = NULL;
char** _low_objectName = NULL;
char** _low_predicateName = NULL;
int _low_numberPredicates = 0;
int _low_requirements = 0;
schema_t* _low_schemaTable[MAXSCHEMA];
int** _low_initialAtoms;
// operators
operator_t _low_operator;
int _low_groundingOperators;
// variables and domain instantiation
int** _low_vars = NULL;
int** _low_values = NULL;
// initial/goal formulas
formula_t* structural = NULL;
formula_t* initialSituation = NULL;
formula_t* goalSituation = NULL;
// tables
typedef map<const char*,formula_t*,ltstr> str2wff_t;
str2wff_t predicates;
str2wff_t defined;
map<const char*,idList_t*,ltstr> objects;
map<const char*,idList_t*,ltstr> types;
/*******************************************************************************
**
** Static Global Data
**
******************************************************************************/
static int domainParsed = 0;
static int maxParameters = 0;
static int numberObjects = 0;
static schema_t* schemas = NULL;
/*******************************************************************************
**
** Forward References
**
******************************************************************************/
static void checkRequirement( int );
static formula_t* unfoldQuantifiers( formula_t* );
static formula_t* linearizeEffect( formula_t*, formula_t*& );
void printFormula( FILE*, formula_t* );
void printFormulaPDDL( ostream& o, formula_t *formula );
void printInitialPDDL( ostream& out, formula_t *formula );
static nnf::node generateEffect( nnf::Manager*, nnf::node, formula_t*, int*, lit_effect_t& );
//static void collectEffectAtoms( formula_t*, int*, std::vector<int>& );
static void collectEffectAtoms( formula_t*, int*, std::vector<int>&, std::vector<int> *atoms_conds = 0 );
static nnf::node generateAtomicFormula( nnf::Manager*, formula_t *, int*, bool );
nnf::node generateFormula( nnf::Manager*, formula_t*, int*, bool );
static void collectPlainFormulaAtoms( formula_t* formula, int* parameters,
std::vector<int> &atoms );
static void collectFormulaAtomsPos( formula_t*, int*, std::vector<int>& );
static void collectFormulaAtoms( formula_t*, int*, std::vector<int>& );
static int atomId( formula_t *literal, int* parameters );
static void idMatchArgsVars( formula_t *formula, idList_t *vars );
static void generateNames( void );
static instantiation_t * buildInstantiation( idList_t *vars, idList_t *args );
static formula_t * copyReplaceFormula( formula_t *formula, instantiation_t *inst );
void yyerror( char const *s );
extern int lineno;
extern int numberAtoms;
extern iatom_t* readAtomHash( int* );
extern std::map<int,int> inv_reachable;
extern std::map<int,int> reachable;
extern unsigned time_shift;
extern bool observation_detected;
%}
%token LEFTPAR RIGHTPAR NAME DEF_NAME TWODOTS HYPHEN DEFINE
%token DOMAIN REQUIREMENTS CONSTANTS PREDICATES QUESTION
%token EITHER NOT AND OR FORALL WHEN EQUAL ACTION OBSERVE EQUALITY
%token CONDITIONAL_EFFECTS NEGATIVE_PRECONDITIONS
%token PARAMETERS PRECONDITION EFFECT
%token PROBLEM INIT GOAL STRUCTURAL SITUATION OBJECTS
%token SERIAL PARALLEL INTEGER FLOAT SET
%token TYPING STRIPS TYPES CERTAINTY KNOW UNKNOWN
%token DEFINED FORMULA ONEOF
%type <integer> INTEGER
%type <real> FLOAT
%type <ident> NAME DEF_NAME name predicate variable term
%type <integer> require_key action_type
%type <idlist> type list_type typed_list_type
%type <idlist> list_name typed_list_name
%type <idlist> list_var typed_list_var plain_or_typed_list_var
%type <idlist> list_term list_parameters
%type <body> schema_body list_schema_body
%type <body> defined_body list_defined_body
%type <formula> atomic_formula formula list_formula
%type <formula> non_det_effect_list non_det_effect
%type <formula> one_effect_formula list_one_effect_formula
%type <formula> literal goal_formula list_literal list_atomic_effect
%start start
%%
start : list_domain_problem
;
list_domain_problem
: list_domain_problem problem
| list_domain_problem domain
| /* empty */
;
/*******************************************************************************
**
** Domain Definition
**
******************************************************************************/
domain : LEFTPAR DEFINE LEFTPAR DOMAIN name RIGHTPAR
{
_low_domainName = $5;
}
LEFTPAR list_def
{
idMatchArgsVars( initialSituation, NULL );
idMatchArgsVars( goalSituation, NULL );
}
list_structure_def
{
/* how much parameters can an schema have? */
for( schema_t *sch = schemas; sch != NULL; sch = sch->next )
{
int i;
idList_t *var;
for( var = sch->vars, i = 0; var != NULL; var = var->next, ++i );
maxParameters = MAX(maxParameters,i);
}
generateNames();
}
RIGHTPAR
{
domainParsed = 1;
}
;
list_def : list_def definition LEFTPAR
| definition LEFTPAR
;
definition : REQUIREMENTS require_def
| TYPES types_def
| CONSTANTS constants_def
| PREDICATES predicates_def
;
require_def : list_require_key RIGHTPAR
;
list_require_key : list_require_key require_key
{
checkRequirement( $2 );
}
| require_key
{
checkRequirement( $1 );
}
;
require_key : TYPING
{
$$ = TYPING;
}
| CONDITIONAL_EFFECTS
{
$$ = CONDITIONAL_EFFECTS;
}
| NEGATIVE_PRECONDITIONS
{
$$ = NEGATIVE_PRECONDITIONS;
}
| EQUALITY
{
$$ = EQUALITY;
/* create the equal predicate */
formula_t *pred = (formula_t*)malloc( sizeof( formula_t ) );
pred->type = ATOMIC_FORMULA;
pred->u.atomic.id = ++_low_numberPredicates;
pred->u.atomic.neg = 0;
pred->u.atomic.equal = 1;
pred->u.atomic.name = strdup( "=" );
predicates[pred->u.atomic.name] = pred;
}
| STRIPS
{
$$ = STRIPS;
}
;
types_def : plain_or_typed_list_type RIGHTPAR
;
constants_def : plain_or_typed_list_name RIGHTPAR
;
type : name
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = 0;
$$->name = $1;
$$->type = NULL;
$$->next = NULL;
}
| LEFTPAR EITHER list_type RIGHTPAR
{
$$ = $3;
}
;
plain_or_typed_list_type
: typed_list_type
| list_type
;
plain_or_typed_list_name
: typed_list_name
| list_name
{
for( idList_t *id = $1; id != NULL; id = id->next )
objects[id->name] = id;
}
;
plain_or_typed_list_var
: typed_list_var
| list_var
;
typed_list_type : typed_list_type list_type HYPHEN type
{
for( idList_t *id = $2; id != NULL; id = id->next )
{
id->type = $4;
types[id->name] = id;
}
}
| list_type HYPHEN type
{
for( idList_t *id = $1; id != NULL; id = id->next )
{
id->type = $3;
types[id->name] = id;
}
}
;
typed_list_name : typed_list_name list_name HYPHEN type
{
for( idList_t *id = $2; id != NULL; id = id->next )
{
id->type = $4;
objects[id->name] = id;
//xxxx printf( "object %s has id %d\n", id->name, id->id );
}
}
| list_name HYPHEN type
{
for( idList_t *id = $1; id != NULL; id = id->next )
{
id->type = $3;
objects[id->name] = id;
//xxxx printf( "object %s has id %d\n", id->name, id->id );
}
}
;
typed_list_var : list_var HYPHEN type typed_list_var
{
idList_t *name;
for( name = $1; name->next != NULL; name = name->next )
name->type = $3;
name->type = $3;
name->next = $4;
$$ = $1;
}
| list_var HYPHEN type
{
for( idList_t *name = $1; name != NULL; name = name->next )
name->type = $3;
$$ = $1;
}
;
list_type : list_type name
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = 0;
$$->name = $2;
$$->type = NULL;
$$->next = $1;
}
| name
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = 0;
$$->name = $1;
$$->type = NULL;
$$->next = NULL;
}
;
list_name : list_name name
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = ++numberObjects;
$$->name = $2;
$$->type = NULL;
$$->next = $1;
//objects[$$->name] = $$;
}
| name
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = ++numberObjects;
$$->name = $1;
$$->type = NULL;
$$->next = NULL;
//objects[$$->name] = $$;
}
;
list_var : variable list_var
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = 0;
$$->name = $1;
$$->type = NULL;
$$->next = $2;
}
| /* empty */
{
$$ = NULL;
}
;
name : NAME
;
variable : QUESTION name
{
$$ = (char*)malloc( strlen( $2 ) + 2 );
$$[0] = '\0';
strcat( $$, "?" );
strcat( $$, $2 );
free( $2 );
}
;
predicates_def : list_atomic_formula_skeleton RIGHTPAR
;
list_atomic_formula_skeleton
: list_atomic_formula_skeleton atomic_formula_skeleton
| atomic_formula_skeleton
;
atomic_formula_skeleton
: LEFTPAR predicate plain_or_typed_list_var RIGHTPAR
{
formula_t *pred = (formula_t*)malloc( sizeof( formula_t ) );
pred->type = ATOMIC_FORMULA;
pred->u.atomic.id = ++_low_numberPredicates;
pred->u.atomic.neg = 0;
pred->u.atomic.name = $2;
pred->u.atomic.equal = 0;
pred->u.atomic.args = $3;
predicates[pred->u.atomic.name] = pred;
assert( pred->u.atomic.name != 0 );
// AQUI!!!
for( str2wff_t::iterator it = predicates.begin();
it != predicates.end();
it++ )
assert( it->first != 0 );
cout << "predicates size = " << predicates.size()
<< " for name = " << predicates[pred->u.atomic.name]->u.atomic.name << endl;
}
;
predicate : NAME
| EQUAL
{
$$ = "=";
}
;
list_structure_def
: list_structure_def LEFTPAR structure_def RIGHTPAR
| structure_def RIGHTPAR
;
structure_def : schema_def
| defined_def
;
action_type : ACTION
{
$$ = ACTION;
}
;
schema_def : action_type name list_schema_body
{
formula_t *f1, *f2, *f3;
schema_t *schema = (schema_t*)malloc( sizeof( schema_t ) );
schema->name = $2;
schema->vars = NULL;
schema->prec = NULL;
schema->effect = NULL;
schema->next = NULL;
bool saw_effect = false, saw_observe = false;
for( body_t *body = $3; body != NULL; body = body->next )
switch( body->type )
{
case PARAMETERS:
schema->vars = body->u.parameters;
break;
case PRECONDITION:
schema->prec = body->u.formula;
break;
case EFFECT:
saw_effect= true;
schema->is_observation = false;
for( f1 = body->u.formula; f1 != NULL; f1 = f1->u.flist.next )
{
f2 = (formula_t*)malloc( sizeof( formula_t ) );
f2->type = LIST_FORMULA;
f2->u.flist.formula = unfoldQuantifiers( f1->u.flist.formula );
f2->u.flist.formula = linearizeEffect( f2->u.flist.formula, f3 );
f2->u.flist.next = schema->effect;
schema->effect = f2;
}
break;
case OBSERVE:
saw_observe = true;
schema->is_observation = true;
observation_detected = true;
for( f1 = body->u.formula; f1 != NULL; f1 = f1->u.flist.next )
{
f2 = (formula_t*)malloc( sizeof( formula_t ) );
f2->type = LIST_FORMULA;
f2->u.flist.formula = unfoldQuantifiers( f1->u.flist.formula );
f2->u.flist.formula = linearizeEffect( f2->u.flist.formula, f3 );
f2->u.flist.next = schema->effect;
schema->effect = f2;
}
break;
}
assert( !saw_effect || !saw_observe );
/* if no effect, insert the empty effect */
if( !schema->effect )
{
f2 = (formula_t*)malloc( sizeof( formula_t ) );
f2->type = EMPTY_FORMULA;
schema->effect = (formula_t*)malloc( sizeof( formula_t ) );
schema->effect->type = LIST_FORMULA;
schema->effect->u.flist.formula = f2;
schema->effect->u.flist.next = NULL;
}
/* check and identify predicates and vars */
idMatchArgsVars( schema->prec, schema->vars );
idMatchArgsVars( schema->effect, schema->vars );
/* printSchema( stdout, schema ); printf( "\n" ); */
/* link schemas */
schema->next = schemas;
schemas = schema;
/* insert schema into schemaTable */
_low_schemaTable[_low_numberSchema++] = schema;
}
;
list_schema_body : list_schema_body schema_body
{
$2->next = $1;
$$ = $2;
}
| /* empty */
{
$$ = NULL;
}
;
schema_body : PARAMETERS LEFTPAR list_parameters RIGHTPAR
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = PARAMETERS;
$$->u.parameters = $3;
}
| PRECONDITION LEFTPAR AND RIGHTPAR
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = AND;
}
| PRECONDITION formula
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = PRECONDITION;
$$->u.formula = $2;
}
| EFFECT non_det_effect_list
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = EFFECT;
$$->u.formula = $2;
}
| OBSERVE non_det_effect_list
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = OBSERVE;
$$->u.formula = $2;
}
;
list_parameters : plain_or_typed_list_var
{
int i;
idList_t *var;
for( i = 1, var = $1; var != NULL; var = var->next )
var->id = i++;
$$ = $1;
}
;
defined_def : DEFINED name list_defined_body
{
formula_t *def = (formula_t*)malloc( sizeof( formula_t ) );
def->type = DEFINED_FORMULA;
for( body_t *body = $3; body != NULL; body = body->next )
switch( body->type )
{
case PARAMETERS:
def->u.lambda.vars = body->u.parameters;
break;
case FORMULA:
def->u.lambda.formula = body->u.formula;
break;
}
/* check and identify predicates and vars */
idMatchArgsVars( def->u.lambda.formula, def->u.lambda.vars );
/* insert into defined table */
defined[$2] = def;
/*
printf( "defined %s = ", $2 );
printFormula( stdout, def->u.lambda.formula );
printf( "\n" );
*/
}
;
list_defined_body : list_defined_body defined_body
{
$2->next = $1;
$$ = $2;
}
| /* empty */
{
$$ = NULL;
}
;
defined_body : PARAMETERS LEFTPAR list_parameters RIGHTPAR
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = PARAMETERS;
$$->u.parameters = $3;
}
| FORMULA formula
{
$$ = (body_t*)malloc( sizeof( body_t ) );
$$->type = FORMULA;
$$->u.formula = $2;
}
;
literal : atomic_formula
| LEFTPAR NOT atomic_formula RIGHTPAR
{
$3->u.atomic.neg = 1;
$$ = $3;
}
;
formula : atomic_formula
| LEFTPAR NOT formula RIGHTPAR
{
if( $3->type == ATOMIC_FORMULA )
{
$3->u.atomic.neg = ($3->u.atomic.neg+1)%2;
$$ = $3;
}
else
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = NOT_FORMULA;
$$->u.formula = $3;
}
}
| LEFTPAR UNKNOWN formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = UNKNOWN_FORMULA;
$$->u.formula = $3;
}
| LEFTPAR AND list_formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = AND_FORMULA;
$$->u.formula = $3;
}
| LEFTPAR OR list_formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = OR_FORMULA;
$$->u.formula = $3;
}
| LEFTPAR ONEOF list_formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = ONEOF_FORMULA;
$$->u.formula = $3;
}
| LEFTPAR FORALL LEFTPAR plain_or_typed_list_var RIGHTPAR formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = FORALL_FORMULA;
$$->u.lambda.vars = $4;
$$->u.lambda.formula = $6;
}
;
list_formula : list_formula formula
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $2;
$$->u.flist.next = $1;
}
| formula
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $1;
$$->u.flist.next = NULL;
}
;
atomic_formula : LEFTPAR predicate list_term RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = ATOMIC_FORMULA;
$$->u.atomic.id = -1;
$$->u.atomic.neg = 0;
$$->u.atomic.equal = 0;
$$->u.atomic.name = $2;
$$->u.atomic.args = $3;
}
| LEFTPAR DEF_NAME list_term RIGHTPAR
{
instantiation_t *inst;
str2wff_t::iterator it;
it = defined.find( $2 );
inst = buildInstantiation( (*it).second->u.lambda.vars, $3 );
$$ = copyReplaceFormula( (*it).second->u.lambda.formula, inst );
}
;
list_term : term list_term
{
$$ = (idList_t*)malloc( sizeof( idList_t ) );
$$->id = 0;
$$->name = $1;
$$->type = NULL;
$$->next = $2;
}
| /* empty */
{
$$ = NULL;
}
;
term : name
| variable
;
non_det_effect_list
: non_det_effect_list non_det_effect
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $2;
$$->u.flist.next = $1;
}
| non_det_effect
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $1;
$$->u.flist.next = NULL;
}
| one_effect_formula
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $1;
$$->u.flist.next = NULL;
}
;
non_det_effect
: LEFTPAR one_effect_formula RIGHTPAR
{
$$ = $2;
}
| LEFTPAR RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = EMPTY_FORMULA;
}
;
list_one_effect_formula
: list_one_effect_formula one_effect_formula
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $2;
$$->u.flist.next = $1;
}
| one_effect_formula
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $1;
$$->u.flist.next = NULL;
}
;
one_effect_formula
: literal
| LEFTPAR SET literal formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = SET_FORMULA;
$$->u.fset.literal = $3;
$$->u.fset.formula = $4;
}
| LEFTPAR AND list_one_effect_formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = AND_FORMULA;
$$->u.formula = $3;
}
| LEFTPAR FORALL LEFTPAR plain_or_typed_list_var RIGHTPAR one_effect_formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = FORALL_EFFECT;
$$->u.lambda.vars = $4;
$$->u.lambda.formula = $6;
}
| LEFTPAR WHEN formula list_atomic_effect RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
if( $3->type != OR_FORMULA )
{
$$->type = WHEN_EFFECT;
$$->u.when.formula = $3;
$$->u.when.effect = $4;
}
else
{
$$->type = AND_FORMULA;
formula_t* cont = (formula_t*)malloc( sizeof( formula_t ) );
$$->u.formula = cont;
formula_t* init = $3->u.formula;
assert( init != NULL );
while( init != NULL )
{
assert( init->type == LIST_FORMULA );
cont->type = LIST_FORMULA;
// new When...
formula_t* newWhen = (formula_t*)malloc( sizeof( formula_t ) );
cont->u.flist.formula = newWhen;
newWhen->type = WHEN_EFFECT;
newWhen->u.when.formula = init->u.flist.formula;
newWhen->u.when.effect = copyReplaceFormula( $4, NULL );
init = init->u.flist.next;
if( init != NULL )
{
cont->u.flist.next = (formula_t*)malloc( sizeof( formula_t ) );
cont = cont->u.flist.next;
}
else
cont->u.flist.next = NULL;
}
}
}
;
list_literal : list_literal literal
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $2;
$$->u.flist.next = $1;
}
| literal
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = LIST_FORMULA;
$$->u.flist.formula = $1;
$$->u.flist.next = NULL;
}
;
list_atomic_effect
: literal
| LEFTPAR AND list_literal RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = AND_FORMULA;
$$ = $3;
}
;
/*******************************************************************************
**
** Problem Definition
**
******************************************************************************/
problem : LEFTPAR DEFINE LEFTPAR PROBLEM name RIGHTPAR
{
_low_problemName = $5;
}
list_def_prob
{
idMatchArgsVars( initialSituation, NULL );
idMatchArgsVars( goalSituation, NULL );
generateNames();
}
RIGHTPAR
;
list_def_prob : list_def_prob def_prob
| /* empty */
;
def_prob : LEFTPAR REQUIREMENTS require_def
| LEFTPAR SITUATION situation_def
| LEFTPAR STRUCTURAL formula RIGHTPAR
{
structural = $3;
}
| LEFTPAR INIT list_formula RIGHTPAR
{
initialSituation = $3;
}
| LEFTPAR GOAL goal_formula RIGHTPAR
{
goalSituation = $3;
}
| LEFTPAR TWODOTS DOMAIN name RIGHTPAR
| LEFTPAR OBJECTS plain_or_typed_list_name RIGHTPAR
;
situation_def : name RIGHTPAR {}
;
goal_formula : formula
| LEFTPAR KNOW list_formula RIGHTPAR
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = KNOW_FORMULA;
$$->u.formula = $3;
}
| CERTAINTY
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = CERTAINTY_FORMULA;
}
| /* empty */
{
$$ = (formula_t*)malloc( sizeof( formula_t ) );
$$->type = EMPTY_FORMULA;
}
;
%%
void
yyerror( char const *s )
{
printf( "%s:%d: %s\n", _low_yyfile, lineno, s );
}
static void
checkRequirement( int req )
{
switch( req )
{
case EQUALITY:
_low_requirements = _low_requirements | REQ_EQUALITY;
break;
case TYPING:
_low_requirements = _low_requirements | REQ_TYPING;
break;
case STRIPS:
_low_requirements = _low_requirements | REQ_STRIPS;
break;
case CONDITIONAL_EFFECTS:
_low_requirements = _low_requirements | REQ_CONDITIONAL_EFFECTS;
break;
case NEGATIVE_PRECONDITIONS:
_low_requirements = _low_requirements | REQ_NEGATIVE_PRECONDITIONS;
break;
default:
printf( "parser(checkRequirement): not supported requirement %d\n", req );
}
}