Comp 524 – Assignment 0:
Hello to Programming Language Tools
Date Assigned: August 16, 2020
Early Completion Date: Friday, August 21, 2020 (+5% extra credit)
Copyright By PowCoder代写 加微信 powcoder
Completion Date: Tuesday, August 25, 2020
The goal of this assignment is to familiarize you with required and optional tools you need to during this course. The required tools are a Java 10 compiler and virtual machine, and Prolog, SML, and Lisp interpreters. The recommended optional tools are Eclipse, LocalChecks, and UNC Checkstyle (also called Hermes), for editing programs in the four languages, checking runtime behavior of programs, and checking source structure of programs, respectively. As mentioned in the last part of the assignment, the use of Hermes will also help you do extra credit that is of the same weight as the Class Q/A diary and also involves work throughout the semester.
You will create four projects, one for each of the four languages above. Each project will have a separate Sakai (and possibly Gradescope) submission. Since Eclipse projects and our grading of them are language-specific, for each language, you will make a separate submission. This assignment thus, maps to four different Sakai (and possibly Gradescope) assignments (Assignment0_1, Assignment0_2, Assignment0_3, Assignment0_4), all with the same due date.
The due date seems very conservative at this time and accounts for the fact that tools installation can be troublesome. Expect the next assignment to be given before the deadline for this assignment, with a deadline close to it. When assignments are given depends on when we cover the material for them in class, which depends on how much interaction we have in class.
Class Library
In the shared google folder:
Downloads/Comp524All.jar (will be updated throughout the semester.)
Reference Material (Instructor-Created)
Installing JDK, Eclipse, Project Libraries: PowerPoint PDF
In the shared google folder:
InstallationDocs/INSTALLING CLISP.pptx
InstallationDocs /installing sml and prolog.pptx
Reference Material (General Web-Resources)
Installing CLisp
Eclipse Dandelion Plugin
Installing SWI-Prolog
Eclipse Prolog Plugin
Installing SML-Site-1
Installing SML-Site 2
Installing Eclipse ML Plug-In
Task 0: Java/Eclipse Installation
1. Install JDK-10.0.2 (Described in Installing JDK, Eclipse, Project Libraries: PowerPoint PDF) on your computer. All assignments will use this JDK.
2. (Optional but recommended): Install Eclipse (Described in Installing JDK, Eclipse, Project Libraries: PowerPoint PDF). ProDT may require the following: IDE for Eclipse Committers, Version: Photon Release (4.8.0), Build id: 20180619-1200,Here is a link to Photon: https://www.eclipse.org/downloads/packages/release/photon/r
Task 1: Java Project and Class Library
Java Project Structure: Create a Java Eclipse project structure (a project directory with an src folder for source files and bin directory for class files.).
When creating a project, uncheck the box that asks for creation of the module-info file. If your project has been created with such a file, delete it.
Class library: Add the library Comp524All.jar (Available In the shared google folder: Downloads/Comp524All.jar). Instructions on how to add libraries to Eclipse projects are in (Installing JDK, Eclipse, Project Libraries: PowerPoint PDF). Add it to the classpath and not to the modulepath.
Task 2: Class Registry
Create a single class (in an appropriate package) in the Java project that implements the following interface defined in the shared library:
gradingTools.comp524f20.assignment0_1.GreetingClassRegistry
For now, return the null value in the getter required by the interface. Eclipse will automatically generate such a method if you ask it to fix the error of unimplemented interface methods.
Our grader will look in your project for a class implementing this interface. If such a class does not exist or more than one such class implements the interface, it will fail, and no other aspect of your assignment will be graded. So it is important to get this simple requirement right.
Task 3: Localchecks Runner (optional)
Create a class with the following code (the name of the class does not matter).
import gradingTools.comp524f20.assignment0_1.F20Assignment0_1Suite;
import trace.grader.basics.GraderBasicsTraceUtility;
import util.trace.Tracer;
public class RunF20A0_1Tests {
public static void main(String[] args) {
// the following two lines should be uncommented if you do not understand why your tests fails
// Tracer.showInfo(true);
// GraderBasicsTraceUtility.setBufferTracedMessages(false);
F20Assignment0_1Suite.main(args);
The main method of this class executes the main method of a test suite class we provide. We will call such a class a LocalChecks runner. You will create such a class for each assignment. Here you are running the main method in the following test suite:
gradingTools.comp524f20.assignment0_1.F20Assignment0_1Suite
In general, the test suite for Assignment
gradingtools.Comp524
At this point you should see the following user-interface:
As you can see, each displayed check has a name that tries to explain its function. You can hover over the name of a check to see what it does. You can double click on any test to check it individually, or execute the AGradableJUnitTopLevelSuite🡪Test All menu item to test all checks.
This is what should happen if you double click on GreetingClassRegistryProvided.
This is what happens if you execute the AGradableJUnitTopLevelSuite.Test All:
As you see here, a test turns green if it finds no problems, and a shade of red if it does find problems.
If the error message in the GUI is not clear enough, look at the console output. If this too is not clear, uncomment the two lines in the main method above to enable tracing, and look again at the console output. If you are still unclear, post the output on Piazza. It is important to give the trace in any message about confusing test messages.
The errors above of course are caused by returning a null main class in the registry and not having a main class. Running tests before you have written code to satisfy them is called test-first or test-driven programming.
Create another class, and for now, give it the name, cls, which has been deliberately chosen to be a non-mnemonic name that does not follow Java conventions. Do not put any method in it. Return its class object as the return value of the getter in the greeting class registry you defined above. The class object for a class named C is C.class. Thus, your class registry getter should now be:
public Class> getGreetingMain() {
return cls.class;
Run your LocalChecks runner to get the following user-interface:
The console provides a better reason for the third test failure:
Error: Main method not found in class …, please define the main method as:
public static void main(String[] args)
Ideally, such a violation of source-code requirements should have been given while editing code which requires a source code checker. Such a checker should also, ideally, catch violations of required code style such as not following Java class conventions and creation of non-mnemonic names. Let us leave these source code violations in our code to see how such a tool may work.
Task 3: UNC Checkstyle (optional)
Perhaps the most famous checker of Java source code is the extensible Checkstyle plugin or extension to Eclipse. UNC Checkstyle is an extension of it. supports only application-independent checks such as following of Java class conventions.UNC Checkstyle extends the application-independent checks and also supports application-dependent checks through class tags as we will see below
The requirements of a Java file to be checked are defined in a checkstyle file associated with the Eclipse Java project in which the file is located. Each assignment will have a separate checkstyle requirement file available here
In the shared google folder:
F20/CheckStyleFiles (will be constantly updated)
The name of the file indicates the associated assignment. For example, the checkstyle file for this assignment is:
unc_checks_524_A0_1.xml
Download the file to your computer. We will call it the assignment check configuration.
The next step is to extend your Eclipse with the plugin. Slides on how to install it, the data it mines and logs, and how to connect a project with an assignment configuration file are accessible from:
Checkstyle with UNC Checks : Install and Use
PowerPoint
These instructions, in fact, take you to the following instructions for installing the difficulty plugin:
Difficulty Plugin
PowerPoint
To reduce the installation effort, we have combined all relevant plugins into a single plugin, called the Hermes plugin which forms both the Checkstyle plugin and the Difficulty plugin. The plugin performs source checks, tries to detect programming difficulties, and will hopefully soon, also provide help within the Eclipse environment. We will focus here on the source checks aspect of it. The last task addresses the difficulty aspects.
Study the instructions in the difficulty plugin slides on how to install and uninstall Hermes. Install the plugin and then follow the instructions in the Checkstyle slides on how to connect a project to a configuration file. Connect the Java project you just created to the configuration file you downloaded.
If all has gone well with your installation, you should be able to right click on the file cls.java and run Checkstyle🡪Check Code with Checkstyle.
When you have more than one file to check in a project, you should right click on the project, and run Checkstyle🡪Check Code with Checkstyle.
You should see the source code annotated with some yellow highlights and magnifying glass marks in the margins.
You can hover over the magnifying glass marks to see the associated messages:
You see that Checkstyle is complaining about the name of your class and also the fact that the main method is missing.
How did it know that a main method was required in this class? This information is in the configuration file:
This is FYI, you do not have to understand this syntax. But it is important to know that somehow UNC Checkstyle needs to know the purpose of each file it is checking to provide file-specific checks. This is a UNC Checkstyle check called ExpectedSignatures and says that a warning should be given if a class with the tag @GreetingMain does not have a method with the following signature:
main:String[]->void
How did the plugin know that class cls has the tag GreetingMain? It is integrated with localchecks. When you ran the local check GreetingClassRegistryProvided, it generated a file class ClassRegistry.csv in your project whose contents have map each class name to the associated tag:
This file is read by the plugin to map your classes to the tags.
This means if you change class names, you should rerun the class registry check – the local check whose name contains the string ClassRegistry.
Rename cls to the better name, Hello (Right click on the class name in the left explorer window and enter ALT-SHIFT-R). Run the class registry check. The class registry file should now be updated:
greeting.Hello,GreetingMain
Run Checkstyle again on the file. Now you see both purple and yellow marks:
package greeting;
public class Hello {
public static void main(String[] args) {
The purple marks are information messages, they are not problems. Hovering over the one shown above tells us that Checkstyle has mapped this class to the tag @GreetingMain. This is good, we have fulfilled at least the need for a main class.
We no longer get an error saying that the main method is missing. But we do get the message about a missing println() in this method:
Checkstyle messages can also be seen in the Problems tab.
This tab reports problems reported both by the Java compiler and also (UNC) Checkstyle.
If you add the following two prints and make args final in the Hello class created in the optional steps above, all of your yellow highlights should go away when running Checkstyle.
package greeting;
public class Hello {
public static void main(final String[] args) {
System.out.println(“Hello World”);
System.out.println(“Goodbye World”);
The remaining purple highlights tell us that this class has correctly been tagged, In general informational messages are good!
If you now run LocalChecks, you should get full points!
We hope to create for each Java assignment such source-code checks to help identify the source-code requirements.
Run the main class. Create a screenshot of the console after you run the main class and save it in the Java project folder.
Task 4: Java Greeting
If you did not perform the optional task 3:
Create a main class that prints the strings containing the text “ello” and “oodbye” in two different lines. Return the class object for this main class in the getter of your class registry. The class object for class C is C.class.
Create a screenshot (not a text file) of the console after you run the main class and save it in the Java project folder. All console screenshots about a program ram should include the entire console contents after the run including any user input.
Task 5: Assignment 0-1 Submission
Zip the entire folder including (src, bin, logs, and the screen dump file) and submit it to Sakai and Gradescope under the appropriate assignment names: Assignment 0-1 and G_Assignment0_1. In your submissions, the project folder name does not matter and we can handle zips with and without a spurious nesting of the top folder. Here is a view of a correctly formatted zip file.
Do not reorganize the folder before submission. For instance, some students have submitted a folder containing the Logs folder and another folder that contains the src and bin folder. Just submit the folder as is as shown above. While we can deal with only an src folder, it is more efficient if you submit the entire project folder.
We will run both LocalChecks and UNC Checkstyle to determine your final grade. If you have no Checkstyle warnings and LocalChecks errors, you should get full points on the automatically computed part of your grade. You may get full points even if you have some Checkstyle warnings, depending on the warning. There will be clearly articulated style and runtime requirements for each assignment which you can check manually if you do not want to use LocalChecks and/or Checkstyle. For this submission, the requirements are the two required tasks. There are no style requirements for it though you are encouraged to use good names.
In general, the Sakai submission will also allow additional manual grading of your submission. For assignments such as this one in which we expect no additional manual grading, we may be able to support a Gradescope submission that is completely automatically graded. We will let you know if and when this facility is available.
Task 6: Install Prolog
Install a Prolog interpreter on your computer based on the reference material above.
Task 7: Prolog Greeting
Create a Prolog project/folder and to it the Prolog file named Greeting.pl. In the case of Java, you had flexibility in how we named the class and hence the file that contained the greeting code. This is because the class registry told the grader the name of the file. There is no equivalent of a class registry in other languages, so it is important to use the file name required. Otherwise our grader will give you no points.
Add the following text to this file, which defines a Prolog greeting rule:
greeting() :-
write(‘hello\n’), write(‘goodbye\n’).
Ask the interpreter to load this file using the command line, ProDT or some other system.
Once the file has been loaded, enter the following two lines on the console to “invoke” the rule and then exit the interpreter:
greeting().
Verify that strings hello and goodbye are output in response to the rule invocation.
Take a screenshot of this console input and output and put it in the Prolog project.
Task 9: Prolog LocalChecks (Optional)
Verify that you can execute swipl from the command line, that is, it is in your PATH.
LocalChecks are written in Java, so it is not possible to run the ones for Prolog from our Prolog project. This will be the case for other non-Java languages in which we code, Lisp and SML. So we will create a Java runner and tell it the name of our Prolog project location.
In the Java project you created, create a Java class whose contents are of the form shown below:
import gradingTools.comp524f20.assignment0_2.F20Assignment0_2Suite;
import trace.grader.basics.GraderBasicsTraceUtility;
import util.trace.Tracer;
public class RunF20A0_2Tests {
static final String PROJECT_LOCATION = “D:/dewan_backup/Java/PLProjs/PLProjsProlog”;
public static void main (String[] args) {
// Tracer.showInfo(true);
// GraderBasicsTraceUtility.setBufferTracedMessages(false);
F20Assignment0_2Suite.setProjectLocation(PROJECT_LOCATION);
F20Assignment0_2Suite.main(args);
Right click on your Prolog project. Go to Properties🡪Resource. Copy the folder name after Location: Assign it to the PROJECT_LOCATION string constant above.
F20Assignment0_2Suite.setProjectLocation(PROJECT_LOCATION);
tells LocalChecks that the project to be graded is not the one from which this runner class is called. Instead, it is, PROJECT_LOCATION.
If you now execute this runner, you should see the checks for the Prolog project and not the Java project from which you ran this class. Double clicking on the only test in this suite should make it run successfully.
The Mac implementation of Java and Eclipse seems to be inconsistent with the specifications. So you might get a NotGradableException. If so, do the following.
On the command line, execute, which swipl.
$ which swipl
/d/Program Files/swipl/bin/swipl
Here, /d/Program Files/swipl/bin/swipl, is the full name of swipl.
Import the following class in the runner:
import grader.basics.execution.prolog.PrologCommandGeneratorSelector;
Now in your runner main method, before you execute the main method of the suite execute the following call, passing to setUserBinary the full name of swipl:
PrologCommandGeneratorSelector.getCommandGenerator().
setUserBinary(
Task 9: Assignment 0-2 Submission
Zip the entire Prolog project folder including the screenshot file and submit it to Sakai and Gradescope under the appropriate assignment names: Assignment 0-2 and G_Assignment_0_2..
Task 10: Install SML
Install an SML interpreter (and compiler) on your computer based on the reference material above.
Task 11: SML Greeting
Create an SML project/folder with the sml file Greeting.sml.
Add the following text to this file, which defines the greeting function:
fun greeting() = print (“hello\ngoodbye\n”);
Ask the interpreter to load this file using the command line, Eclipse SML plugin or some other system.
Once the file has been loaded, enter the following two lines on the console to execute the function and exit from the interpreter:
greeting();
OS.Process.exit(OS.Process.success);
Verify that strings hello and goodbye are output in response to the function call.
Take a screenshot of this console input and output and put it in the SML project folder.
Task 13: SML LocalChecks (Optional)
Verify that you can execute sml from the command line, that is, it is in your PATH.
Again, in the Java project you created, create a runner for the SML project along the lines of the runner for the Prolog project. The assignment suite