Question: Complete this parser in Standard ML. write the code Declare the following datatype: datatype token = ID of string | EQ | PL | MI

Complete this parser in Standard ML. write the code

Complete this parser in Standard ML. write the code Declare the following

datatype: datatype token = ID of string | EQ | PL |

Declare the following datatype: datatype token = ID of string | EQ | PL | MI | TI | DI; Write an ML function named parse : string token list that inputs the name of a text file. The file will contain a sequence of characters representing a (not necessarily proper) assignment statement. Your function will parse the text file character by character. The output will be a list of tokens that classify each type of word that was read in the file. The following tables shows all the possible words and their tokens. For example, if the text file is named input.txt and contains: profit=Revenuecost Then your function should work as follows: -parse("input.txt");valit=[ID"profit",EQ,ID"Revenue",MI,ID"cost"]:tokenlist As another example, if the text file is named input2.txt and contains: Hello world + Then your function should work as follows: - parse ("input2.txt"); val it = [ID "Hello", ID "world",PL] : token list If your function reads any other invalid characters such as in the example: Hello 3 world + Then your function should return an empty list and print the message "Compilation error" to the terminal. Specifications/Notes: - To parse the assignment statement, you must evaluate it character by character and then make appropriate decisions so that the parser will return the correct tokens. - The words can be separated by any amount of whitespace, which shall be ignored. - The valid characters shall be only lowercase letters, uppercase letters, and the five operation characters listed above. - The operation characters will always be of length one. They may or may not have whitespace around them, so your parser should be able to handle this. In other words, if the file in the first example above contained profit=Revenue-cost, then then your program should return the same result. - The input file can be blank, in which case your function should return an empty list. - You will not know the name of the file in advance. - Check Moodle for a list of allowed structures/library functions. No other structures or library functions are allowed without explicit permission, especially if they perform the tokenization for you. - You must use the functional/recursive programming style with pattern matching where appropriate. Do not use loops, "global" variable bindings, or other procedural techniques (e.g., no huge if-then-else chains). - To conquer the complexity of the project, it is recommended you start by coding to succeed on "simpler" cases and then adjust your code to handle more complex cases. - To assist in code readability, break up tasks by writing helper functions when possible. - Comment your code briefly but thoroughly. - If you use ideas/code from other sources, cite them in the comments. Outside sources should be minimal... they shall not be used to replace large segments of code or to perform the tokenization for you. - You may work with one partner. If you do, include in the comments a brief statement on how the work was divided and/or who was responsible for which pieces of code. - You shall set an office appointment to do a presentation/demonstration/defense of your project after the submission deadline, which will be a part of your project grade. - You shall be graded on clarity, efficiency, efficacy. Observe good coding practices

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!