Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!shelby!agate!darkstar!saturn.ucsc.edu From: kjell@saturn.ucsc.edu (Kjell Post) Newsgroups: comp.lang.prolog Subject: Re: Does Prolog have an unambiguous syntax definition? Message-ID: <12388@darkstar.ucsc.edu> Date: 15 Feb 91 08:48:57 GMT Sender: usenet@darkstar.ucsc.edu Organization: University of California, Santa Cruz Lines: 75 In article <4764@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: >In article <12166@darkstar.ucsc.edu>, kjell@terra.ucsc.edu writes: >> Is there a document that describes the reader's behaviour when it >> sees an ambiguous term? > >Which Prolog? There *is* a document: the public-domain DEC-10 Prolog >parser, published in 1984 (or was it 1983)? > >> :- op(300,fx,#). % prefix >> :- op(500,xf,#). % postfix >> :- op(400,fx,@). % prefix > >> display(@ #). > >> Will Prolog display @(#) or #(@), and why is one preferred over the other? > >In a Prolog system whose reader is based on the public-domain parser (the >*point* of providing that was to help implementors tell the truth when they >claimed "Edinburgh" compatibility), the answer must be #(@). >THERE IS NOTHING AMBIGUOUS ABOUT THIS TERM: > if a possible prefix operator is followed by > - a right bracket of some sort , ) | ] } . > - a possible infix operator of wider scope (bigger number) > - or a possible postfix operator of wider scope (bigger number) > then the possible prefix operator is read as an atom. > (In the case of a following infix or postfix operator, this forces > the operator reading.) Interesting. I hadn't seen that before and it certainly takes care of some problems. But what about this example? :- op(500,xfy,@). % infix :- op(600,xf,@). % postfix :- op(700,xf,#). % postfix display(a @ #). Quintus Prolog Release 2.2 (Sun-3, Unix 3.5) => @(a,#) SICStus 0.6 #18: Mon Oct 22 13:46:21 PDT 1990 => #(@(a)) ============================================================================== PS: Pnews didn't like my citation/comment-ratio so I included this picture: ***** ** ** ** ** * ** ******* * ** ** * ** *** * * __ __ * ** * / .\ /. \ * ** * \__/ \__/ * ** * . * * * * . * ** * * . * ** ** * * * * * **** * * * * ****** * * ** * ****** * * *** **** ****** * * ****** ** **** * * *** ** * *** ** ** * ********** * | * * | * *** --Kjell -- For athletes and programmers, ! Kjell E. Post a woman is the end of their career. ! CIS/CE ! University of California, Santa Cruz -- A.Wickberg ! Email: kjell@saturn.ucsc.edu