This is an old revision of the document!

June 29: Implemented while-done loops and for-done loops. The current idea is:

  • I have a global variable prog_ctr, that is the program counter
  • A stack (not as a stack, but just for storage space) is used to store the commands
  • Another stack is used to store the information for a loop.
  • In the system() function (I'm using this because it is the common point for both scripts and typed commands), a command is stored if the prog_ctr >= size of the command list. This means that it is a new line, that has not been stored before
  • while, for, do (not yet implemented), done, break and continue are defined as commands.
  • The while and for commands will push the required information onto the loop stack, and the evaluated condition onto the if stack. In addition, the for command has to check whether this is the first iteration. If so, it will set the loop variable to the first word in the list, else it will set it to the next one. Similar to the if command, the while and for commands will push a 0 onto the if stack if the top of the stack is 0 (meaning that the commands in the loop should not be executed).
  • The done command will check whether the top of the if stack is true. While it is true, all the commands inside the loop will be executed. This will run through all loops exactly one extra time, without executing it.
  • break and continue will set the values in the if stack, from the while/for condition to the top of the stack to 0. Now, since continue means to continue from the next iteration onwards, this fact needs to be stored as part of loop information, and considered by the done command.
  • The do command will need some thought.

Hence, the following fields are needed for each loop:

  • program counter for start of the loop
  • the position of the loop condition on the if stack (required for break and continue)
  • whether we have encountered a continue
  • the current argument in a for loop

Today's commits:

QR Code
QR Code soc:2009:lynusvaz:journal:week6 (generated for current page)