Question
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started