Frequently Asked Questions for CISC 672 Project

This page is meant for the TA and instructor to post answers to questions asked via email so the whole class can benefit from the answers.
Questions on Homework 5
Q1: When will the folder be availabe?
A1: I have uploaded hw5/ directory to each of your account. It contains the ReadmePhase4.txt, a pdf guide file and a source folder cgen/.

For this last (code generation) programming assignment, you will be working in the cgen folder. Be sure to update your classpath to that cgen/ folder.

Currently, if you run (under cgen/)

  java testEnvironment.CoolCompiler ../../examples/x.cl

you would get a x.s file in ../../examples/ directory. It is the code generated by the solution class. So in the bin/ directory. You run spim and load “x.s”, you should be able to run the program.

To use your treeNodes and codeGeneration solution, modify the last “true” of the following line in CoolCompiler.java

  CoolCompiler coolc = new CoolCompiler(new SolutionLexerFactory(),
  new SolutionParserFactory(), true, true);

to “false”. As you already know, this true is using solution class, false would be using your own solution.

Currently, if you change true to false and run

  java testEnvironment.CoolCompiler ../../examples/x.cl

you would get an empty x.s file in examples/.

So modify treeNodes and files in codeGeneration/


Questions on Homework 4
Q1: Give me a working code, this time.
A1: This time you will be working under ~/name/hw4/semant/ directory instead of ~/name/src/.
Remember to change CLASSPATH variable.

In the hw4/ folder, there are README for this phase, a pdf file hopefully will be helpful and four txt files.

1) If you run

  java semanticAnalyzer.Semant ../../example/arith.cl >> java_after_on_arith.txt 
  you get the same  java_after_on_arith.txt.
  It uses the solution(might not be perfect) class to do the semantic checking. It gives you an alternative 
  way (besides bin/semant) to see what is the expected result.


2)If you run under the long-existing directory bin

 lexer name/example/arith.cl |parser | semant >> bin_semant_after_on_arith.txt
 you get the same bin_semant_after_on_arith.txt
 It is  the standard bin/semant's output.


3)If you run under the long-existing directory bin

 lexer name/example/arith.cl |parser >> bin_semant_before_on_arith.txt
 you get the same bin_parser_after_on_arith.txt
 It is the standard bin/parser's output.
 It shows where you start from.

4)THIS IS IMPORTANT

 you must comment out the following lines in semanticAnalyzer/Semant.java
"
 String s = CoolCompiler.solutionSemant(CoolCompiler.lexAndParseToDumpedAST(new SolutionLexerFactory(),new SolutionStudentParserFactory(),args));
 System.out.println(s);    
 "
And Uncomment the lines following these two lines:
"
Program result = CoolCompiler.lexAndParseToStudentAST(new SolutionLexerFactory(), 
   new SolutionStudentParserFactory(), 
   args);
  
 // The call to the semantic analyzer
 result.semant();
  
 OutputStreamWriter out = new OutputStreamWriter(System.out); 
 result.dumpWithTypes(out, 0);
 out.flush();
 out.close(); 

“ then you recompile the Semant.java

  javac semanticAnalyzer/Semant.java


then run

 java semanticAnalyzer.Semant ../../example/arith.cl >> java_before_on_arith.txt \\

you will get the same java_before_on_arith.txt.
It uses the current class files. And you need to add java code to update these classfiles.
————————————————————————————————
you can diff between these files to understand the difference.

testCasesSemantCheck folder is in root directory, however.

Questions on Homework 3

Q8:About line no. and dump method
A8:Ignore them.

Q7:How could I see output (at least part) of the AST of my program?
A7:After the construction of a treeNode, you need to implement almost all the dumpWithType methods in treeNodes/.java files.
Q6:Where is the testCasesParser/ directory?
A6:I don't have the files in the directory yet. Lori might have that directory. Please wait for update.
Update:testCasesParser/ directory has been updated. Please do an update.

Q5:What should be handed in for deadline 1?
A5: LORI - Just the specifications with a working grammar, no action rules needed. You can test whether your program accepts correct cool files located in examples/ directory. (output nothing for deadline1, output AST tree for deadline2).

Q4:The constructor for Let looks like it takes information about a single variable declaration. However, Let can have a list of variable declarations according to the Cool Reference Manual. How do we deal with this?
A4:You might want to try introducing something similar to class_list, feature_list (i.e. LET list) to address this issue.

