Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Oppgave 7a)
- fun {Length Ls}
- case Ls
- of nil then 0
- [] _|Lr then 1 + {Length Lr}
- end
- end
- %Oppgave 7b)
- fun {Take Xs N}
- if N==0 then
- nil
- else
- case Xs
- of nil then nil
- [] Ls|Xr then Ls|{Take Xr N-1}
- end
- end
- end
- %Oppgave 7c)
- fun {Drop Xs N}
- if N==0 then
- Xs
- else
- case Xs
- of nil then nil
- [] _|Xr then {Drop Xr N-1}
- end
- end
- end
- %Oppgave 7d)
- fun {Append Xs Ys}
- case Xs
- of nil then Ys
- [] Ls|Xr then Ls|{Append Xr Ys}
- end
- end
- %Oppgave 7e)
- fun {Member Xs Y}
- if Xs == nil then
- false
- elseif Xs.1 == Y then
- true
- else
- {Member Xs.2 Y}
- end
- end
- %Oppgave 7f)
- fun {Position Xs Y}
- if Xs.1 == Y then 1
- else 1 + {Position Xs.2 Y}
- end
- end
- %Oppgave 8
- fun {Tokenize L}
- if L == nil then nil
- elseif {Member ["local" "then" "in" "if" "end" "else" "elseif" "skip"] L.1} then "key("#L.1#")"|{Tokenize L.2}
- elseif {Member ["+" "-" "/" "*"] L.1} then "op("#L.1#")"|{Tokenize L.2}
- elseif L.1 == "=" then "un("#L.1#")"|{Tokenize L.2}
- elseif L.1 == "==" then "sammenligning(==)"|{Tokenize L.2}
- elseif L.1.1 >= &A andthen L.1.1 =< &Z then "id("#L.1#")"|{Tokenize L.2}
- elseif L.1.1 >= &a andthen L.1.1 =< &z orelse L.1.1 == "'" then "atom("#L.1#")"|{Tokenize L.2} %L.1.1 - Første bosktav i første ord
- else 'Error, error! System will self destruct in 5 seconds'
- end
- end
Add Comment
Please, Sign In to add comment