Thu 25 Apr 2013 03:18:41 PM UTC, original submission:
I used gnu-prolog to create a program. For syntax purposes I defined an operator '::' (i.e, op(350,xfy,::)) in order to make infix expressions such as A=a::b::c
Now I want to use gnu prolog for java (0.2.6) and I defined the same operator in my environment:
environment.getOperatorSet().add(350,SPECIFIER.XFY,"::");
Nevertheless, the infix syntax A=a::b::c is not allowed.
--Example--
I'm loading the following prolog program:
<rename.pl>
1 rename([]):-!.
2 rename([_::_|Tail]):-!, %the api already exists
3 rename(Tail).
4 rename([S::M as Alias| Tail]):-
5 api(S::M,Bounded,Free),!,
6 assertz(dataset(Alias,Bounded,Free)),
7 rename(Tail).
In my java code I'm defining the '::' operator in the environment (along with the operator 'as'):
<define1>
this.environment = new Environment();
this.interpreter = this.environment.createInterpreter();
this.environment.runInitialization(this.interpreter);
this.environment.getOperatorSet().add(350,SPECIFIER.XFY,"::");
this.environment.getOperatorSet().add(900,SPECIFIER.XFX,"as");
Then I load the <rename.pl> program with the code:
<load>
for(int i= 0; i < plFileNames.length; i++){
Log.d("Loading '"+plFileNames[i].trim()+"'");
this.environment.ensureLoaded(AtomTerm.get(plFileNames[i]));
this.environment.runInitialization(this.interpreter);
List<PrologTextLoaderError> list = environment.getLoadingErrors();
Iterator<PrologTextLoaderError> iterator = list.iterator();
int j=0;
while(iterator.hasNext()){
PrologTextLoaderError p_error = iterator.next();
Log.d((++j)+"\t"+p_error.getMessage());
}
}
Then I get the error messages:
<errors>
[13.04.25 10:12:43:140] Loading '/Users/aguacatin/Research/HADAS/PhD/Prolog/qw_activity_derivation/rename.pl'
[13.04.25 10:12:43:142] 1 syntax error: Encountered "::" at line 2, column 10.
[13.04.25 10:12:43:142] Was expecting one of:
[13.04.25 10:12:43:142] <CLOSE_LIST_TOKEN> ...
[13.04.25 10:12:43:142] <COMMA_TOKEN> ...
[13.04.25 10:12:43:142] <HEAD_TAIL_SEPARATOR_TOKEN> ...
[13.04.25 10:12:43:142]
[13.04.25 10:12:43:143] 2 syntax error: Encountered "::" at line 4, column 10.
[13.04.25 10:12:43:143] Was expecting one of:
[13.04.25 10:12:43:143] <CLOSE_LIST_TOKEN> ...
[13.04.25 10:12:43:143] <COMMA_TOKEN> ...
[13.04.25 10:12:43:143] <HEAD_TAIL_SEPARATOR_TOKEN> ...
[13.04.25 10:12:43:143]
[13.04.25 10:12:43:143] GENERATING: "hsql2_2([whatulike::interests as a, whatulike::interests as b],[a::nickname='Alice', b::nickname='Bob', a::interests::interest::tag=b::interests::interest::tag],[ b::nickname, b::interests])."
gnu.prolog.io.ParseException: Encountered "." at line 1, column 192.
Was expecting:
<CLOSE_TOKEN> ...
at gnu.prolog.io.TermReader.readTermEof(TermReader.java:87)
at gnu.prolog.io.TermReader.stringToTerm(TermReader.java:69)
at QWDerivationWrapper.generate(QWDerivationWrapper.java:123)
at QWDerivationWrapper.main(QWDerivationWrapper.java:324)
Exception in thread "main" java.lang.NullPointerException
at QWDerivationWrapper.generate(QWDerivationWrapper.java:128)
at QWDerivationWrapper.main(QWDerivationWrapper.java:324)
Another attempt defining 'op(350,xfy,::)'…
<define2>
try {
Term double_colon_op_term = TermReader.stringToTerm("op(350,xfy,::)", this.environment);
interpreter.runOnce(double_colon_op_term);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PrologException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.environment.getOperatorSet().add(900,SPECIFIER.XFX,"as");
but I get the same error messages <errors>.
|