It's UWAweek 42 (2nd semester, week 12)

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying the 8 articles in this topic
Showing 8 of 738 articles.
Currently 175 other people reading this forum.


 UWA week 37 (2nd semester, week 7) ↓
SVG not supported

Login to reply

👍x1
helpful
3:22pm Mon 9th Sep, Samay G.

1) Under the Our ml Language headline, it says, "only a single datatype is supported - real numbers, such as 2.71828", and, "variables do not need to be defined before being used in an expression, and are automatically initialised to the (real) value 0.0". Whereas, under the Project Requirements headline, it says, "When printed, numbers that are exact integers must be printed without any decimal places", and, in sample04.ml file the output required is in the integer data type, which as stated under 'our ml language' headline, is not supported by the language. 2) The project assessment section states that "runml.c" code shall compile using command "cc -std=c11 -Wall -Werror -o runml runml.c", but it doesn't confirm if the translated code should be compiled with "-Wall -Werror" flags or just "cc -std=c11 -o myoutput myoutput.c"? 3) Some gcc/cc compilers allow nested functions as extension, e.g. a function can be declared within the main() function. Can you please confirm if nested functions are permissible in this project or not.


SVG not supported

Login to reply

👍?
helpful
4:49pm Wed 11th Sep, ANONYMOUS

For your third question, I think it was mentioned in an earlier post that nested functions aren't allowed in ml, so we won't have to deal with those. Sorry I can't help answer the first two :(


SVG not supported

Login to reply

👍?
helpful
7:32pm Wed 11th Sep, Samay G.

Just to clarify the third question. i dont mean using nested functions in the ml, but using them while translating ml to c as the gcc compiler doesnt throw any warnings or errors, it works fine.


SVG not supported

Login to reply

👍?
helpful
8:30pm Wed 11th Sep, Joshua N.

"Samay Gupta" <23*6*5*8@s*u*e*t*u*a*e*u*a*> wrote:
> 1) Under the Our ml Language headline, it says, "only a single datatype is supported - real numbers, such as 2.71828", and, "variables do not need to be defined before being used in an expression, and are automatically initialised to the (real) value 0.0". Whereas, under the Project Requirements headline, it says, "When printed, numbers that are exact integers must be printed without any decimal places", and, in sample04.ml file the output required is in the integer data type, which as stated under 'our ml language' headline, is not supported by the language.
You need to change the format string of printf so that you print the double without any decimal places. Answered here: [help2002]
> 2) The project assessment section states that "runml.c" code shall compile using command "cc -std=c11 -Wall -Werror -o runml runml.c", but it doesn't confirm if the translated code should be compiled with "-Wall -Werror" flags or just "cc -std=c11 -o myoutput myoutput.c"?
I would say so. Some warning in C are straight up errors and result in strange behaviour when run.
> 3) Some gcc/cc compilers allow nested functions as extension, e.g. a function can be declared within the main() function. Can you please confirm if nested functions are permissible in this project or not.
Nested functions aren't allowed.


SVG not supported

Login to reply

👍?
helpful
1:10pm Thu 12th Sep, Samay G.

Q1) I saw the thread that you shared but it means that we will have to store the expression, evaluate it and then handle the value. something like - double temp = <entire expression>; if (temp==int(temp)){....} Q2) So if i understand correctly, the expectation is that runml.c should compile the translated code using "cc -std=c11 -Wall -Werror -o runml runml.c"? Q3) One related question, ml can have code like this - x <- 3 function add a return a+5 add(x) function multiply b return b*5 multiply(x) print x I can keep first line outside main function (global variable), and then parse entire ml code find all functions and then move them to the top (outside main) in translated code. any suggestions, or can we assume that all the functions in ml language will be declared first (ahead of other expressions/statements)?


SVG not supported

Login to reply

👍?
helpful
9:04pm Thu 12th Sep, Joshua N.

"Samay Gupta" <23*6*5*8@s*u*e*t*u*a*e*u*a*> wrote:
> Q1) I saw the thread that you shared but it means that we will have to store the expression, evaluate it and then handle the value. something like - > double temp = <entire expression>; > if (temp==int(temp)){....}
It would. Or you can write an if statement in the c version of the ml file to change what is printed, then let c do the hard work.
> Q2) So if i understand correctly, the expectation is that runml.c should compile the translated code using "cc -std=c11 -Wall -Werror -o runml runml.c"?
That would make the most logical sense. Since warnings can be errors and do something unintended.
> Q3) One related question, ml can have code like this - > > x <- 3 > function add a > return a+5 > > add(x) > > function multiply b > return b*5 > > multiply(x) > print x > > I can keep first line outside main function (global variable), and then parse entire ml code find all functions and then move them to the top (outside main) in translated code. any suggestions, or can we assume that all the functions in ml language will be declared first (ahead of other expressions/statements)?
No guarantees about the order in which statements appear in ml. You could store the functions in one file and the main function in another. Or you could store two arrays one containing the function definitions and the other containing the contents that will be in main and then they just write the function definitions first and then write the contents to main next. Or you could go through the file twice find the functions write them to the file and then go through the file a second time and get the statements. There are many ways to approach it.


SVG not supported

Login to reply

👍x1
helpful
3:40pm Fri 13th Sep, Amitava D.

"Samay Gupta" <23*6*5*8@s*u*e*t*u*a*e*u*a*> wrote:
> 1) Under the Our ml Language headline, it says, "only a single datatype is supported - real numbers, such as 2.71828", and, "variables do not need to be defined before being used in an expression, and are automatically initialised to the (real) value 0.0". Whereas, under the Project Requirements headline, it says, "When printed, numbers that are exact integers must be printed without any decimal places", and, in sample04.ml file the output required is in the integer data type, which as stated under 'our ml language' headline, is not supported by the language. > > 2) The project assessment section states that "runml.c" code shall compile using command "cc -std=c11 -Wall -Werror -o runml runml.c", but it doesn't confirm if the translated code should be compiled with "-Wall -Werror" flags or just "cc -std=c11 -o myoutput myoutput.c"? > > 3) Some gcc/cc compilers allow nested functions as extension, e.g. a function can be declared within the main() function. Can you please confirm if nested functions are permissible in this project or not.
There is no need to complicate matters. Assume that there is no nested function, and that the generated code can be compiled without -Werror


SVG not supported

Login to reply

👍?
helpful
5:45pm Sat 14th Sep, Samay G.

Thank you for your guidance. So I will be compiling the translated code using "cc -std=c11 -Wall -o runml runml.c".

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy