Skip to content

Commit

Permalink
[VRG]
Browse files Browse the repository at this point in the history
- renamed vectorize-run.pl to vrg-run.pl (the old one
  is overridden)
- added builtin infix operators "eq", "neq", and ":=" to
  xclips.

git-svn-id: http://svn.berlios.de/svnroot/repos/unisimu/VRG@815 625e195c-0704-0410-94f2-f261ee9f2fe7
  • Loading branch information
agent committed Nov 7, 2006
1 parent 6ac7659 commit 1228a34
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 57 deletions.
4 changes: 2 additions & 2 deletions preprocess.xclp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module Vectorize.

\?a, \?b, meet(?a, ?b, ?)
=>
bind(?A, gensym()), #?A,
?A := gensym(), #?A,
?a [on] ?A, ?b [on] ?A,
?a [~//] ?b.

\?a, #?A, meet(?a, ?A, ?) => ?a [~//] ?A, ?a [~on] ?A.

\?a, #?alpha, \?b, project(?a, ?alpha, ?b)
=>
bind(?theta, gensym()), #?theta,
?theta := gensym(), #?theta,
?a [X] ?alpha, ?a [on] ?theta,
meet(?theta, ?alpha, ?b),
?theta [T] ?alpha.
4 changes: 2 additions & 2 deletions sanity2.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ run {
ok system(split(/\s+/, $xclips), "$id.xclp") == 0, "$name - invoking $xclips ok";
my ($stdout, $stderr);
ok run3(
[$^X, 'vectorize-run.pl', "$id.clp"],
[$^X, 'vrg-run.pl', "$id.clp"],
\undef,
\$stdout,
\$stderr,
),
"$name - vectorize-run.pl ok";
"$name - vrg-run.pl ok";
warn $stderr if $stderr;
my $got = sort_list($stdout);
my $expected = sort_list($block->vectorized);
Expand Down
7 changes: 4 additions & 3 deletions vector-eval.xclp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
define defmodule(
Eval,
import(Vectorize, deftemplate, vector-relation)
).
)

module Eval.

include "vrg-sugar.xclp".

?a <//> ?b, ?a <?R> ?b => ?a <//> ?b.
?a <//> ?b, ?a <?R> ?c, ?b neq ?c
=> ?a <?R> ?c.

?a <T> ?b; ?a <X> ?b => ?a <~//> ?b.

?a <T> ?b, ?b <T> ?c, ?c <T> ?d, ?d <T> ?a, ?a <~//> ?c
?a <T> ?b, ?b <T> ?c, ?c <T> ?d, ?d <T> ?a, ?a <~//> ?c, ?b neq ?d
=> ?b <//> ?d.

?a <?R> ?b => ?b <?R> ?a.
33 changes: 0 additions & 33 deletions vectorize-run.pl

This file was deleted.

94 changes: 82 additions & 12 deletions vrg-run.pl
Original file line number Diff line number Diff line change
@@ -1,15 +1,85 @@
use strict;
use warnings;

my $profile = shift;
my $data = `$^X pro.pl -s $profile -g go -t halt -q`;
my $pro_src = "(deffacts vector_facts \"$profile\"\n";
open my $in, '<', \$data;
while (<$in>) {
next if !/^\S+ \S+ \S+$/;
chomp;
$pro_src .= " ($_)\n";
}
$pro_src .= ")\n";
close $in;
print $pro_src;
use CLIPS_Visualize;
use Getopt::Std;
use CLIPS;

my %opts;
getopts('v', \%opts) or help();
$CLIPS::Verbose = $opts{v};

my %infix = (
'parallel' => '//',
'orthogonal' => 'T',
'cross' => 'X',
'on' => 'on',
);

my %prefix = (
'line' => '\\\\',
'plane' => '\\#',
);

my $infile = shift or help();;
my $clips = CLIPS->new('vectorize.clp', $infile, 'vector-eval.clp');
$clips->watch('rules');
$clips->watch('facts');
$clips->reset;
$clips->focus('Vectorize');
$clips->rules if $opts{v};
$clips->facts('*', \my $init_facts);
$clips->get_current_module;
$clips->agenda;
$clips->run(\my $run_log);
$clips->facts('Eval', \my $facts);
$clips->focus('Eval');
$clips->facts('*', \$init_facts);
$clips->run(\$run_log);
$clips->eof;
#warn "FACTS: ", $facts;
while ($facts =~ /\(vector-relation ([^\)]+)\)/g) {
print "$1\n";
}

if ($opts{v}) {
my $painter = CLIPS::Visualize->new($init_facts, $run_log);
$painter->draw(
outfile => "a.png",
fact_filter => \&format_fact,
trim => 1,
);
}

sub help {
die "usage: $0 [-v] infile\n";
}

sub format_fact {
my $clips = $_[0];
if ($clips =~ /(?x) ^ \( (space|vector)-relation \s+ (\S+) \s+ (\S+) \s+ (\S+) \) $/) {
#warn "$1, $2, $3";
my ($type, $rel, $a, $b) = ($1, $2, $3, $4);
my $prefix = '';
if ($rel =~ s/^not_//) {
$prefix = '~';
}
my $infix = $infix{$rel};
if ($infix) {
return $type eq 'space' ? "$a [$prefix$infix] $b" : "$a <$prefix$infix> $b";
}
}
elsif ($clips =~ /(?x) ^ \( (line|plane) \s+ (\S+) \) $/) {
#warn "$1, $2";
my ($type, $a) = ($1, $2);
my $prefix = $prefix{$type};
return "$prefix $a";
}
elsif ($clips =~ /(?x) ^ \( (\S+) ((?:\s+ \S+)*) \) $/) {
my ($func, $args) = ($1, $2);
$args =~ s/^\s+//g;
my @args = split /\s+/, $args;
return "$func(" . join(',', @args) . ')';
}
$clips;
}
20 changes: 15 additions & 5 deletions xclips.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ conjunction : clause ',' <commit> conjunction

clause : prefix <commit> atom

{ "($item{prefix}$item{atom})" }

| atom <skip:''> /\s+/ general_infix <commit> <skip:'\s*'> atom

{ "($item{general_infix}$item[1] $item[7])" }
{ my $s = $item{prefix};
my ($open, $close) = (0, 0);
$open++ while $s =~ /\(/g;
$close++ while $s =~ /\)/g;
"($s$item{atom})" . (')' x ($open - $close))
}

| atom <skip:''> /\s+/ general_infix /\s+/ <commit> <skip:'\s*'> atom

{ my $s = $item{general_infix};
my ($open, $close) = (0, 0);
$open++ while $s =~ /\(/g;
$close++ while $s =~ /\)/g;
"($s$item[1] $item[8])" . (')' x ($open - $close))
}

| atom <skip:''> postfix

Expand Down
6 changes: 6 additions & 0 deletions xclips.pl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

our (%prefix, %infix, %infix_prefix, %infix_circumfix, %infix_circum_close);

%infix = (
'neq' => "test (neq ",
'eq' => "test (eq ",
':=' => "bind ",
);

$::RD_HINT = 1;
#$::RD_TRACE = 1;
our $parser = CLIPSx->new;
Expand Down

0 comments on commit 1228a34

Please sign in to comment.