Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN ML!!!!! datatype token = ID of string | EQ | PL | MI | TI | DI; fun createlist(c:char, file:TextIO.instream) : token list =

IN ML!!!!!

datatype token = ID of string | EQ | PL | MI | TI | DI;

fun createlist(c:char, file:TextIO.instream) : token list = if Char.isAlpha(c) then word(TextIO.input1(file), file, acc [c]) else if exist(c,[#" ",#"=",#"+",#"-",#"*","/"]) then case c of #" " => thelist(TextIO.input1(file), file) | #"=" => createlist(TextIO.input1(file), file, acc @ [EQ]) | #"+" => createlist(TextIO.input1(file), file, acc @ [PL]) | #"-" => createlist(TextIO.input1(file), file, acc @ [MI]) | #"*" => createlist(TextIO.input1(file), file, acc @ [TI]) | #"/" => createlist(TextIO.input1(file), file, acc @ [DI]) else print("Complication Error.") else word(TextIO.input1(file), file, acc, tmp) and word (c:char, file:TextIO.instream, acc:token list, tmp:char list) = if Char.isAlpha(c) then word(TextIO.input1(file), file,acc, tmp @ c) else if exist(c,[#" ",#"=",#"+",#"-",#"*",#"/"]) then let val theword = implode(tmp) in creatlist(TextIO.input1(file), file, acc @ [ID theword]) else if c = nil then acc else print("Complication Error.");

fun parse(fname: string) : token list = let val file = TextIO.openIn(fname) in createlist(TextIO.input1(file), file, []) end;

My code keeps getting an "unbound variable or constructor" error and I don't know how to fix this in ML. Please help. I am trying to parse this in ML so that a text file can be read and return the string token. For example, if I had "this = school - fun" in the text file, I would get" val it = [ID "this",EQ,ID "school",MI,ID "fun"] : token list" is what it should return. I also include the error message.

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

Describe the investment planning process.

Answered: 1 week ago