Computer Science Canada use of include statement with variable filename |
Author: | SuperGenius [ Sun May 16, 2004 6:04 pm ] | ||
Post subject: | use of include statement with variable filename | ||
This is part of the code from my drawing program and what I'm trying to do is get the program to write data to a .t file to take some of the sting out of complicated drawings. I want the program to include the file that it is writing to so that the user can develop a drawing using the stuff they've already done as a base so that the drawing wont look like a blind person did it. I set it up so that the user inputs a word and the program tacks .t onto the end of the string but I get an error "illegal include statement"
|
Author: | Tony [ Sun May 16, 2004 6:11 pm ] |
Post subject: | |
you can't do that. include file must be static at compile time since the program does not contain the compiler to execute variable commands at runtime. If that is what you really want to do though, you can write an enterpriter to recognize the commands in the file and execute them. |
Author: | SuperGenius [ Mon May 17, 2004 3:53 pm ] |
Post subject: | |
tony wrote: If that is what you really want to do though, you can write an enterpriter to recognize the commands in the file and execute them. two questions: How would I do this? Would it be difficult? |
Author: | Tony [ Mon May 17, 2004 6:44 pm ] | ||
Post subject: | |||
its not neccessary difficult. I've made an enterpriter in turing before. basically you assume perfect syntax and read one command at a time. Then according to what it is, read the number of parameters required. Such as:
obviously you'd have to cut out all the extra junk such as ()s and ,s but you could (and should) use them as your flags in conjunction with index() to cut the code line into command and arguments. |