"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.