Q3:Constructor for Attribute takes an initial expression. However, attributes might not be initialized. Is it correct to pass an instance of NoExpression as the init in this case?
A3:Yes.

Q2: We have NEG and NOT terminals, which correspond to Negate and Complement, but which is which?
A2: NEG–Negate, NOT–Complement

Q1: I get the following error

  1. ”../examples/hello_world.cl“, line 2: parse error at or near OBJECTID = main
  2. java.lang.NullPointerException
  3. at parser.StudentParserFactory.parse(StudentParserFactory.java:22)
  4. at parser.Parser.lexAndParse(Parser.java:47)
  5. at parser.Parser.lexAndParseCoolSource(Parser.java:65)
  6. at parser.Parser.main(Parser.java:74)
  7. Compilation halted due to lex and parse errors -

Is this error because I havent written the grammar for an OBJECTID?
A1: Yes, you are right. Write grammar to match OBJECTID so the parser won't report error. What you need to do is to expand the cool.cup file with the grammar. And later implement in TreeNodes directory to output AST.

Questions on Homework 2
Q6: Where is the Symbol.java file?
A6: It is easier to get the answer to this using SourceInsight(in Windows) or Eclipse (preferred).
The following describes how to use ECLIPSE to help understand the code structure of the cool compiler.

  1. Suppose your ECLIPSE working directory is in ~/cisc672_f10/your_account_name.
  2. Open ECLIPSE (workbench is your working directory.)
  3. Click File→New→Java Project.
  4. Assert{src directory is under ~/cisc672_f10/your_account_name.}.
  5. Name the project src, and click next.
  6. About to finish. All the packages have been imported now to ECLIPSE.
  7. Click Run→Run Configurations
  8. Select and Right Click Java Application
  9. Choose New
  10. Set the name to JLex(whatever…)
  11. in Main tab, set Project to src, set Main class to lexer.JLex
  12. in Arguments tab, set Program arguments to lexer/CoolLexer.lex
  13. Click Apply and run.
  14. Now you know how to run lexer.Lexer examples/*.cl, similar to previous 5 steps.

If you have issues setting ECLIPSE to work, please let me know.

Q5:Having problem dealing with INT_CONST/STRING_CONST ?
A5: Keep in mind that, for INT_CONST, STRING_CONST, not only should you return “TOKEN.INT_CONST” but also the content-string of INT_CONST and STRING_CONST because they are later to be dumped as tokens lile INT_CONST 555 or STRING_CONST “blabla..”. Think how you would return a pair like that. You may want to use AbstractSymbol and/or AbstractTable class located in SymbolHandling.


Q4: How could I distinguish keyword “in” and “in” in “main” or “something” or “Int” in the following piece of program?

  1. main() : Int
  2. {
  3. {
  4. let x:Int←5 in{
  5. – do something
  6. };
  7. self;
  8. }
  9. };

Ans:Well I couldn't answer it concisely. However, follow the following steps you may get some idea.
1. Add keyword recognition IN=[iI][nN] and return the Symbol.IN in action part.
So that's the only rule. When the lexer find “m”, it doesn't know what to do and also “a”. Then it encounters “i”, great, I have potentially a match! Then it reads n (these reads are transparent to us) hmm, I have got “IN” and then it reads ”(“. Thus it continues and output “In” in “Int” and “IN” in “Int←5” and “IN” in “in” (hope you are not lost) and even “IN” in “something”. So there are 5 INs. Only one is valid.
FIX it. Why it returns “IN” while it encounter “Int”. Because you only have one rule. Next is to add another rule that specifies the typeid (begin with UPPER case alpha) and followed by alpha|numberic. It's like TYPEID=[A-Z]Somethinghere, and I specify taking no actions.

  1. <YYINIT>{TYPEID} {}.

So now when it reads Int, after read “In” of “Int”, lexer macthes both “IN” and “TypeID” rule. Longest match has higher precedence, right? SO it reads t and encounters “\n” or ”<“ in the case of “INt←5”. So I got one match that's TYPEID!! What should I do, {Here takes no actions, but you certainly need to output the typeid}. Now all “Int” will not be recognized as “IN” and thus we have only “main, in, something” that will output “IN”.
Again fix it, what's “main”, it is something like objectid that begins with small case and I specify a rule like OBJECTID=[a-z]{something here} and again takes no actions (you shouldn't). So now it reads “m”, oh, it matches the OBJECT rule, so it reads “a” “i” “n” and upon reading ”(“, great, I got OBJECTID. What is my action–NULL. So it does the same with “something”. Thus only “in” is recognized as “IN”.

Q3: Compare my lexer output with standard lexer output.
A3: So you need to obtain a standard version of output.

  1) goto bin/ directory. Remember you used coolc command? 
  Now use only lexer command, for the subsequent project, 
  you  may use parser semant... "lexer examples/*.cl >> std_output".
  2) do "diff my_output std_output"


Q2: Bring CoolLexer.lex to a working stage.
A2:

  1) Save the comments in CoolLexer.lex to elsewhere and delete them in CoolLexer.lex.
  2) add "package lexer;" on top of the CoolLexer.lex  
  3) also add  "import parser.TokenConstants;  
                import symbolHandling.AbstractTable; 
                import symbolHandling.AbstractSymbol; " 
     following the import that was already there. 
  4) add "%implements MyLexer" under  
                   %class CoolLexer 
                   %cup  
                   %line 
  5) add "public" before curr_lineno and set_filename function                
            


Q1: Error with “java lexer.JLex lexer/CoolLexer.lex”, bad macro definition line#
A1: The error is reporting that JLex doesn't recognize those comments in line #. These comments only serve as some instructions. So once you know the instructions, you must delete them in order to make your code work. Alternative is to place all the comments at the top of the lex file. The reason why these comments are placed in wrong locations is such statements as Don't modify the following three lines or begin your code here will make sense by doing so. You can make a copy of the file and delete all the comments in .lex file. The comments that are in %{ }% or %init{ }init% … don't bother JLex.

Questions on Homework 1

Question: How can I know whether I have successfully uploaded my work or not?
Answer: Method 1, Do a recheck out of the svn elsewhere. After that, dive into your directory and see if there exist your files
Method 2: backup your files. Then delete all your files. After that, run “svn up” see if these deleted files are restored.

Q0: What is the URL for the svn?
A0: You can check out the svn repo by issuing command “svn co svn+ssh:/ /*@svn.acad.ece.udel.edu/repos/cisc672_f10” and enter your account password (might need to enter twice)

Q1: Where should I run the cool program?

A1: Yankees or other Solaris Sparc machines. One can successfully compile the cool program and run through spim.


Q2: Instructions for getting started with the COOL compiler?

1) Cool binary files can be found in the root directory of the svn repos. Check the repo out according to the svn-handout available.
2) You may need to run “chmod 700 *” under directory (/cisc672_10f/)bin/ to make them executable.
3) If necessary (receiving error from running ./*), add the bin directory to PATH
4) Compile with the command coolc <filename> , this would create a file of the form filename.s .
5) Run the simulator by running the command spim and then you load the *.s file by using load “filename.s” command
6) More information can be found in the cool manual present on the class website http://www.cis.udel.edu/~pollock/672f10/index.html.


Q3: Why couldn't I run spim on hoek/ren eecis machines, although research accounts can get access to them?

A3: Spim can be successfully run on Solaris Sparc machines. Stimpy, mudskipper, and yankees(academic) machines are of this kind.

Q4: When I type the command
svn co svn:/ / anonymous@svn.acad.ece.udel.edu/repos/cisc672_f10
but it shows that something wrong: svn: No repository found in 'svn:anonymous@svn.acad.ece.udel.edu/repos/cisc672_f10'
A4: You are probably checking out svn from outside svn.acad.ece.udel.edu machine. A simple change, type the following command instead.
svn co svn+ssh:/ / you@svn.acad.ece.udel.edu/repos/cisc672_f10

Q5: Can I use windows for the project?
A5: You can work on windows after the cool programing (PA1). As to cool programming, spim needs sparc architecture support and you need to first log on to yankees/stimpy/mudskipper. And find a working space to check out the repos. Goto A2.

Q6: How do I submit my work?
A6: Suppose you are to upload your cool file named “cool.cl”. Put this file under your working directory (e.g. wwang/). Make sure you run “svn add cool.cl”. After executing this command, cool.cl file is under svn control. You can edit it if you want. Once you think it is ready to submit the work. Issue the command “svn ci” (abbr. for svn commit). Input some log info if you wish to.

Q7:COOLC command not found
A7: You need to make coolc files as well as others like semant/cgen/spim executable by doing chmod 755 *