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…
No, the #! is the input to an Interpreter that is written in C. The rest of the file is in “calculator language” (sort of like an HP41C but labels are merged with steps and variables take up one step each but are named so you can have as many as you like). The
I am not getting this, but anyway, I am writing an interpreter in C to run a program written in “Calculator Language”
What are you saying? I think that word was supposed to be “implementation”, but what is a “FILE define”? The interpreter won’t have the name of the file, will it?
One thing I might do is provide the name of the calculator language file in the shebang so the interpreter sees it…
This is the start of a file in calculator language named fizbuz.lnc :
#! /bin/lincalc fizbuz.lnc
The interpreter would see this first line on its standard input and stop reading standard input, and open the file “fizbuz.lnc” but this is non-standard for a shbang line. Also, this won’t work if the shebang is stripped off the input by the shell and not provided to the called program.