🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4108

canonical syntax

#4108
From: Mats Carlsson
Date: Fri, 08 Dec 1989 11:58
67 lines
3441 bytes
There is a problem with the "Syntax of Terms as Tokens" of Common
Prolog, which complicates the definition of a canonical syntax.

The canonical syntax is normally defined as quoting atoms that need it
and ignoring op declarations, writing all compound terms as
	<functor>(<arg 1>, ..., <arg n>)

The culprit is the syntax rules for term(N), which typically looks like

@var{term(N)}     --> @var{op(N,fx)}				(**)
                   |  @var{op(N,fy)}				(**)
                   |  @var{op(N,fx)} @var{subterm(N-1)}
                         @{ except the case @kbd{-} @var{number} @}
                         @{ if subterm starts with a @kbd{(},
                           @var{op} must be followed by a @var{space} @}
                   |  @var{op(N,fy)} @var{subterm(N)}
                         @{ if subterm starts with a @kbd{(},
                           op must be followed by a @var{space} @}
                   |  @var{subterm(N-1)} @var{op(N,xfx)} @var{subterm(N-1)}
                   |  @var{subterm(N-1)} @var{op(N,xfy)} @var{subterm(N)}
                   |  @var{subterm(N)} @var{op(N,yfx)} @var{subterm(N-1)}
                   |  @var{subterm(N-1)} @var{op(N,xf)}
                   |  @var{subterm(N)} @var{op(N,yf)}

@var{term(1000)}  --> @var{subterm(999)} @kbd{,} @var{subterm(1000)}

@var{term(0)}     --> @var{functor} @kbd{(} @var{arguments} @kbd{)}
                         @{ provided there is no space between
                           the @var{functor} and the @kbd{(} @}
                   |  @kbd{(} @var{subterm(1200)} @kbd{)}
                   |  @kbd{@{} @var{subterm(1200)} @kbd{@}}
                   |  @var{list}
                   |  @var{string}
                   |  @var{constant}
                   |  @var{variable}

@var{constant}          --> @var{atom} | @var{number}

@var{number}            --> @var{integer} | @var{float}

@var{atom}              --> @var{name}
                         @{ where @var{name} is not a prefix operator @}

The two rules marked (**) cause prefix operators used as atoms to have
precedence N, whereas all other atoms have precedence 0.

Another rule, not included above, defines the "context precedence" of
arguments of compund terms as 999.  Consequently, prefix operators
with precedence > 999 must be parenthesized *in the canonical syntax*
when they occur in compound terms, as in

	p((public)).


Questions:

What is the point of the above distinction between prefix operators and
other atoms?  To simplify the parser?

The canonical syntax would become independent of op declarations if
the two (**) rules and the constraint on @var{atom} not being a prefix
operator were deleted.  Would this measure make it more difficult to
parse or cause any other bad effects?
--
Mats Carlsson
SICS, PO Box 1263, S-164 28  KISTA, Sweden    Internet: matsc@sics.se
Tel: +46 8 7521543      Ttx: 812 61 54 SICS S      Fax: +46 8 7517230
Technical Details
Message-ID: <MATSC.89Dec8125828@vishnu.sics.>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!usc!ucsd!ucsdhub!hp-sdd!hplabs!hp-ses!hpcuhb!hpsmtc1!hpda!motcsd!apple!brutus.cs.uiuc.edu!samsung!cs.utexas.edu!tut.cis.ohio-state.edu!purdue!bu-cs!bloom-beacon!eru!luth!sunic!sics.se!sics.se!matsc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!wuarchive!usc!ucsd!ucsdhub!hp-sdd!hplabs!hp-ses!hpcuhb!hpsmtc1!hpda!motcsd!apple!brutus.cs.uiuc.edu!samsung!cs.utexas.edu!tut.cis.ohio-state.edu!purdue!bu-cs!bloom-beacon!eru!luth!sunic!sics.se!sics.se!matsc
From: matsc@sics.se (Mats Carlsson)
Newsgroups: comp.lang.prolog
Subject: canonical syntax
Message-ID: <MATSC.89Dec8125828@vishnu.sics.>
Date: 8 Dec 89 11:58:00 GMT
Lines: 67