mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-01-23 19:08:00 +00:00
as: parse: handle symbol +/- offset exprs
This commit is contained in:
parent
8ddaa532e8
commit
09016f7e2e
@ -639,16 +639,33 @@ do_expr(ScanState, First) ->
|
||||
{ok, {_Location, {?T_UINTEGER, UInt}}} ->
|
||||
{ok, mk_integer_expr(UInt)};
|
||||
{ok, {_Location, {?T_LOCAL_LABEL, Number, Direction}}} ->
|
||||
{ok, mk_local_label_expr(Number, Direction)};
|
||||
do_expr_maybe_offset(ScanState, _Symbol = {Number, Direction});
|
||||
{ok, {_Location, {?T_SYMBOL, Symbol}}} ->
|
||||
{ok, mk_symbol_expr(Symbol)};
|
||||
do_expr_maybe_offset(ScanState, Symbol);
|
||||
_ ->
|
||||
badtok("invalid start of expr", First)
|
||||
end.
|
||||
|
||||
do_expr_maybe_offset(ScanState, Symbol) ->
|
||||
case scan:token(ScanState) of
|
||||
{ok, {_Location, ?T_MINUS}} -> do_expr_offset(ScanState, Symbol, _IsMinus = true);
|
||||
{ok, {_Location, ?T_PLUS}} -> do_expr_offset(ScanState, Symbol, _IsMinus = false);
|
||||
{ok, {_Location, _Token} = First} ->
|
||||
scan:pushback(ScanState, First),
|
||||
{ok, mk_symbol_expr(Symbol)};
|
||||
{error, _Reason} = Error -> Error
|
||||
end.
|
||||
|
||||
do_expr_offset(ScanState, Symbol, IsMinus) ->
|
||||
case scan:token(ScanState) of
|
||||
{ok, {_Location, {?T_UINTEGER, UInt}}} ->
|
||||
{ok, mk_symbol_expr(Symbol, if IsMinus -> -UInt; true -> UInt end)};
|
||||
ScanRes -> badtok("expected <uinteger> after <sign>", ScanRes)
|
||||
end.
|
||||
|
||||
mk_integer_expr(Value) -> #expr{symbol = false, offset = Value}.
|
||||
mk_local_label_expr(Number, Direction) -> mk_symbol_expr({Number, Direction}).
|
||||
mk_symbol_expr(Symbol) -> #expr{symbol = Symbol, offset = 0}.
|
||||
mk_symbol_expr(Symbol, Offset) -> #expr{symbol = Symbol, offset = Offset}.
|
||||
|
||||
%% String Lists ----------------------------------------------------------------
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
%%% -*- erlang-indent-level: 2 -*-
|
||||
%%%
|
||||
%%% scanner for pdp10-elf as
|
||||
%%% Copyright (C) 2013-2019 Mikael Pettersson
|
||||
%%% Copyright (C) 2013-2020 Mikael Pettersson
|
||||
%%%
|
||||
%%% This file is part of pdp10-tools.
|
||||
%%%
|
||||
@ -169,6 +169,7 @@ do_token(ScanState) ->
|
||||
$/ -> do_slash(ScanState);
|
||||
$\" -> do_string(ScanState, Location, []);
|
||||
$- -> {ok, {Location, ?T_MINUS}};
|
||||
$+ -> {ok, {Location, ?T_PLUS}};
|
||||
_ ->
|
||||
if $0 =< Ch, Ch =< $9 -> do_number(ScanState, Location, Ch);
|
||||
($A =< Ch andalso Ch =< $Z) orelse
|
||||
|
||||
@ -84,6 +84,7 @@ format(Token) ->
|
||||
?T_DOT -> ".";
|
||||
?T_LPAREN -> "(";
|
||||
?T_MINUS -> "-";
|
||||
?T_PLUS -> "+";
|
||||
?T_RPAREN -> ")";
|
||||
?T_NEWLINE -> "<newline>";
|
||||
?T_EOF -> "<eof>"
|
||||
|
||||
@ -61,6 +61,7 @@
|
||||
-define(T_DOT, 'T_DOT'). % .
|
||||
-define(T_LPAREN, 'T_LPAREN'). % (
|
||||
-define(T_MINUS, 'T_MINUS'). % -
|
||||
-define(T_PLUS, 'T_PLUS'). % +
|
||||
-define(T_RPAREN, 'T_RPAREN'). % )
|
||||
|
||||
%% synthetic symbols
|
||||
@ -96,6 +97,7 @@
|
||||
| ?T_DOT
|
||||
| ?T_LPAREN
|
||||
| ?T_MINUS
|
||||
| ?T_PLUS
|
||||
| ?T_RPAREN
|
||||
| ?T_NEWLINE
|
||||
| ?T_EOF
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user