UNIVERSITY OF DELAWARE <br>
 DEPARTMENT OF COMPUTER AND INFORMATION SCIENCES


CISC 672 Advanced Compiler Construction
(Spring Semester 2002)

Frequently Asked Questions

Assignment PA1:

2/6:Question: what are <, >, = supposed to return on the top of the stack
Answer: They are relational operators. So, they return either 0 for false or 1 for true on top of the stack, depending on whether stack-2 < stack-1, for example.

2/6: Question: do we have to implement the stack for numbers > 9
Answer: Yes, you should implement it for numbers > 9. You can use the existing codes to convert between strings and integers. There are class methods for substr also.

Clarification of ta office hours: I just wanted to say it may be worth noting that my office phone # given above is not the number at 51 East Main Street(to the best of my knowledge, there is no phone at 51 East Main Street). The number above is the phone # for my regular office which is at 28 West Delaware Avenue. So, if you call during office hours and they say that I'm not there, it's bc I am at 51 East Main Street where office hours are held.

Please feel free to send me email with questions as well. Email is the quickest way to contact me and I am often up late at night and check my email.

2/7: Question: I am just wondering something about the a command. You have mentioned in the assignment that the a command is similar to repeatedly performing 'e'. However I noticed in your second test file, you have a stack similar to this:

- * 40 3 + 2 12 10 4..

So, I am thinking how we are supposed to use the a command to evaluate this, since the 2 following entries should be integers. Since you have also mentioned that our program need not do error checking, I am wondering what iam missing out.
Answer: The stack2.test contains a typical postfix notation expression. I think I misled you by saying " the 'a' command evaluates the entire contents of the stack similar to repeatedly performing 'e'. It is not as easy as just calling the 'e' command repeatedly. There is other work to be done also. That is why it says "similar to". The 'a' command cannot evaluate the stack by repeatedly calling the code for the 'e' command without doing other work, when the operands below the operator are not integers. In this case, the 'a' command has to evaluate the next operator first to get its result to be the operand for the top operator. My suggestion is to deal with the 'a' command last after you have the rest of the commands working properly. It is the most challenging.

2/7: Question: To implement a stack, in a simple way, we need a concept of an array or a list that can hold different elements. Is there a concept of Array in COOL? I did a google search and found out that int X{10]; can work in COOL but then this compiler gives an error for the same. So should we implement our own List? Answer: First, you should be trying to make your program as oop-like as possible so that you learn the oop features of Cool. Answer: Arrays are not built into Cool as a predefined type structure. int X[10] is not legal in Cool. The syntax for declarations is varname : typename ;

2/11: The deadline is dated online by midnight tomorrow, the due date. Remember the turnin procedure emails the ta to let us know that you have officially turned it in.

2/25: Hello Class(es).

I need to change my office hours for tomorrow and on Mondays in general (I am required to attend talks in the cis dept. from 9-10am on Mondays for about the next month I believe...).

My new Monday office hours will be from 11:15 am - 12:15 pm. My Friday office hours will stay the same as they are now.

Stacey

2/26: Turning in PA2:

To turnin your work type:

% gmake turnin MYSECRET=yoursecretname

This will collect the files cool.flex, test.cl, and README. Don't forget to edit the README file to include your write-up, and to write your own test cases in test.cl.

You may turn in the assignment as many times as you like. However, only the last version will be retained for grading.

2/28: Questions from PA2

1. What is the LET_STMT token for?

Answer: I don't know. You can use either as long as you use the same one in your parser, there is no need for both of them to exist.

2. Is there any boundary condition for integers too? I tried out 10000000000000000 and the scanner gives out some other result.

Answer: Your machine boundary for integers, which is probably 4 bytes. (2^32)-1 = 4,294,967,295 for unsigned int.

3. In what field of the cool_yylval do we put the lexeme for the single character symbols before we return? Thanks!

Answer: if you mean things like * / + - < = then just return the lexeme, no need to put it in cool_yylval

4. Is there any length limitation on object ids and type ids like MAX_STR_CONST for string constants?

Answer: not that I am aware of. You may want to check documentation for limits of yytext, but I am not aware of any. You do not need to check the size of ids.

5. Should we convert int constants to integer before adding them to inttable so that "0000128" is same as "128"?

Answer: no

Is there any value ranger for accepted int constant like from 0 to 2^16 ?

Answer: see similar question above.

