Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #910
| From | Aleksey Demakov <ademakov@gmail.com> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: interpreter: how is it possible to interpret nested IF ELSE ENDIF ???? |
| Date | 2013-05-31 16:07 +0400 |
| Organization | Compilers Central |
| Message-ID | <13-05-024@comp.compilers> (permalink) |
| References | <13-05-009@comp.compilers> |
Hi, Just have in your interpreter a structure that has all the information required to execute one statement. To support nested statements every such structure should have a pointer to the parent structure. You will have a global pointer to the currently executing statement. When interpreter meets a nested statement it creates a new structure, saves the current statement in the parent pointer and makes the new structure current. When the interpreter reaches the end of the current statement it takes its parent pointer and makes it current. For if-else-endif statement you will need to remember within the structure if the if-condition was met. Depending on it you set a global skip-flag when entering either of the two if branches. When the flag is set the statements like assignments and procedure calls are just ignored. But for nested if-else-endif statements the interpreter still creates nested structures and observes the described above order of entering and leaving them. But on entering a branch before setting the skip flag it is required to save its previous value and on leaving a branch the previous value has to be restored. Such implementation technique works well for such simple cases as #ifdefs of c preprocessor. But when it is necessary to handle something more complicated like loop statements or gotos then it becomes more practical to have some sort of intermediate representation like ASTs or bytecodes. Regards, Aleksey
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
interpreter: how is it possible to interpret nested IF ELSE ENDIF ???? Jens Kallup <jkallup@web.de> - 2013-05-15 07:42 +0200 Re: interpreter: how is it possible to interpret nested IF ELSE ENDIF ???? Aleksey Demakov <ademakov@gmail.com> - 2013-05-31 16:07 +0400 Re: interpreter: how is it possible to interpret nested IF ELSE ENDIF ???? mertesthomas@gmail.com - 2013-06-19 03:43 -0700
csiph-web