This adds (*,x) functionality.

This commit is contained in:
Ondrej Filip 2011-03-26 14:18:56 +01:00
parent d0e9b36d30
commit 4fc36f394e
2 changed files with 54 additions and 7 deletions

View file

@ -25,6 +25,19 @@ static int make_pair(int i1, int i2)
return (u1 << 16) | u2; return (u1 << 16) | u2;
} }
struct f_tree *f_generate_rev_wcard(int from, int to, int expr)
{
struct f_tree * ret = NULL;
if(from <= to) {
ret = f_new_tree();
ret->from.type = ret->to.type = T_PAIR;
ret->from.val.i = ret->to.val.i = make_pair(from, expr);
ret->left = f_generate_rev_wcard(from+1, to, expr);
}
return ret;
}
CF_DECLS CF_DECLS
CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
@ -229,7 +242,7 @@ fipa:
; ;
set_atom: set_atom:
expr { $$.type = T_INT; $$.val.i = $1; } expr { $$.type = T_INT; $$.val.i = $1; } /* 'SYM' included in 'expr' creates 3 reduce/shift conflicts */
| RTRID { $$.type = T_QUAD; $$.val.i = $1; } | RTRID { $$.type = T_QUAD; $$.val.i = $1; }
| fipa { $$ = $1; } | fipa { $$ = $1; }
| ENUM { $$.type = $1 >> 16; $$.val.i = $1 & 0xffff; } | ENUM { $$.type = $1 >> 16; $$.val.i = $1 & 0xffff; }
@ -254,12 +267,25 @@ set_item:
$$->from.val.i = make_pair($2, $4); $$->from.val.i = make_pair($2, $4);
$$->to.val.i = make_pair($9, $11); $$->to.val.i = make_pair($9, $11);
} }
| '(' '*' ',' '*' ')' { /* This is probably useless :-) */
$$ = f_new_tree();
$$->from.type = $$->to.type = T_PAIR;
$$->from.val.i = 0;
$$->to.val.i = 0xffffffff;
}
| '(' expr ',' '*' ')' { | '(' expr ',' '*' ')' {
$$ = f_new_tree(); $$ = f_new_tree();
$$->from.type = $$->to.type = T_PAIR; $$->from.type = $$->to.type = T_PAIR;
$$->from.val.i = make_pair($2, 0); $$->from.val.i = make_pair($2, 0);
$$->to.val.i = make_pair($2, 0xffff); $$->to.val.i = make_pair($2, 0xffff);
} }
| '(' '*' ',' expr ')' {
$$ = f_generate_rev_wcard(0, 0xffff, $4);
}
/* This causes 3 reduce/reduce conflicts
| '(' expr '.' '.' expr ',' expr ')' {
cf_error("Not implemented yet");
}*/
| set_atom { | set_atom {
$$ = f_new_tree(); $$ = f_new_tree();
$$->from = $1; $$->from = $1;

View file

@ -11,6 +11,11 @@ define xyzzy = (120+10);
define '1a-a1' = (20+10); define '1a-a1' = (20+10);
define one = 1; define one = 1;
function onef(int a)
{
return 1;
}
function 'mkpair-a'(int a) function 'mkpair-a'(int a)
{ {
@ -31,8 +36,9 @@ int i;
i = arg2; i = arg2;
case arg1 { case arg1 {
2: printn "dva, "; printn "jeste jednou dva"; one: printn "jedna, "; printn "jedna";
3 .. 5: if arg2 < 3 then printn "tri az pet"; (one+onef(2)): printn "dva, "; printn "jeste jednou dva";
(2+one) .. 5: if arg2 < 3 then printn "tri az pet";
else: printn "neco jineho"; else: printn "neco jineho";
} }
print; print;
@ -78,7 +84,9 @@ clist l;
print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1; print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
l = - empty -; l = - empty -;
print "Should be false in this special case: ", l ~ [(*,*)];
l = add( l, (one,2) ); l = add( l, (one,2) );
print "Should be always true: ", l ~ [(*,*)];
l = add( l, (2,one+2) ); l = add( l, (2,one+2) );
print "Community list (1,2) (2,3) ", l; print "Community list (1,2) (2,3) ", l;
print "Should be true: ", (2,3) ~ l, " ", l ~ [(1,*)], " ", l ~ [(2,3)]," ", l ~ [(2,2..3)], " ", l ~ [(1,1..2)], " ", l ~ [(1,1)..(1,2)]; print "Should be true: ", (2,3) ~ l, " ", l ~ [(1,*)], " ", l ~ [(2,3)]," ", l ~ [(2,2..3)], " ", l ~ [(1,1..2)], " ", l ~ [(1,1)..(1,2)];
@ -91,6 +99,7 @@ clist l;
l = delete( l, [(2,*)] ); l = delete( l, [(2,*)] );
print "Community list (1,2) ", l; print "Community list (1,2) ", l;
print "Should be false: ", (2,3) ~ l, " ", l ~ [(2,*)], " ", l ~ [(one,3..6)]; print "Should be false: ", (2,3) ~ l, " ", l ~ [(2,*)], " ", l ~ [(one,3..6)];
print "Should be always true: ", l ~ [(*,*)];
l = add( l, (3,one) ); l = add( l, (3,one) );
l = add( l, (one+one+one,one+one) ); l = add( l, (one+one+one,one+one) );
l = add( l, (3,3) ); l = add( l, (3,3) );
@ -98,6 +107,16 @@ clist l;
l = add( l, (3,5) ); l = add( l, (3,5) );
l = delete( l, [(3,2..4)] ); l = delete( l, [(3,2..4)] );
print "Community list (1,2) (3,1) (3,5) ", l; print "Community list (1,2) (3,1) (3,5) ", l;
l = add( l, (3,2) );
l = add( l, (4,5) );
print "Community list (1,2) (3,1) (3,2) (3,5) (4,5) ", l;
print "Should be true: ", l ~ [(*,2)], " ", l ~ [(*,5)], " ", l ~ [(*, one)];
print "Should be false: ", l ~ [(*,3)], " ", l ~ [(*,(one+6))], " ", l ~ [(*, (one+one+one))];
l = delete( l, [(*,(one+onef(3)))] );
l = delete( l, [(*,(4+one))] );
print "Community list (3,1) ", l;
l = delete( l, [(*,(onef(5)))] );
print "Community list empty ", l;
} }
function bla() function bla()
@ -185,8 +204,10 @@ string s;
print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2; print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/9 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false; print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/9 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false;
is1 = [one, (2+1), (6-one), 8, 11, 15, 17, 19]; is1 = [ 1, 5, 8, 11, 15, 17, 19];
is2 = [19, 17, 15, 11, 8, 5, 3, 2];
is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
is3 = [5, 17, 2, 11, 8, 15, 3, 19]; is3 = [5, 17, 2, 11, 8, 15, 3, 19];
print " must be true: ", 1 ~ is1, " ", 3 ~ is1, " ", 5 ~ is1; print " must be true: ", 1 ~ is1, " ", 3 ~ is1, " ", 5 ~ is1;
@ -244,7 +265,7 @@ string s;
print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ]; print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
print "Testing functions..."; print "Testing functions...";
# callme ( 1, 2 ); callme ( 1, 2 );
callme ( 2, 2 ); callme ( 2, 2 );
callme ( 2, 2 ); callme ( 2, 2 );
callme ( 3, 2 ); callme ( 3, 2 );