|typechecking break-statement firstname.lastname@example.org (cp) (2006-12-01)|
|Re: typechecking break-statement email@example.com (Matthias Blume) (2006-12-01)|
|Re: typechecking break-statement firstname.lastname@example.org (cp) (2006-12-03)|
|Re: typechecking break-statement email@example.com (2006-12-04)|
|From:||Matthias Blume <firstname.lastname@example.org>|
|Date:||1 Dec 2006 11:54:21 -0500|
"cp" <email@example.com> writes:
> I was wondering if anyone could give me any pointers (not C pointers)
> on how to typecheck for the occurence of a break-statement outside a
> loop. I'm using the imperative side of SML/Moscow ML language.
I'm assuming you are doing a recursive traversal of the abstract
syntax tree. Simply keep track of whether or not you are in a context
where "break" is legal. This could be as simple as a boolean argument
to the traversal function. Depending on what else your traversal is
doing, you might want to pass additional information about the
"current loop" or the "current switch statement". In this case you
would perhaps have some type "break_info", and the extra argument to
the traversal function would be a "break_info option".
You probably want to do something similar for "continue", which is
legal within loops but not legal when you are merely within a "switch"
(without being also in a loop).
Hope this helps,
Return to the
Search the comp.compilers archives again.