[mercury-users] lexer construction

Michael Day mikeday at bigpond.net.au
Tue Feb 12 16:28:40 AEDT 2002


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.

Any thoughts, fellow lex users?


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