catch not an rvalue

Luke Gorrie <>
Tue Feb 19 18:08:01 CET 2002


Hal Snyder <> writes:

> Hope this isn't another RTFM, but I can't resist asking.
> Am going through the puzzle box while home with the flu.
> 
> During prototyping, it would be nice to replace
>   X = <risky expression>
> with
>   X = catch <risky expression>
> but the shell (and compiler) don't like that.
> 
> Just wondering why the syntax error is happening.
> Didn't see the answer in, e.g., Chap 6 of
>  http://www.erlang.org/download/erl_spec47.ps.gz 

This keeps coming up all the time :-)

I had a squiz at the grammar in the spec and in
stdlib/src/erl_parse.yrl, and it seems to be caused by the
implementation of operator precedence. "Catch" binds the weakest
(`expr'), a match (`expr_100') needs at least another `expr_100' on
its right hand side. I don't know enough about parsing to know if
that's the way it has to be.

But, with ignorance established as my defense, I hacked erl_parse.yrl
so that any expression can appear on the right hand side of a match
(patch below). It seems to do what you'd expect - "X = catch 1 + 2."
binds X to 3 - and it at least managed to compile > 100K lines of code
without complaining.

So.. maybe someone can explain what it's all about?

NB, the new parser comes out about the same size at 4 lines longer
than the normal 4925 line erl_parse.erl.

Cheers,
Luke

-------------- next part --------------
A non-text attachment was scrubbed...
Name: erl_parse.patch
Type: text/x-patch
Size: 453 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20020219/43523ee2/attachment.bin>


More information about the erlang-questions mailing list