[m-rev.] for review: make parsing tail recursive

Paul Bone pbone at csse.unimelb.edu.au
Wed May 7 22:16:21 AEST 2008


On 07/05/2008, at 2:41 PM, Zoltan Somogyi wrote:

> On 07-May-2008, Paul Bone <pbone at csse.unimelb.edu.au> wrote:
>>     ( Token = io_error(IO_Error) ->
>>         io.error_message(IO_Error, IO_ErrorMessage),
>>         string.append("I/O error: ", IO_ErrorMessage, Message)
>>     ; Token = junk(Char) ->
>>         char.to_int(Char, Code),
>>         string.int_to_base_string(Code, 10, Decimal),
>>         string.int_to_base_string(Code, 16, Hex),
>>         string.append_list(["Syntax error: Illegal character 0x",  
>> Hex,
>>             " (", Decimal, ") in input"], Message)
>>     ; Token = error(ErrorMessage) ->
>>         string.append("Syntax error: ", ErrorMessage, Message)
>>     ;
>>         check_for_bad_token(Tokens, Message, LineNum)
>>                                              ^^^^^^^ It's unified  
>> here too,
>>         when LineNum is unified here it probably shouldn't be  
>> unified against
>>         the line number in the first argument.
>>     ).
>>
>> Perhaps using a switch over all the function symbols that Token  
>> may be can help as well.
>
> Yes, that would be a good idea. The reason why didn't do it originally
> is that it would have required duplicating the code for the  
> "everything else"
> case, but that has not been a concern since I implemented multi- 
> cons-id
> switch arms.
>

I thought that before the multi-cons-id switch arms it was still  
possible to write:

	(
		( Var = fn1
           	; Var = fn2 ),
		goal
	;
	...

and goal would be duplicated by the complier, but the human didn't  
need to duplicate goal, and the compiler would correctly understand  
the determinism of the entire switch.

So that the multi-cons-id switch arms was an optimization.

Did I misunderstand?

Thanks.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20080507/a18f8af9/attachment.sig>


More information about the reviews mailing list