Interpreters: Handling includes/imports
Posted
by sub
on Stack Overflow
See other posts from Stack Overflow
or by sub
Published on 2010-04-09T16:30:45Z
Indexed on
2010/04/09
16:33 UTC
Read the original article
Hit count: 177
I've built an interpreter in C++ and everything works fine so far, but now I'm getting stuck with the design of the import/include/however you want to call it function.
I thought about the following:
Handling includes in the tokenizing process: When there is an
include
found in the code, the tokenizing function is recursively called with the filename specified. The tokenized code of theinclude
d file is then added to the prior position of the include. Disadvantages: No conditional includes(!)Handling includes during the interpreting process: I don't know how. All I know is that PHP
must
do it this way as conditional includes are possible.
Now my questions:
- What should I do about includes?
- How do modern interpreters (Python/Ruby) handle this? Do they allow conditional includes?
© Stack Overflow or respective owner