Hi,
Is there any example of using the parser control predicates to customize the Ciao grammar?
Thanks, Mark.
On Thu, Sep 13, 2012 at 4:06 PM, Mark Green <mark(a)antelope.nildram.co.uk> wrote:
Hi,
Is there any example of using the parser control predicates to customize the Ciao grammar?
Hi Mark,
You can customize the Ciao grammar using operator definitions, like in most Prolog systems. This is powerful enough for many purposes. Additionally, the parser has some experimental flags to allow more exotic syntax like array subscript ("A[B]").
It is also possible to plug custom parsers by doing some tricks with the compiler hooks. If you can provide us some concrete example of customization, we could help you with some code and a more precise answer.
Regards
Hi,
Thanks for your reply. I was interested in an example of how the hook predicates work. For example, if I wished to have a pattern as follows:
The PROPERTY of SUBJECT is OBJECT.
Where PROPERTY, SUBJECT, and OBJECT are atoms and "the", "of", and "is" are keywords, to parse as PRED(SUBJECT,OBJECT); how would that be done?
Mark Green mark(a)antelope.nildram.co.uk
On 15 Sep 2012, at 10:40, Jose F. Morales <jfran(a)clip.dia.fi.upm.es> wrote:
On Thu, Sep 13, 2012 at 4:06 PM, Mark Green <mark(a)antelope.nildram.co.uk> wrote:
Hi,
Is there any example of using the parser control predicates to customize the Ciao grammar?
Hi Mark,
You can customize the Ciao grammar using operator definitions, like in most Prolog systems. This is powerful enough for many purposes. Additionally, the parser has some experimental flags to allow more exotic syntax like array subscript ("A[B]").
It is also possible to plug custom parsers by doing some tricks with the compiler hooks. If you can provide us some concrete example of customization, we could help you with some code and a more precise answer.
Regards
-- Jose (and the Ciao Dev team)
On Mon, Sep 17, 2012 at 3:00 AM, Mark Green <mark(a)antelope.nildram.co.uk> wrote:
Hi,
Thanks for your reply. I was interested in an example of how the hook predicates work. For example, if I wished to have a pattern as follows:
The PROPERTY of SUBJECT is OBJECT.
Where PROPERTY, SUBJECT, and OBJECT are atoms and "the", "of", and "is" are keywords, to parse as PRED(SUBJECT,OBJECT); how would that be done?
Using hook predicates for language extensions (term_expansion, etc.) allow some pre-processing at the abstract-syntax tree level (i.e., terms). Currently, it is not possible to redefine the parser itself with hooks.
So one cheap option here is to define the keywords as prefix, infix, or postfix operators with the right priorities. That is, read:
the PROPERTY of SUBJECT is OBJECT.
as:
(the (PROPERTY of SUBJECT)) is OBJECT.
For example:
?- op(650, fx, the). ?- op(640, xfx, of). ?- X = (the brother of john is paul). X = (the brother of john is paul) ?
which is equivalent to "X = is(the(of(brother, john)), paul)", which resembles your PRED(SUBJECT, OBJECT) term. This has the great advantage that you can merge it with Prolog syntax, but it also has some limitations (mostly, it is useful only for toy examples).
For more complex stuff you probably need your own reader and parser predicates (e.g., get codes from the stream and parse them with a DCG).