[mercury-users] lexer construction

Ralph Becket rafe at cs.mu.OZ.AU
Tue Feb 12 17:39:59 AEDT 2002

Michael Day, Tuesday, 12 February 2002:
> Hi,
> Regarding the ever-handy lex module: creating a lexer (with init) is very 
> time consuming. Therefore, I only want to do it once for a given set of 
> lexemes. However if I want to lex two different things (for example, a 
> string and a file) I'll need to specify a different read predicate in each 
> case, which will require calling init twice, rather pointlessly.
> A couple of solutions present themselves... there could be a function to 
> change the read predicate of a lexer, or there could be a two step method 
> of constructing a lexer that involved first compiling the lexemes and then 
> selecting the read predicate, allowing several lexers to be created from 
> the same set of compiled lexemes. These would require modifications to 
> lex, which is why I raise them here, as it is tiresome maintaining 
> locally modified modules in parallel to the official version.
> A third possibility is to make a type that encapsulates all possible 
> sources and a read predicate that checks which source every time, which 
> would be slightly inefficient and ungainly but wouldn't require any 
> changes to lex whatsoever.

You're quite right, although I wasn't aware that it was a performance

I think the right solution is to use type classes, supply the
appropriate instances for IO streams and strings, and get rid of the
need to mention the input stream source type at all in calls to init.

I'll put this on the TODO list, but I'm afraid there are several other
tasks closer to the top right now.  If the status quo is a *major*
problem, let me know and I'll see what can be done about bumping up the
priority of this task...

- Ralph
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list