aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-04-02 13:08:06 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-04-02 13:08:06 -0400
commitc73e96ff916209d74e2be9bd7d8de3758685ce4d (patch)
tree8f902fea5b6790061e48600243f0f8faeded32dd /parse.c
parentb6534ce34706d1a98584e5f916107d91da072346 (diff)
Add comparison operator <> and array method to sort by a custom
comparison function
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index e683bb63..8b2e9840 100644
--- a/parse.c
+++ b/parse.c
@@ -38,6 +38,7 @@ int op_tightness[] = {
[BINOP_MIN]=4, [BINOP_MAX]=4,
[BINOP_EQ]=3, [BINOP_NE]=3,
[BINOP_LT]=2, [BINOP_LE]=2, [BINOP_GT]=2, [BINOP_GE]=2,
+ [BINOP_CMP]=2,
[BINOP_AND]=1, [BINOP_OR]=1, [BINOP_XOR]=1,
};
#define MAX_TIGHTNESS 9
@@ -505,7 +506,7 @@ type_ast_t *parse_pointer_type(parse_ctx_t *ctx, const char *pos) {
return NULL;
spaces(&pos);
- bool is_readonly = match(&pos, "(readonly)");
+ bool is_readonly = match(&pos, "%");
spaces(&pos);
type_ast_t *type = expect(ctx, start, &pos, parse_type,
"I couldn't parse a pointer type after this point");
@@ -1313,7 +1314,12 @@ binop_e match_binary_operator(const char **pos)
case '*': *pos += 1; return BINOP_MULT;
case '/': *pos += 1; return BINOP_DIVIDE;
case '^': *pos += 1; return BINOP_POWER;
- case '<': *pos += 1; return match(pos, "=") ? BINOP_LE : (match(pos, "<") ? BINOP_LSHIFT : BINOP_LT);
+ case '<':
+ *pos += 1;
+ if (match(pos, "=")) return BINOP_LE;
+ else if (match(pos, ">")) return BINOP_CMP;
+ else if (match(pos, "<")) return BINOP_LSHIFT;
+ else return BINOP_LT;
case '>': *pos += 1; return match(pos, "=") ? BINOP_GE : (match(pos, ">") ? BINOP_RSHIFT : BINOP_GT);
default: {
if (match(pos, "!=")) return BINOP_NE;