Add binary operator '_' for left shift

If the command line option yus to allow the underscore character in
symbols is NOT selected, then interpret underscore as a new binary
operator meaning to do a left shift of the left side value by the
number of bit positions indicated by the right side value.  As for the
arithmetic operators, both values must be literal (numeric constants
or symbols equated to a numeric constant).
This commit is contained in:
Stephen Casner
2021-02-13 15:25:08 -08:00
committed by Rhialto The M
parent e452ac437c
commit dcdbc02b2e
6 changed files with 148 additions and 90 deletions

11
parse.c
View File

@@ -596,6 +596,7 @@ int parse_float(
#define MUL_PREC 1
#define AND_PREC 1
#define OR_PREC 1
#define LSH_PREC 1
EX_TREE *parse_unary(
char *cp); /* Prototype for forward calls */
@@ -678,6 +679,16 @@ EX_TREE *parse_binary(
leftp = tp;
break;
case '_':
if (symbol_allow_underscores || depth >= LSH_PREC)
return leftp;
rightp = parse_binary(cp + 1, term, LSH_PREC);
tp = new_ex_bin(EX_LSH, leftp, rightp);
tp->cp = rightp->cp;
leftp = tp;
break;
default:
/* Some unknown character. Let caller decide if it's okay. */