문제

I am currently working on a homework for a lecture in which I have to write a Interpreter for a language we defined in the lecture. Part of my homework is to write a function that will take an expression from my datatype and turn it into a string.

Here is my datatype so far:

datatype basicType = voidType | intType | boolType; 
datatype etype = basicType
               | tupelType of (etype * etype)
               | functionType of etype -> basicType;

Note that I am not even sure that this datatype is correct. I am allowed to use the SML functions String.concatWith and Int.toString.

Since this is a homework I should do I like to only get a start and tips and tricks. No full blown solutions please.

I am thankfull for any input from you girls/guys since I am about to lose my sanity from this lecture.

도움이 되었습니까?

해결책

You need to implement a function that can print all variants of etype by recursing into each value. You also need a helper function for printing basicType values, bot it does not need to be recursive but instead act as the base case in your recursion.

Both of them need one function body for each variant of the respective datatype. The body handling the functionType would also need to apply the function.

You should also think about addnig some extra string output in each function body to make it possible for the reader to distinguish between the different types.

The tupelType could for example be printed something like this: (a, b) where a and b are recursive calls into each of the tuple elements.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top