Re: typechecking break-statement

Matthias Blume <>
1 Dec 2006 11:54:21 -0500

          From comp.compilers

Related articles
typechecking break-statement (cp) (2006-12-01)
Re: typechecking break-statement (Matthias Blume) (2006-12-01)
Re: typechecking break-statement (cp) (2006-12-03)
Re: typechecking break-statement (2006-12-04)
| List of all articles for this month |

From: Matthias Blume <>
Newsgroups: comp.compilers
Date: 1 Dec 2006 11:54:21 -0500
Organization: private
References: 06-12-014
Keywords: analysis
Posted-Date: 01 Dec 2006 11:54:21 EST

"cp" <> 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,

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.