-
Notifications
You must be signed in to change notification settings - Fork 0
Internals of the tool
This is where the internal workings of the tool are explained.
In execution the tool reads the input file line by line and keeps only one line in a buffer. Here are the steps it goes through:
- A command is sought, dividing the line into a part of text before the command and after the command.
- Next the part before is checked out. If it's only whitespace and a command was found then nothing is outputted. Otherwise the text goes to the output file.
- Now the command is checked out, if there is one. The function of the command is looked up and executed giving the command the rest of the string which it can interpret by itself.
You may wonder how the if/then/else can work with only these steps. The answer is it wouldn't. I left that part out. For the if/then/else functionality I've added two stacks. One holds the boolean valuation of the condition which tells us whether or not anything should be outputted and/or executed with the commands. The or holds a boolean wether or not an else has been seen or not.
Now when an if is found, a boolean valuation of the condition is put on the conditions stack. When an else is found it checks wether or not an else has been seen before (if so ERROR!). Then it registers the else on the second stack and inverts the latest condition on the condition stack. The endif just pops the top of both stacks :)
The other commands check the stack themselves to see if they should do anything. I may move that to somewhere before the execution of the command so there's less code duplication.