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.
Submission reference: IN3403
Not related to the assignment but when will we get any of our marks for the in class tests or A3?
The A3 marks should be available within the next week. You will need to ask Mark about the ICTs.
Keywords: assign3
Submission reference: IN3394
my parser outputs this the n testing it with example.dsl: The first token is: KEYWORD INT ok ok is this compleatly incorrect? I have restarted multiple times and have always ended up with this output
If you have completed the assignment, then it should just print "ok" as in the spec. Just delete the other output that I put in the starter code.
Keywords: assign4
Submission reference: IN3391
when I run the assignment4 code with the example.dsl the outputs are The first token is: KEYWORD INT OK. Is it the right output?
It depends what you mean. If you are parsing the whole of the example.dsl file then the output should just be ok
. There should not be any other debugging info printed. If you haven't implemented anything yet then the output will be
The first token is: KEYWORD INT error
Keywords: assign4
Submission reference: IN3381
assignment ::= IDENTIFIER ':=' expression ;what exactly does this statement mean ?
IDENTIFIER ':=' expression ;
this is clear and is equivalent to N1 := 6;
but i'm confused with assignment ::= IDENTIFIER
The rule means that an assignment (statement) is defined as consisting of an IDENTIFIER (e.g., sum, price, x, etc.) followed by ':=' (an assignment symbol, like '=' in Java) followed by an expression, where expression is defined later in the grammar.
In terms of writing a parser for it, just follow the rules outlined in the parsing lecture/slides: check that the current token is an identifier, then check that the next token is the assignment symbol, then check that what follows is an expression (by calling the parseExpression) method.
Keywords: assign4
Submission reference: IN3379
What is the difference between these symbols := ::=
The spec say, The notation ::= means 'is defined as'
. It is part of the grammar notation. The spec also says:
In the grammar be careful to distinguish between those characters not enclosed between single-quote characters (e.g., ::= and ;) and those that look similar but are enclosed (e.g., ':=' and ';').So, in the following:
assignment ::= IDENTIFIER ':=' expression ;
:=
is a symbol found in the input.
Keywords: assign4
Submission reference: IN3377
I'm following the suggested implementation steps in the spec.I was just wondering whether in step 4 we are meant to create a new method or should that be implemented in parsedeclaration as I'm confused
In the parseDeclaration method, when you have IDENTIFIER as a token you should then access the symbol table. Check first whether there is already an entry for it. If there is, then that is an error. If there isn't then add it to the table.
Keywords: assign4
Submission reference: IN3375
how would i know if a symbol is a comma or semicolon and I cant use strings?
I am not sure what, 'I cant use strings' means but if you know that a token is a SYMBOL you can call the getSymbol method of the Tokenizer and check whether the symbol is ";" or ",".
Keywords: assign4
Submission reference: IN3371
what should the output be to the example dsl file you have provided?
It's a valid program, so the output should be:
ok
Keywords: assign4
Submission reference: IN3361
For A4 what java files provided do we actually need to modify? is it just the parser or do we need to modify the other java files
You should only need to add code to the Parser class, but feel free to modify the others if you feel you need to, or add additional classes similarly.
Keywords: assign4
Submission reference: IN3360
When i translate instructions which include 3 parts(one opcode, one reg, one number), my reg translations occur at the end of the translation of the 8 bit string for some reason, while the padding is inbetween the opcode and reg. For example, JGT A,4 JLT D,39 translate to
> 01010001 00000100 01100010 00100111 code deleted
You cannot assume that every instruction can be handled in the same way. Look at the encoding of each in the spec and group together the translations of those with similar structure.
The obvious conclusion is that you must be outputting the padding before the register encoding, which is clear from the order in which you do things in the method. So the solution is to print the register encoding before the padding for the instructions in which it is currently wrong.
Keywords: assign3
Submission reference: IN3358
when i run my program on raptor command line with java Main prog.mal it works fine, but when i use java -cp . Main prog.mal like it says on the brief, i get the error Unrecognized option: -cp. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Is this fine as my program still runs.
If your program runs and gives the correct answers that's fine; I will figure it out when marking.
Submission reference: IN3357
Submission reference: IN3355 Im not entirely sure where to be moving/removing the output.println(). Ive tried removing them from
code deletedand also adding output.println() to below this snippet like this.
code deletedbut neither works. Is it more than just moving the output.println(), or am i placing it in the wrong spots?
It's about recognising that some instructions require two 8-bit outputs and so the 4-bits of opcode for the first of the pair need padding out with zeros to 8 bits. You have to do that for some instructions and not others. You can tell which you need to do it for from the assignment brief.
Keywords: assign3
Submission reference: IN3356
Cant find the MAL Spec, I had the MAL spec on my laptop however as im on another desktop right now i tried to retrieve the spec but couldnt
It is on the Moodle page in the assignment brief.
Submission reference: IN3355
Ive got just one problem, my assembler correctly translates, except for ensuring that for instructions that include numbers, the opcodes and reg part of the translation doesnt correctly translate to 8 bit string. It only translates the opcode and reg but doesnt pad the rest of the string with 0s if it needs to. For example the instructions, JEQ A,125 and JMP 16, translate to
011101 01111101 0100 00010000 code deleted
It's because you call output.println before adding the padding:
if (segment.length > 1) { if (isNumeric(segment[1])) { output.println();
Submission reference: IN3353
Apologies, here is the code:
code deletedCould you tell me why the first line still produces a 16 character long line except for all other opcodes.
It is simply that you have concatenated the binaryOpcode string and binaryOperand string together without a newline between them:
String binaryInstruction = binaryOpcode + binaryOperand;
Keywords: assign3
Submission reference: IN3352
When the program is ran, the translation of the first line is always 16 characters long but the other opcodes are translated in 8 characters, how can I fix the first line issue.
Add some debugging information to your code. I have no way of knowing why this is without seeing your code, but you should be able to work the problem out by looking at what the first instruction is in the input file and then tracing how that is translated in your code.
Keywords: assign3
Submission reference: IN3351
my assembler can correctly translate numeric constants, but only if the constant is the fourth word in the instruction. How can I change my code so that it can also translate when the numeric constant is the second or third word in the instruction? For example, I can successfully translate instructions like ADD A D 5, and JLT D,A 39, but not LOADN 127 or JEQ A,125.
code deleted
Don't try to translate all instructions in the same way. Have separate cases for the instructions that take either one or two operands.
Keywords: assign3
Submission reference: IN3350
Regarding Question 10 (2023), i have created the following code, but it is not working at all. For example when trying to translate LOADN 127, all it does it translate 0000
code deleted
I suggest that you add some further debugging to your code to make sure that: a) that piece of code is being executed; and b) what the values of the number and numericConstant variables are. I suspect they are not what you think they are.
Submission reference: IN3349
Does the Main.java file need to be edited or is it just the Assembler.java. I'm not to sure if the Main.java has to call the Assembler.
The Main class already calls the Assembler. You don't need to change anything in Main.
Keywords: assign3
Submission reference: IN3348
I have managed to get my assembler working for translating opcodes and regs, but I'm unsure of how to handle numeric constants for my code.
code deleted
Try a Google search for 'java convert int to binary string with leading zeros'
Keywords: assign3
Referrers: Question 12 (2023)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |