[m-dev.] Re: user-defined operators
Peter Schachte
schachte at cs.mu.OZ.AU
Fri Jul 9 10:40:15 AEST 1999
On Fri, Jul 09, 1999 at 07:54:28AM +1000, Fergus Henderson wrote:
> Well, the current implementation reads in and parses one file at a time.
Ah, I see. So presumably you'd want to change that to: read in and
parse one module and all its imported interfaces.
> The compiler would also need to be able to save and
> restore the state of the current operator table, because any operator
> declarations in the main file should not affect the way that declarations
> in the interface files are parsed.
Since you (the compiler) generate the interface files, you could just
arrange that they always be written in canonical (display) format.
> > I guess there is still the question of how to handle importation of
> > two different modules that have incompatible operation declarations
>
> One possible approach is to use a partial order rather than a total
> order for the operator precedences.
This would give you some of the power of a real (context-free)
grammar, but also much of the pain of one. In fact, maybe more,
because you'd have to remember to declare a new operator's
relationship to *all* the other operators it's related to. If two
separate packages declared new (what would be) precedence 1000 xfy
operators, they couldn't be used near each other without parenthesis.
This would be surprising to users.
If you're going to do something like this, I think it would be better
to go all the way and allow user-written grammar rules. In this way,
one could just add one new grammar rule like maybe:
:- grammar clause_body(parallel_conj(X,Y)) -->
goal(X), ['&'], clause_body(Y).
Of course, this would be significantly harder to implement.
> > Are there any other hard problems?
>
> Integrating operators with the module system in this way would make it
> significantly more difficult to write programs that parse Mercury source
> code, e.g. preprocessors.
Not if your term reading library has a basic operation to read a
module file and all the interfaces it depends on. The user can always
ignore the interface information if they don't need it.
--
Peter Schachte Never doubt that a small group of
mailto:schachte at cs.mu.OZ.AU thoughtful committed citizens can change
http://www.cs.mu.oz.au/~schachte/ the world, indeed it's the only thing
PGP: finger schachte at 128.250.37.3 that ever has. -- Margaret Mead
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list