Hi experienced people!
I am working on an interpreter of sorts. I would like its scripts to be invokable from the command line - so It would honor the “#!” as a first line, basically by making any line starting with a “#” a comment.
The issue is that I want to be able to read the source code more than once. The first pass will deduce the number of lines, the number of variables, the number of line labels, The beginning of the second pass will allocate arrays (malloc) to hold the program and its data, then re-read the source to store it internally and fill symbol tables and mark variables. once the source is read the 2nd time the program will begin to execute.
If an interpreted program is mentioned on the command line it would only get one pass at the source, right? That source would come in on standard input, and once read is no longer available.
Is there a way for my interpreter to get the file name instead of the body of the file?
While writing the question I came up with an idea, but I hope there is a better one. I could as a first pass store each line of the program in a known temporary file, then for the second pass I could read that file. I don’t like this but if there is no better way…
More Background might be helpful - I am writing an interpreter that will read and execute “keystroke programmable RPN calculator program”
The #! I am asking about will be in the text of the calculator program, it will cause the interpreter to be loaded.
My understanding is that after that the rest of the file of calculator program steps will be presented to the C program as standard input. But if that is the case, then I only see this input once and have no way to elicit a second pass through the code.