[m-rev.] Re: [m-dev.] '|' as an operator

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Feb 11 17:52:41 AEDT 2003


On 11-Feb-2003, David Overton <dmo at cs.mu.OZ.AU> wrote:
> On Tue, Feb 11, 2003 at 02:31:58PM +1100, Fergus Henderson wrote:
> > On 11-Feb-2003, David Overton <dmo at cs.mu.OZ.AU> wrote:
> > > We have been using `|' as an operator in HAL using the SICstus reader
> > > (which treats it the same as `;', except in lists).  Now that the HAL
> > > compiler is compiling to Mercury, we are using lexer.m from the Mercury
> > > library instead.  Unfortunately, lexer.m treats `|' as a special token
> > > `ht_sep' so it is not possible to define it as an operator.
> > 
> > The reason lexer.m treats `|' as a special token is because that is
> > what ISO Prolog specifies.
> 
> Okay, how about if we do something like the following?  It's backwards
> compatible and allows `|' to be used as a `name("|")' except when we are
> parsing a list.  (I'm still in the middle of bootchecking this, btw, but
> I think it should be okay.)

I think that change will slow down parsing significantly.  Firstly,
you've added another field to the parser state, which will increase by
20% the amount of memory that it allocates for parser states.  Secondly,
you've added an new test every time it gets a token or peeks at a token.
These both seem like a fairly high price to pay.  I don't think it is
worth it.

There are advantages to sticking with a syntax that can be parsed
easily by standard Prolog.  Why don't you just use a different operator?

But if you are really committed to using a non-standard-Prolog syntax,
a more efficient and IMHO more elegant approach to implementing it would
be to change the `IsArg' argument from a boolean to an enumeration of
the different possible states -- an ordinary term, a list element, or an
argument.  That can then be used instead of the `in_list_context' field.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list