CS 3723 Programming Languages
Questions and Answers, Spring 2005

(See also previous questions: Fall 2004,   Spring 2004.)


  1. Question (Mon Jan 24 19:56:49 CST 2005): I'm stuck on part g of Recitation 1 and was hoping you could offer a hint or two to get me unstuck... I've rid the program of all but 4 labels so far, and cannot figure out which of two of those last labels is a function call... L12 or L6? Seems more logical that L12 would be a function call, but then again, I just don't know.

    Any help would be greatly appreciated.

    [This student sent partly transformed code that compiled and produced the correct output and included the following in the middle.]

    Answer: Maybe this assignment is harder than I thought. I checked your current program, and it does compile and produce what it should when executed. Nevertheless, it seems to be muddled together in some weird way. I didn't realize that you could transform it, while still able to compile, run, and get the right output, and yet have it pretty mixed up.

    With it in its current state, I think I'd be rather stuck too! Anyway, don't worry about the function call, but just try to get it as goto-less as possible.

    For example, in your transformed code, you have a goto L14 _after_ the goto L3. This seems like it's not going to work out. Here's a hint to start from scratch. The original program looks like:

    Now transform it to the following:

    If you think about it, this has broken the code into 3 distinct pieces, each with labels and gotos confined to that piece. You can go on simplifying from here.


  2. Question (Sat Jan 29 23:09:02 CST 2005): I'm in your Programming Language class and I have a question about Recitation 2. I notice that you want us to do both of eliminating the C-comments and the convertion of the Floating Point numbers. Do you want us to do two seperate programs or just have it in one program? If you want us to do it in one program, can't the C-comment part be ignored since we can scan through the file and JUST recognize the floating point numbers, this would eliminate the C-comments automatically. THANK YOU!!!

    Answer: For full credit you should process the given input, which includes C-style comments and floating point numbers intermingled. Yes, it should be one program. At first I didn't understand you, but now I do. If your program was just looking for the start of a floating point constant, which must be either a digit or a dot, it would of course just read past any start or end of a comment along the way. The problem is that a comment might have a number inside it, and that number must be ignored. (I just added such an example to the input for the recitation. The input now has a number 53.53 that is inside a comment, and so should not be processed.) A program that "scanned through a file and JUST recognized floating point numbers" would not eliminate C-comments automatically, and so would find any numbers inside the comments. For full credit you must add code to eliminate comments. You could use code similar to what I supplied, or write your own.


  3. Question (Sun Jan 30 20:10:12 CST 2005): I am a transfer student and this is my first semester attending UTSA. The reason I'm telling you this is because I have a question regarding using parts of your code for recitation 02. I have just read part 10 of the submissions of recitations and was wondering if it was OK to use parts of the code you provided for the c-style comments.

    Also, I would like to know if you grade the time and space complexity of our programs.

    Answer:Yes, of course you can use the code I supply for the course. (It would be insane to say you're not to look at it.) In fact you can use any source at all for your code as long as you give a clear and prominent citation of where it came from. In that case the credit will depend on how much you wrote yourself. No citation is needed for the code I have supplied. Remember, though, that you only learn from the code you write yourself. (I just changed the submissions page to give this information.)

    About the second question, I'm only worrying about the correctness of your code in this course. This corresponds to much of the real world. Most often time and space concerns are of secondary importance (or less).


  4. Question (Mon, 21 Feb 2005 01:51:24): I had a question about rec 5. You said to use the given parser for the arithmetic expressions. I was looking at that and I was just wondering if we were supposed to change anything in it?

    Answer: Of course I meant to adapt the given parser to become part of the new one. There are several minor changes needed, and then you need to embed this code into the larger collection of functions.


  5. Question (Wed Mar 2 19:22:13 CST 2005): I'm trying to figure out how A() knows what to print out from the return from E()... if I return the temp location from E(), then A() ALWAYS tries to print out a temporary location instead of the assigned variable's location!

    I think I'm either thinking too hard about this or am "off track" somewhere in my understanding?

    Answer: Yes, you are a little bit off track, but not too much. You're very close on this.

    First let's look at E. Suppose there is no plus or minus sign, but just other operators. In that case E does _nothing_. E does: "res = T();" and just returns the res. Nothing else. In this case E has no need for a temporary location. What does the res represent? It might be a constant. It might be a single variable. It might be a temporary representing a more complex term. E doesn't know or care. That's true with all of these functions. When they get a return value, they don't care what kind of an expression it was. They process it the same in any case.

    In E, you only need a new temporary in case there is a + or -. Say it is a plus. Then E will call T twice, getting back a value each time, call these arg1 and arg2. As far a E is concerned, it thinks the expression looks like something (whose value will be at location arg1) plus something else (whose value will be at location arg2). _Now_ E will get a new temporary. E will load the locations given by arg1 and arg2 into registers. (Of course I mean that E will output MIPS code to do these things at run time.) Then E will output an add instruction to add the two registers, leaving the result in a third register. Finally, E will output code to store the result into the temporary location. If there are no more + or - signs, E will return the index of this temporary location.

    So inside E (and T as well) don't get a new temporary unless you need it, that is, inside the loop. Of course you have to increment the temp variable after using it.

    Think about A. It calls E and gets back an index (at compile time). A doesn't know or care what kind of an expression it was, whether a digit, a letter, or a complicated expression. A outputs the same two instructions in any of these cases.


  6. Question (Thu Apr 7 07:55:47 CDT 2005): I'm trying to do Recitation 11 and in the first question I can't get the right answer. I'm sure it is something small I missed, but here is my code.

    Answer: This is a common problem. In Java (and C/C++) the / operator used with int arguments produces a truncated integer result, so that 1/n will be zero for n > 1.


  7. Question (Sat Apr 16 15:20:46 CDT 2005): I had a question on part 2 (return address) of Recitation 12. I have it all done and it looks good. My question has to do with the left hand side. The vertical spacing as stated is 15 pts down, But when I do that for the last lineto it looks like it is spaced far below San Antonio text. It seems unporportional to the line above the UTSA text. Should the address area look like it is exactly between the lines or should I just leave the last line 15 points down from the San Antonio text?

    Answer: I didn't specify the spacing for the horizontal lines on the left, or for the height of the box on the right, or for the spacing between the box and the top or bottom text lines on the right. I assumed that you would make it look "good". On the left, 15 points down from the upper horizontal line to the first text line looks good, but 15 points is too far down for the lower text line on the left. You should just specify it so that it looks the same as the upper spacing.