Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!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 Summary: prefix operators as atoms should not be a special case Message-ID: Date: 8 Dec 89 11:58:28 GMT Sender: news@sics.se Distribution: comp Organization: Swedish Institute of Computer Science, Kista Lines: 67 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 (, ..., ) 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