Created
December 17, 2015 11:59
-
-
Save oskimura/7386c37260528bf208b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
%% -*- erlang -*- | |
%%! -smp enable -sname factorial -mnesia debug verbose | |
eval(File) -> | |
{ok, B} = file:read_file(File), | |
Forms = scan(erl_scan:tokens([],binary_to_list(B),1),[]), | |
F = fun(X) -> {ok,Y} = erl_parse:parse_form(X), Y end, | |
[F(X) || X <- Forms]. | |
scan({done,{ok,T,N},S},Res) -> | |
scan(erl_scan:tokens([],S,N),[T|Res]); | |
scan(_,Res) -> | |
lists:reverse(Res). | |
main([File]) -> | |
erlang:display(eval(File)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment