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: IN3445
Would this be full marks?
code deleted
I can't assess your work ahead of the deadline. You should aim to test it thoroughly to increase your confidence that it works as it should.
Keywords: assign4
Submission reference: IN3444
i have not yet implemented conditional statements or loops in my parser yet. However when i test the dsl test file on moodle(containing ifs, and while) my parser is still returning ok? is this meant to happen even if i havent implemented certain features yet.
I have no way of knowing for sure without seeing your code. However, if there are tokens in the DSL file that your parser can't recognise then I would expect it to output error.
Keywords: assign4
Submission reference: IN3442
is the assignment symbol meant to be ::= or := because in the grammar it shows
program ::= declarations statements;but then in the dsl test file it uses
sum := 0; num := 1;So should there be two colons or one?
See my answer to Question 32 (2023). You must read the whole of the assignment brief, even though the deadline is really close.
Keywords: assign4
Submission reference: IN3440
Submission reference: IN3439 I am struggling to see what is causing the issue elsewhere in my class, these are the two methods that involve the parseAssingment() method so i assume there must be an issue in here.
code deleted
I recommend that you put println debugging statements in to work out where the failure is occurring. I can't debug it from just snippets of code, you will have to be systematic about it yourself.
Are you declaring identifiers correctly?
This isn't the problem, but I don't see why you use expectSymbol for the semicolon but not for the assignment symbol.
Your while-loop in parseStatements should be conditional on parseStatement rather than currentToken.
Submission reference: IN3439
Hello, i am trying to add the feature of the ::=. This is my method for it,
code deletedBut when trying to it works using a file containing,
int x; x := 10;it returns error, when it should be ok.
What you are parsing there is an assignment, so the method should be called parseAssignment. You haven't checked that an expression is actually parsed successfully, as it is not optional. Otherwise, the logic looks ok so some other part of the parsing process must be at fault.
Keywords: assign4
Submission reference: IN3438
is this somewhat a good start to implementing the parseExpression method ? and would I need to also consider IF, ELSE and WHILE statements for expressions?
private boolean parseExpression(){ if (parseDeclaration()){ if (expectSymbol(Symbol.ADD) || expectSymbol(Symbol.SUBTRACT)|| expectSymbol(Symbol.EQUAL_TO) || expectSymbol(Symbol.NOT_EQUAL_TO)||expectSymbol(Symbol.LESS_THAN)||expectSy mbol(Symbol.MORE_THAN)||expectSymbol(Symbol.LESS_THAN_EQUAL_TO)||expectSymb ol(Symbol.MORE_THAN_EQUAL_TO)){ getNextToken(); if (!parseDeclaration()){ throw new SyntaxException("error"); } } return true; } return false; }
That's not a good start at all and I am not sure how you came up with that as an idea. For instance, there is no reason to think that parsing an expression involves parsing a declaration. Please take another look at the grammar rule for an expression, which involves terms and a binaryOp.
IF, WHILE, etc. are part of statements, so they also have no role in parsing expressions.
It looks like you need to go back to the lecture that covered how to convert a grammar to a parser and start again there.
Keywords: assign4
Submission reference: IN3437
is this code correct for parsing statements, terms and expressions.
code deleted
No, it is quite a long way off. For instance, if there is more than one statement, parseStatements returns false. It is incorrect in most of the methods you have written. Make sure you refer to the slides on parsing and how to turn a grammar into parsing code.
Even though you are close to the deadline, you need to write the code in small steps and test it systematically rather than trying to write the whole thing in one go.
Keywords: assign4
Submission reference: IN3435
I've just read through the brief to double check my question, but in 'The Parser Class' section the following is said:
"If they detect an error – such as a missing expression after the token PRINT – then they should throw an exception, as illustrated in the example method. The SyntaxException class has been provided for you."
Do we specifically NEED to throw exceptions if we find an error? Will we actually lose marks for just returning False?
I notice in Main.java the code simply catches a SyntaxException and prints error anyway, so does it particularly matter if we throw an error? For example, if an attempt to declare an identifier twice was made, would it matter if I just return False (as in a deduction of marks), or would I instead need to throw said SyntaxException.
You don't have to throw an exception. What matters is whether either ok
or error
is printed.
Keywords: assign4
Submission reference: IN3434
do we upload a zip of the whole folder? so including the parser the main, tokenizer ,symbol table , keyword, SyntaxException etc or just the parser and main?
Yes, all your code so that it is a complete program.
Keywords: assign4
Submission reference: IN3432
Is this test meant to return error. Test this with a single DSL file that contains multiple declarations, such as: int x; int x,y,z;
You should be able to check that from the grammar. Is it possible to have more than one declaration? Is it ok to have no statements?
Keywords: assign4
Submission reference: IN3424
Im the process of creating the symbol table in my parse identifiers method. Before i created my symbol table, my method looked like this, and it worked for single declaration.
code deletedBut my new methods make the parser return java.lang.NullPointerException error.
code deleted
That's probably because the expectToken method moves on to the next token if it matches an IDENTIFIER, so when you ask the Tokenizer for the identifier immediately afterward, it's already gone.
Keywords: assign4
Submission reference: IN3423
Would you give declarations in the test like this? int a := 3; or is declaring a variable completely separate from initializing it in this lang?
Reading and understanding the grammar will tell you the answer to that.
What can you write in a declaration? Can you write an assignment in it? Check the grammar.
Keywords: assign4
Submission reference: IN3419
Submission reference: IN3418 I see that IDENTIFIER is of type Token, does that mean my method would start like this and i would need to create an expectToken method?
code deleted
Yes, something like that.
Keywords: assign4
Submission reference: IN3418
I am trying to write the method headers for parseDeclaration and parseIdentifiers. I have followed the suggestions for parseDeclaration but for parseIdentifiers i am getting errors such as Cannot resolve symbol 'IDENTIFIER'. Here are my methods,
code deleted
IDENTIFIER is not a Keyword. Find out what type it is by looking in the other source files provided.
Keywords: assign4
Submission reference: IN3415
Leading onto the previous assertions question, I found that out when I got a null point exception in the tokenizers decodeNextToken method when it passed by the assertion and ran into the nullpoint error.
No question asked. See my answer to the previous question.
Submission reference: IN3414
Why do my assertions not do anything in the IntelliJ IDE? I made a method specifically to test if assertions work and it kept running as if it doesnt.
private void assertFalse(){assert false;} public boolean parseProgram() { assertFalse(); }
Assertions are off by default. You need to include -ea
as a VM option in the run configuration.
Keywords: assign4
Submission reference: IN3413
I am getting this weird error from the tokenizer when it reads a minus sign. Every token is evaluated properly until I get to this point. When I run the .dsl program provided I get this error when I reach this assignment:
while.. if.. sum := sum + (num - 2);Unexpected exception parsing: main.dsl java.lang.IllegalStateException: Unrecognised character: – But for this case the program will run properly:
int sum ,num; sum := sum + (num - 2);Why would the tokenizer be able to recognize the minus sign here and not when I run the full file?
Make sure you have the most up-to-date Example DSL file from the Assessments Section of the Moodle page, or simply edit that character in the file you have to make sure that the '-' character really is a '-' character.
Keywords: assign4
Submission reference: IN3412
It says in the requirements paper that declaration is ::= but in the example DSL file you provided all the declarations are :=
In the requirements it 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 ';').
Keywords: assign4
Referrers: Question 47 (2023)
Submission reference: IN3409
How can I know for sure that the right identifiers are being parsed while also being recorded in the symbol table. For example for all three of the dsl files:
int x; int x, y, z; int x; int x,y,z;The output is: "The first token is: KEYWORD INT" "error". How can I be sure that the second line of the third file is even being read?
The output is just the starting debugging code I provided, so you can get rid of that now you have started.
Each token identified by the Tokenizer has additional information associated with it. Take a look at the source of the Tokenizer class to see what methods you can call to access that information.
Keywords: assign4
Submission reference: IN3404
if my parser prints ok correct with the first part of the example del file ie
int num, sum; int ch; sum := 0; num := 1; ch := 65; print sum; print ch;
but seems to malfunction at the while loop :
while ch < 128 do if (num != 0) + (ch != 127) then sum := sum + (num – 2); ch := ch - 1; else sum := sum - num; ch := ch + 1; fi; num := num + 1; od;Will I still get a good amount of marks?
Your parser will be tested with a range of test inputs on the different declaration and types, so if it is only failing on the loop that should not have a very big impact on your overall.
Keywords: assign4
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. |