DM565 - Formal Languages and Data Processing
 
Fall 2023
Kim Skak Larsen

Home Innovation

Exercises
  1. Extend SCIL with a new construction

    repeat 〈statement_list〉 until 〈expression〉 ;

    You must go through all the relevant phases. You can get significant inspiration from considering the while-loop equivalent.
  2. It is a little annoying to have to declare a variable and write dummy = f() in situations where we do not really want the function to return any value. Change this in SCIL by allowing an expression as a statement. It is ok (and easiest) to still require that all functions return a value. At the point where you now do not use the value, you should remember to pop it off the stack.
  3. Discuss how to add break and continue statements to while-loops so they can be used as illustrated below, where we add positive values from an array until reaching the (stop) value zero.
    i = -1;
    sum = 0;
    while i+1 < length(A) do {
       i += 1;
       if A[i] == 0 then break;
       if A[i] < 0 then continue;
       sum += A[i];
    }
    
    Discuss what would be needed in the different phases of SCIL to add this feature. (Note that the motivating program example is not a SCIL program, but this is irrelevant for the discussion of how to add the feature, and we just assume that SCIL already has arrays, etc.)

    After this discussion, consider nested while-loops using these features. How should it work, and does your solution supply the right functionality?
  4. Discuss what should be done in the different phases if we wanted to add the type boolean and allow the operators and, or, and not.
  5. Discuss how C-style for-loops could be added to SCIL via syntactic sugar.
  6. Some of the above exercises only ask for discussions of how to implement a feature in SCIL. Though it may not be covered at the exercise class, implementing any of the above-mentioned extra features in SCIL will of course only boost your understanding of compiler construction.

 


   Data protection at SDUDatabeskyttelse på SDU