From b95827b2d01bd503918f4f218199ee9ddbdbeb72 Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Fri, 15 Feb 2019 14:34:32 +0100 Subject: [PATCH] Parse call. --- src/aeb_fate_asm.erl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/aeb_fate_asm.erl b/src/aeb_fate_asm.erl index 2932e2a..893cbfd 100644 --- a/src/aeb_fate_asm.erl +++ b/src/aeb_fate_asm.erl @@ -50,6 +50,7 @@ -export([ assemble_file/3 , asm_to_bytecode/2 , bytecode_to_fate_code/2 + , function_call/1 , pp/1 , read_file/1 , to_hexstring/1 @@ -63,6 +64,33 @@ assemble_file(InFile, OutFile, Options) -> {_Env, BC} = asm_to_bytecode(Asm, Options), ok = file:write_file(OutFile, BC). +function_call(String) -> + {ok, Tokens} = aeb_fate_asm_scan:scan(String), + parse_function_call(Tokens). + +parse_function_call([{id,_,Name}, {'(',_}| Rest]) -> + Args = to_args(Rest), + {Name, Args}. + + +to_args([{')', _}]) -> []; +to_args(Tokens) -> + case to_data(Tokens) of + {Arg, [{',', _} | Rest]} -> + {More, Rest2} = to_args(Rest), + {[Arg|More], Rest2}; + {Arg, [{')', _} | Rest]} -> + {[Arg], Rest} + end. + +to_data([{int,_line, Int}|Rest]) -> + {Int, Rest}; +to_data([{boolean,_line, Bool}|Rest]) -> + {Bool, Rest}; +to_data([{hash,_line, Hash}|Rest]) -> + {Hash, Rest}. + + pp(Asm) -> Listing = format(Asm), io:format("~s~n", [Listing]).