[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Info-gnuprologjava] Infix expressions with user-defined operators
From: |
Daniel Thomas |
Subject: |
Re: [Info-gnuprologjava] Infix expressions with user-defined operators |
Date: |
Wed, 24 Apr 2013 09:24:56 +0100 |
Hello Carlos,
Unfortunately this looks like a bug. The parser (which has other known
flaws and which we need to rewrite) doesn't appear to be able to cope
with :: as a token, it doesn't know to parse it into a user defined
token to be processed later. However I think that you could define an
operator "cc" which could replace "::" and do an admittedly ugly s/::/
cc /g on your code.
We are hoping to get the parser rewritten as a GSOC project this summer.
Unfortunately we can't make small modifications to the parser as the
compiler compiler does not produce working code.
You can file a bug in our bug tracker or I can do that this evening.
Daniel
On Tue, 2013-04-23 at 16:29 -0500, Carlos-Manuel LÓPEZ-ENRÍQUEZ wrote:
> Hi Daniel,
>
>
> First of all, thanks for your kind attention.
>
>
> Here is one of the prolog code files I'm using.
>
>
> <rename.pl>
>
>
> rename([]):-!.
> rename([_::_|Tail]):-!, %the api already exists
> rename(Tail).
> rename([S::M as Alias| Tail]):-
> api(S::M,Bounded,Free),!,
> assertz(dataset(Alias,Bounded,Free)),
> rename(Tail).
>
>
> 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 (among others) 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.23 15:54:43:322] Loading
> '/Users/aguacatin/Research/LIG/HADAS/PhD/Prolog/qw_activity_derivation/utils.pl'
> [13.04.23 15:54:43:347] Loading
> '/Users/aguacatin/Research/LIG/HADAS/PhD/Prolog/qw_activity_derivation/rename.pl'
> [13.04.23 15:54:43:349] 1 syntax error: Encountered "::" at line 2,
> column 10.
> [13.04.23 15:54:43:349] Was expecting one of:
> [13.04.23 15:54:43:349] <CLOSE_LIST_TOKEN> ...
> [13.04.23 15:54:43:349] <COMMA_TOKEN> ...
> [13.04.23 15:54:43:349] <HEAD_TAIL_SEPARATOR_TOKEN> ...
> [13.04.23 15:54:43:349]
> [13.04.23 15:54:43:350] 2 syntax error: Encountered "::" at line 5,
> column 22.
> [13.04.23 15:54:43:350] Was expecting one of:
> [13.04.23 15:54:43:350] <CLOSE_LIST_TOKEN> ...
> [13.04.23 15:54:43:350] <COMMA_TOKEN> ...
> [13.04.23 15:54:43:350] <HEAD_TAIL_SEPARATOR_TOKEN> ...
> [13.04.23 15:54:43:350]
> [13.04.23 15:54:43:352] op(350,xfy,::)
> [13.04.23 15:54:43:352] op(900,xfx,as)
> [13.04.23 15:54:43:353] Loading
> '/Users/aguacatin/Research/LIG/HADAS/PhD/Prolog/qw_activity_derivation/utils.pl'
> [13.04.23 15:54:43:353] 1 syntax error: Encountered "::" at line 2,
> column 10.
> [13.04.23 15:54:43:353] Was expecting one of:
> [13.04.23 15:54:43:353] <CLOSE_LIST_TOKEN> ...
> [13.04.23 15:54:43:353] <COMMA_TOKEN> ...
> [13.04.23 15:54:43:353] <HEAD_TAIL_SEPARATOR_TOKEN> ...
> [13.04.23 15:54:43:353]
> [13.04.23 15:54:43:354] 2 syntax error: Encountered "::" at line 5,
> column 22.
> [13.04.23 15:54:43:354] Was expecting one of:
> [13.04.23 15:54:43:354] <CLOSE_LIST_TOKEN> ...
> [13.04.23 15:54:43:354] <COMMA_TOKEN> ...
> [13.04.23 15:54:43:354] <HEAD_TAIL_SEPARATOR_TOKEN> ...
> [13.04.23 15:54:43:354]
> [13.04.23 15:54:43:355] Loading
> '/Users/aguacatin/Research/LIG/HADAS/PhD/Prolog/qw_activity_derivation/rename.pl'
> [13.04.23 15:54:43:355] 1 syntax error: Encountered "::" at line 2,
> column 10.
> [13.04.23 15:54:43:355] Was expecting one of:
> [13.04.23 15:54:43:355] <CLOSE_LIST_TOKEN> ...
> [13.04.23 15:54:43:355] <COMMA_TOKEN> ...
> [13.04.23 15:54:43:355] <HEAD_TAIL_SEPARATOR_TOKEN> ...
> [13.04.23 15:54:43:355]
> [13.04.23 15:54:43:356] 2 syntax error: Encountered "::" at line 5,
> column 22.
> [13.04.23 15:54:43:356] Was expecting one of:
> [13.04.23 15:54:43:356] <CLOSE_LIST_TOKEN> ...
> [13.04.23 15:54:43:356] <COMMA_TOKEN> ...
> [13.04.23 15:54:43:356] <HEAD_TAIL_SEPARATOR_TOKEN> ...
> [13.04.23 15:54:43:356]
> [13.04.23 15:54:43:357] 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:112)
> at QWDerivationWrapper.main(QWDerivationWrapper.java:313)
> Exception in thread "main" java.lang.NullPointerException
> at QWDerivationWrapper.generate(QWDerivationWrapper.java:117)
> at QWDerivationWrapper.main(QWDerivationWrapper.java:313)
>
>
>
>
> Another attempt with your suggestion…
>
>
> I defined the operator '::' with the code:
>
>
> <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>.
>
>
>
>
> Observation: As you can see in the <define1> java code, I also defined
> an operator 'as' but I don't get any error message related with this
> one.
>
>
>
>
> I hope my explanation is clear.
>
>
> Kind regards,
>
>
> --
> Carlos
>
>
> Le 23 avr. 2013 à 15:22, Daniel Thomas <address@hidden> a écrit :
>
> > Hello Carlos,
> >
> > Have you tried specifying the operator entirely in the prolog code
> > using
> > op(350,xfy,::)?
> >
> > Can I have details of exactly what is going wrong. What error
> > messages
> > are you getting etc.? Can you give me a minimal test case which
> > fails?
> >
> > User defined infix operators should just work, if they don't that is
> > an
> > unexpected bug.
> >
> > Daniel
> >
> > On Mon, 2013-04-15 at 21:00 -0500, Carlos-Manuel LÓPEZ-ENRÍQUEZ
> > wrote:
> > > G'day,
> > >
> > >
> > > 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 and I have
> > > to
> > > use B=..[::,b,c], A=..[::,a,B].
> > >
> > >
> > > All my code has infix expressions (e.g., head(A::B::C):- ... )
> > > and I
> > > want to avoid massive and dangerous modifications and keep my code
> > > readable.
> > >
> > >
> > > Is there a way in gnu prolog for java to enable infix expression
> > > with
> > > user-defined operators?
> > >
> > >
> > > Thanks in advance!
> > >
> > >
> > > --
> > > Carlos
> >
>
>
signature.asc
Description: This is a digitally signed message part