Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CO5570 Anonymous Questions and Answers Page (2021, 55-74) XML CO5570 Anonymous Questions and Answers This page lists the various questions and answers. To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers. We have taken the liberty of making some minor typographical corrections to some of the questions as originally put. Although most of the questions here will have been submitted anonymously, this page also serves to answer some questions of general interest to those on the course. Question 74: Submission reference: IN2391 im not sure what the difference is between the rom label and ram. Rom addresses go after all the RAM addresses in memory? Answer 74: For the assignment you just have to appreciate that those defined in the .dec section are RAM labels and those used as labels are ROM labels. Where they go is irrelevant. Question 73: Submission reference: IN2390 hello david, I was just a bit confused on the location of the shack file that your gonna test, I mean do we have to write an assembler that assembles a shack file from anywhere from the computer or is there a certain directory for the shack file? sorry if this sounds complicated but its been circling through my mind Answer 73: The location can be anywhere. So the assembler needs to separate the name of the file from its containing folder/directory so that the translated version ends up in the same folder/directory with the .asm suffix. Referrers: Question 75 (2021) , Question 76 (2021) Question 72: Submission reference: IN2378 if i have an opcode with too many operands do i produce the error and not process it even if i have the first opcode(if needed) for example -INC 13 -ADDD 13 14 Answer 72: Yes, don't attempt to translate anything with an error in it. Question 71: Submission reference: IN2376 are labels case sensitive ? Answer 71: Yes. Keywords: labels , assign3 Question 70: Submission reference: IN2368 just wanted to double check im doing illegal character error on label names that arent a number, letter or underscore ? Answer 70: Sounds fine. Question 69: Submission reference: IN2362 I've just come back from holiday and i'm trying to attempt the assignment, I just don't know how to start. is there any tips or advice on how to start Answer 69: Which one of the two concurrent assignments? In both cases, make sure that you have read the brief several times over, and looked over the questions people have already asked. Then aim to have a specific question about some aspect that you don't understand. Question 68: Submission reference: IN2355 I am unsure where to start for assign3, I have read the brief, would I start on raptor or possibly the software from the website? Answer 68: You don't have to start on raptor. You can use whatever IDE you want to develop the code. By all means use the very small piece of code I have provided as your starting point. I recommend browsing the anonymous Q&A pages to check out some of the clarifications that others have sought. Question 67: Submission reference: IN2333 Hi, for the usage error it states "Usage: sham file.shk" does this mean that if we used java as an example it would have to run by using java sham file.shk Answer 67: No, that doesn't mandate the way the command is run, just the error message; 'sham' stands for Shack Assembler. Question 66: Submission reference: IN2332 Hi, I hope the holidays treated you well and just a quick one: All the errors in the Labels used Incorrectly section end with a full stop but the rest do not do this. Does this mean that we must put full stops at the end of the errors which have them? Just want to make sure I don't lose marks over something silly! Many thanks :) Answer 66: If you stick to the format of each error as shown in the brief you will be on safe ground, even if the formatting is inconsistent in the brief. Question 65: Submission reference: IN2322 Hi David, Will we be getting any Boaz example files at any point or not? Answer 65: Assume not. You should be able to construct your own fairly easily from the examples in the brief and the grammar. Keywords: assign4 Question 64: Submission reference: IN2292 Hi David, could you please give an example of a statement with the unaryOp '-' for Boaz, im kind of unsure as to what it does Answer 64: x := -x; Keywords: assign4 , unaryOp Question 63: Submission reference: IN2289 So just a follow up on Question 61 (2021): sum+num*2 is valid but if we have more than one inner expression we need parentheses? so sum+num*2+2 is not valid? Answer 63: No, they are both valid and - in the absence of parentheses - simply parse as a sequence of term separated by binaryOp because you can have any number of binaryOp term elements following the initial term according to the rule: expression ::= term { binaryOp term } ; Think while loop for the 0-or-more concept. Keywords: assign4 , expression Question 62: Submission reference: IN2288 Hi David, Im a bit confused as to the grammar of the expression bit in assignment 4, in Boaz if we have a left recursive call to an expression by the rules of the grammar we should expect the inner expression to be between brackets '(' expression ')' but in your example code you have sum:=sum+num*2; which doesn't contain any brackets, could you please elaborate? Answer 62: The following expression: sum+num*2 would parse as: expression -> term binaryop term binaryop term -> IDENTIFIER '+' IDENTIFIER '*' INT_CONST because the rule for expression allows 0 or more binaryop term elements to following the initial term. If there were a pair of parentheses, e.g., (sum+num)*2 then that would parse as: expression -> term binaryop term -> '(' expression ')' binaryop term -> '(' term binaryop term ')' binaryop term -> '(' IDENTIFIER '+' IDENTIFIER ')' binaryop term -> '(' IDENTIFIER '+' IDENTIFIER ')' '*' INT_CONST Keywords: assign4 , expression Question 61: Submission reference: IN2282 Hello David Barnes, for assignment 3, what is the difference between "ADDD" and "ANDD", looking at their hack translations, I'm confused what the difference between: ADDD: "D = D + A" and ANDD: "D = D & A" My second question is how does the "ORD" operator work in terms of functionality? How does it decide between the 2 operators? Would it work like the "or" operator in java "||" where it will return either true or false depending if at least 1 of the 2 operands holds true? If so, how would you expect someone to compute it semantically for this assignment? Answer 61: The nice thing about this assignment is that you don't actually need to understand how any of the operations actually work in practice. It is purely a textual translation operation. Whatever you find in the Shack source gets mapped to the equivalent Hack source. So, in terms of what you need to do, the only difference between ADDD and ANDD is that one outputs a '+' character and the other outputs a '&' character. The semantic difference is irrelevant. Similarly, treat ORD as just a textual mapping because the runtime semantics have no bearing on the translation. If you find an ORD instruction in the Shack source, output the equivalent Hack version that is shown in the assignment brief. Referrers: Question 63 (2021) Question 60: Submission reference: IN2280 Hi David, for assignment 4 should a Boaz program containing: program test compile successfully without a begin and end? Answer 60: No, because this grammar rule: program ::= PROGRAM IDENTIFIER varDecs BEGIN statements END ; says that the BEGIN and END have to be there. However, varDecs and statements both allow those parts to be empty (0 or more), so the minimal program would be: program test begin end That is the example suggested under point 2 of the section on Suggested order of implementation. Keywords: assign4 Question 59: Submission reference: IN2259 In the assigment 4 brief I can't see anywhere that mentions about declaring identifiers with the same name. Technically then, the following boaz code should be valid: program example char a; int a; int b, b; begin print a + b; end Is this correct? Answer 59: Within the constraints of the limited type checking requirements of the assignment, you are correct that that program is valid. Obviously, for a full type checker it would not be, but you should not report any errors for this particular example. One issue you have highlighted is that a variable could potentially be defined to have different types, and the impact that could have on the type checking that is required. You are welcome to decide for yourself whether the first or last declaration type takes precedence. However, I will not be testing your programs with any examples like this one. Keywords: assign4 , type-checking Question 58: Submission reference: IN2247 The code: program example char ch; begin while ch + !"z" do od; end is valid by the grammar rules, but semantically it shouldn't make sense right? But at the same time the rules for semantics are that if it contains any boolean operator (including '!') then its counted as a boolean and therefore valid for a while statement. Is this correct? Thanks Answer 58: Yes, completely correct. Question 57: Submission reference: IN2244 Sorry if it is a silly question, but which of the below should result in an error and which should result in ok?: Running the program with no boaz file argument passed in Running the program with a file of the wrong extension passed in Running the program with a boaz file that doesn't exist in the current directory Running the program on a correct boaz file that doesn't contain anything at all in it Thanks Answer 57: All would be errors. Keywords: assign4 Question 56: Submission reference: IN2230 For a previous Question 44 (2021), you wrote that if num/3!=0&ch!="y"then ch:=ch+1;fi is a valid if statement, but shouldn't there be a ';' at the end of 'fi' for it to be valid? So, 'fi;' Thanks Answer 56: The definition of ifStatement does not, itself, include a semicolon, but each statement is followed by a semicolon via the statements rule. It is important to make that distinction in the parser and not 'consume' the semicolon as part of parsing a particular statement. Keywords: assign4 Question 55: Submission reference: IN2228 for assignment 4 should there be spaces in the boaz code for certain statements like sum+num*2 or ifsum+num=4;thenprintsum;fi; Answer 55: See my answer to Question 44 (2021). Keywords: assign4 , spaces This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Last modified Thu Feb 10 09:13:46 2022 This document is maintained by David Barnes, to whom any comments and corrections should be addressed.