Jeff Donner <jdonner(a)cs.nmsu.edu> wrote: I'm doing some 'sentence translation' for a module which parses code related to Prolog. ... compute 1 { not fail }. Why not take the public domain Prolog tokeniser and the public domain Prolog parser and modify the parser?
Prolog has prefix (unary) operators; postfix (unary) operators; infix (binary) operators. It does not have any 'fxx' operators, although if I recall correctly NU Prolog does support that. It would be a comparatively small matter to modify the public domain parser to support fxx operators.
A Prolog extension I thought about several years ago is to allow compound terms to be operators, so you would write :- op(900, fy, [compute/0, compute/1]). ... compute 9 => compute(9) compute(9) {not fail} => compute(9,{}(not(fail))) (compute 9) {not fail} => compute(9,{}(not(fail))) compute 9 {not fail} => ERROR
This would be quite a small change to the public domain Prolog parser, rather easier and less troublesome than introducing binary prefix operators.
Simplest of all, why not change the syntax to something Prolog _can_ parse?
(A) Make compute infix binary instead of prefix binary: 1 compute { not fail }.
It has always been legal in Prolog for an atom to be both a prefix and an infix operator.
(B) Include a dummy operator in the surface syntax which you strip out before processing: compute 1 times { not fail }.
:- load_compilation_module(library(braces_tr)). :- op(900, fy, compute). :- op(900, fy, not). + :- op(850, xfx, times).
compute 9 => compute(9). compute 1 times { not fail } => compute(times(1,{}(not(fail)))). ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------