You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having trouble with an assignment that involves file i/o. It involves the problem of where to save my file in Oz.If it's not too much trouble, may I have a hint/Assistance to my problem? #333
The proposed imperative language which should be tokenized has the following list of tokens: keywords, operators, atoms, integers, floats, and separators.The keywords are: program, void, bool, int, float, true, false, if, then, else, local, in, end, assign, call. The operators are: ‘=’, ‘+’, ‘-‘, ‘*’, ‘/’, ‘==’, ‘!=’, ‘>’, ‘<’,‘<=’,‘>=’. An atom starts with a lowercase character, followed byany number of alphanumeric characters, but it cannot be a keyword. The integers and floats are those known like in any programming language. The separators are blanks (spaces), ‘;’, ‘,’, ‘(‘, ‘)’, ‘{‘, ‘}’. Write an Oz program which reads a sequenceof characters, and provides in the output the list of tokens according to the above rules.If a token cannot be accepted, then the Oz program should provide an error message accordingly.For example, the fileprogram foo; int meth1(int x) { assign x=x+1; call boo(3)}should provide at the output the list of tokens: [program foo ';' int meth1 '(' int x ')' '{' assign x '=' x '+' 1 ';' call boo '(' 3 ')' '}']
What i did so far:
declare
%ExampleOfToken="foo;;foo;"
fun {SeparateToken Token Token1 Acc}
case Token
of nil then Acc
[] H|T then
if H == '&' then
% We identify the semicolon ;
% The scanned characters identify the token Token1
if Token1 \= nil then
% if this token is not nil, then we append Token1 and ";"
{SeparateToken T nil {Append Acc {Append [Token1] [";"]}}}
else
% if this token is nil, we do not append Token1
{SeparateToken T nil {Append Acc [";"]}}
end
else
% otherwise, we are in the middle of a token, so
% Token1 will be {Append Token1 [H]}
{SeparateToken T {Append Token1 [H]} Acc}
end