6. What is nested comments? I am assuming (* (* *) (**) *) is valid and (* (* *) is not valid.

Answer: correct

7. What is the difference between error and ERROR?

Answer: ERROR is a token you can return from the lexical analyzer, and is user defined. Returning ERROR will in the lexer will cause a parse error. error is a terminal/token defined by bison that you can use in bison to recover from parse erorrs (so that you can continue parsing). see the bison online documentation for more info. I would think JCup provides something similar.

3/11: Questions for PA3

When I run the parser after writing the grammer (not the actions), it goes till the end of the program, but gives a segmentation fault at the end. the error looks like the following

OBJECTID '(' ')' ':' TYPEID '{' expression_all '}' feature_list sfeature ; #97 _program #76 _class CellularAutomaton IO "cells.cl" ( Segmentation Fault ren[37] [~/CISC672/AS3/]>

Do we need to bother abt this error? I guess it is coz of the fact that the actions are not yet added.

Answer: You can ignore this for this first deadline. This is normal until the actions are added.

3/11: I was wondering if error recovery is part of the grammar due on tuesday, or is it part of the complete assignment due on 21??

Answer: You can do error recovery for the final deadline.

Answer: You can ignore this for this first deadline. This is normal until the actions are added.

Questions for Parsing Homework

3/20: Question: Is the first production in q3. is S-> F=T|T istead of S-> E=T|T ???

Answer: The first rule should read: S -> T = T | T

3/20: In question 2, the $ in the grammar is not the $ for end of input. If you want to change this $ to the symbol * to avoid confusion, go ahead.

3/20:The grammar should be:

S -> Xe | cXd | Yd | cYe

rest is the same as the sheet.

Questions for PA4

4/17: Question: We are working on finding out the types of our features. Tree.h claims to have a get_type function, but it is not defined in the header. I would really really really (etc...) like to use that functions. :-) What course should we take? Trying to define it in Feature_EXTRAS causes problems and the variable "type" (which should also be in tree.h) is not defined. We shouldn't modify tree.h. :-/ How can we get all those type symbols that the parser put in for us? Thanks!!

Answer: get_type is defined in cool-tree.handcode.h which you get when you do the gmake for the PA4 assignment.

Question: let(x:Int<-4 , x:Int <-3) in {.. }

it should be illegal, but

let(x:Int <- 4) in let(x : Int <- 3) in {...}

should be legal, with the x=3 shadowing the x=4. once we are past the parse stage, these two are indistinguishable; all lets with > 1 variable declaration are passed as nested lets. in the first example, the variables should be in the same scope, or no? there should be a way to catch this error.... (i don't think coolc catches it, it will compile anyway)

Answer:

On page 10 of the Cool manual, it says if identifiers are defined multiple times in a let, the later bindings hide earlier ones. So, both statements above should be treated the same, thus the reason for changing the single let into a nested let. It actually makes symbol table creation and accessing easier after the change.

Question: we were trying to use the get_type function for the expression , but it doesn't seem to return anything. are we supposed to implement it? also what does the Symbol type point to?

Answer: get_type returns the Symbol corresponding to the type inferred for an expression node in the AST. So, you can do things like:

if ((e1->get_type() != Int)...

where e1 is pointing to the root of the left subtree of the current expression being type checked.

Question: There is a functions already defined in semant.cc called install_basic_classes() which I suppose creates AST nodes for the basic classes. however when I traverse the classes list passed to the ClassTable constructor, it is unable to find any nodes for the basic classes.

Answer: The ClassTable constructor needs to initializes a symbol table mapping class names to inheritance graph nodes. The constructor can call install_basic_classes to install the predefined basic classes into the symbol table, not the AST.

Question: We were wondering what is the type of isvoid. right now we have put Boolean by default. We are not able to figure out clearly from the type checking rules. Also what is the type for the no_expr tree node?

Answer: for isvoid, the rule just says that if expr e1 has some type T1, then isvoid e1 has type Bool. so you want to typecheck e1, set the type for the isvoid expression to Bool, and return Bool. in short, you are correct - Bool is the type.

for no_expr you should use No_type.

Hint: Pointers to the exited scopes can be maintained as you exit by adding a pointer from the AST.

Question:The code given to us, in a lookup checks only the nested scopes and doesn't follow the inheritance graph.

Answer: In class I mentioned that you might want a class table list. and a set of symbol tables for each class, and have a pointer to the parent class in the ast node. so if you don't find it in the scope of the current class, you find out who it's parent is and check the parents table. this is just a variation of keeping pointers to each classes scope in one symbol table perhaps...

5/02: Question: we are not sure what ClassNameTab means and what are its fields. Also should its fields (and the class_nameTab fields) should be in the same order as that generated by coolc?

Answer: The ClassNameTab is a mapping from class tags to class names. The ordering used within the table is up to you.

Questions for PA5

5/06: Question: I notice that the dispatch tables list inherited methods. What happens when a method overrides another method. Are both methods listed or just the one that is lowest in the inheritance tree.

Answer: The dispatch table for a given class should have an entry for each method that makes sense for that class. That will include its own defined methods as well as inherited ones that are NOT overridden. So, given a class C, it should have entries for each method that C inherits and does not override, and then C's locally defined methods, including those overriding inherited methods. The dispatch tables implement the inheritance rules.

5/08: Question: > > 1. In the code generation of cases we came across an instruction li, we > > are not sure what value is given to its imm parameter. it shows some value > > that is never found anywhere else in the rest of the code. for eg li $a0 > > 21. We don't know how to get this 21. >

Answer: The imm parameter is indeed the line number. It is emitted as the value to be loaded immediately into a temporary register T1. They generate an LI T1 linenumber instruction before the dispatch_abort and case_abort routines are called in coolc. But, the emit_case_abort and emit_dispatch_abort routines just emit JAL instructions, so these loads into the temporary seem extraneous to me.