diff --git a/erlang/apps/as/src/parse.erl b/erlang/apps/as/src/parse.erl index 0750ef3..b6fac6b 100644 --- a/erlang/apps/as/src/parse.erl +++ b/erlang/apps/as/src/parse.erl @@ -116,38 +116,31 @@ stmt_after_symbol(ScanState, Location, Name) -> case scan:token(ScanState) of {ok, {_Location, ?T_COLON}} -> {ok, {Location, #s_label{name = Name}}}; {ok, {_Location, ?T_NEWLINE}} -> make_insn(Location, Name, false, false, false, false); - {ok, {_Location, {?T_UINTEGER, UInt}}} -> insn_uint(ScanState, Location, Name, UInt); - {ok, {_Location, {?T_SYMBOL, Symbol}}} -> insn_symbol(ScanState, Location, Name, Symbol); - {ok, {_Location, {?T_LOCAL_LABEL, Number, Direction}}} -> - insn_local_label(ScanState, Location, Name, Number, Direction); - ScanRes -> badtok("junk after symbol", ScanRes) + {ok, {Location2, {?T_UINTEGER, UInt}}} -> insn_uint(ScanState, Location, Name, Location2, UInt); + {ok, {_Location, _Token} = First} -> insn_disp(ScanState, Location, Name, First); + {error, _Reason} = Error -> Error end. %% Seen " ". The is the if followed %% by ",", otherwise (the start of) the . -insn_uint(ScanState, Location, Name, UInt) -> +insn_uint(ScanState, Location, Name, Location2, UInt) -> case scan:token(ScanState) of {ok, {_Location, ?T_COMMA}} -> % the Uint is the Accumulator, parse EA next insn_ea(ScanState, Location, Name, _AccOrDev = UInt); - {ok, {_Location, ?T_LPAREN}} -> % the Uint is the Displacement, parse Index next - Displacement = mk_integer_expr(UInt), - insn_ea_index(ScanState, Location, Name, _AccOrDev = false, _At = false, Displacement); - {ok, {_Location, ?T_NEWLINE}} -> % the Uint is the Displacement - Displacement = mk_integer_expr(UInt), - make_insn(Location, Name, _AccOrDev = false, _At = false, Displacement, _Index = false); - ScanRes -> badtok("junk after ", ScanRes) + {ok, {_Location, _Token} = Follow} -> % the UInt is start of the Displacement + scan:pushback(ScanState, Follow), + insn_disp(ScanState, Location, Name, {Location2, {?T_UINTEGER, UInt}}); + {error, _Reason} = Error -> Error end. -%% Seen " ". The is (the start of) the . -%% TODO: permit to be the (named register or device). -insn_symbol(ScanState, Location, Name, Symbol2) -> - Displacement = mk_symbol_expr(Symbol2), - insn_ea_disp(ScanState, Location, Name, _AccOrDev = false, _At = false, Displacement). - -%% Seen " ". The is (the start of) the . -insn_local_label(ScanState, Location, Name, Number, Direction) -> - Displacement = mk_local_label_expr(Number, Direction), - insn_ea_disp(ScanState, Location, Name, _AccOrDev = false, _At = false, Displacement). +%% Seen " " where is not followed by ",". +%% is the start of the . +insn_disp(ScanState, Location, Name, First) -> + case do_expr({ok, First}) of + {ok, Displacement} -> + insn_ea_disp(ScanState, Location, Name, _AccOrDev = false, _At = false, Displacement); + {error, _Reason} = Error -> Error + end. %% "," . [ ["@"] ["(" ")"] ] insn_ea(ScanState, Location, Name, AccOrDev) -> @@ -155,31 +148,21 @@ insn_ea(ScanState, Location, Name, AccOrDev) -> {ok, {_Location, ?T_NEWLINE}} -> make_insn(Location, Name, AccOrDev, _At = false, _Displacement = false, _Index = false); {ok, {_Location, ?T_AT}} -> insn_ea_at(ScanState, Location, Name, AccOrDev); - {ok, {_Lcation, {?T_UINTEGER, UInt}}} -> - Displacement = mk_integer_expr(UInt), - insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = false, Displacement); - {ok, {_Location, {?T_SYMBOL, Symbol}}} -> - Displacement = mk_symbol_expr(Symbol), - insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = false, Displacement); - {ok, {_Location, {?T_LOCAL_LABEL, Number, Direction}}} -> - Displacement = mk_local_label_expr(Number, Direction), - insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = false, Displacement); - ScanRes -> badtok("junk after comma", ScanRes) + {ok, {_Location, _Token}} = ScanRes -> + case do_expr(ScanRes) of + {ok, Displacement} -> + insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = false, Displacement); + {error, _Reason} = Error -> Error + end; + {error, _Reason} = Error -> Error end. %% [ ","] "@" . ["(" ")"] insn_ea_at(ScanState, Location, Name, AccOrDev) -> - case scan:token(ScanState) of - {ok, {_Location, {?T_UINTEGER, UInt}}} -> - Displacement = mk_integer_expr(UInt), + case expr(ScanState) of + {ok, Displacement} -> insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = true, Displacement); - {ok, {_Location, {?T_SYMBOL, Symbol}}} -> - Displacement = mk_symbol_expr(Symbol), - insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = true, Displacement); - {ok, {_Location, {?T_LOCAL_LABEL, Number, Direction}}} -> - Displacement = mk_local_label_expr(Number, Direction), - insn_ea_disp(ScanState, Location, Name, AccOrDev, _At = true, Displacement); - ScanRes -> badtok("junk after @", ScanRes) + {error, _Reason} = Error -> Error end. %% [ ","] ["@"] . ["(" ")"] diff --git a/erlang/rebar.config b/erlang/rebar.config index 075029e..977449b 100644 --- a/erlang/rebar.config +++ b/erlang/rebar.config @@ -1,6 +1,6 @@ %% -*- erlang -*- %% rebar.config for pdp10-tools -%% Copyright (C) 2018-2019 Mikael Pettersson +%% Copyright (C) 2018-2020 Mikael Pettersson %% %% This file is part of pdp10-tools. %% @@ -61,7 +61,6 @@ %% actual unused exports , {pdp10_opcodes, cpu_device_from_name, 2} , {pdp10_opcodes, models_from_name, 1} - , {scan, pushback, 2} ]}. {escript_emu_args, "%%! +sbtu +A1 +Bd -noshell -smp auto\n"}.