commit 4fd9a0bca3e9cb1801e07f717f235b644becc429
parent 756ad62e31c58c6d9232191d7c88cafa03fce56c
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 23 Dec 2020 15:45:36 -0500
parse: unary & requires object-selector
Diffstat:
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -98,7 +98,6 @@ check_expr_binarithm(struct context *ctx,
switch (expr->binarithm.op) {
// Numeric arithmetic
case BIN_BAND:
- case BIN_BNOT:
case BIN_BOR:
case BIN_DIV:
case BIN_LSHIFT:
diff --git a/src/parse.c b/src/parse.c
@@ -21,7 +21,7 @@ static void
synassert_msg(bool cond, const char *msg, struct token *tok)
{
if (!cond) {
- fprintf(stderr, "Syntax error: %s at %s:%d:%d ('%s')\n", msg,
+ fprintf(stderr, "Syntax error: %s at %s:%d:%d (found '%s')\n", msg,
tok->loc.path, tok->loc.lineno, tok->loc.colno,
token_str(tok));
exit(1);
@@ -555,6 +555,18 @@ unop_for_token(enum lexical_token tok)
}
static struct ast_expression *
+parse_object_selector(struct parser *par)
+{
+ trace(TR_PARSE, "object-selector");
+ struct token tok;
+ lex(par->lex, &tok);
+ unlex(par->lex, &tok);
+ struct ast_expression *exp = parse_postfix_expression(par);
+ synassert_msg(exp->type == EXPR_ACCESS, "expected object", &tok);
+ return exp;
+}
+
+static struct ast_expression *
parse_unary_expression(struct parser *par)
{
trace(TR_PARSE, "unary-arithmetic");
@@ -571,7 +583,11 @@ parse_unary_expression(struct parser *par)
exp = calloc(1, sizeof(struct ast_expression));
exp->type = EXPR_UNARITHM;
exp->unarithm.op = unop_for_token(tok.token);
- exp->unarithm.operand = parse_unary_expression(par);
+ if (tok.token == T_BAND) {
+ exp->unarithm.operand = parse_object_selector(par);
+ } else {
+ exp->unarithm.operand = parse_unary_expression(par);
+ }
return exp;
default:
unlex(par->lex, &tok);
diff --git a/src/qinstr.c b/src/qinstr.c
@@ -87,7 +87,6 @@ binarithm_for_op(enum binarithm_operator op)
return Q_SHL;
case BIN_RSHIFT:
return Q_SHR;
- case BIN_BNOT:
case BIN_GREATER:
case BIN_GREATEREQ:
case BIN_LAND: