aboutsummaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-28 23:57:45 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-28 23:57:45 +0200
commita8a3f92984afbe4e02a427bfea468ebc2e146a5a (patch)
treef054e6f3052a7023f12f898132753099d816bf4c /src/parser.c
parentc80417c925b70b28f78a3111baa503f9b489286d (diff)
Implement ~x and x ~ y
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/parser.c b/src/parser.c
index 6a96154..f0977d4 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -71,8 +71,10 @@ fwdnode(ast_t ast, idx_t i)
case ASTBINMOD:
case ASTBINMUL:
case ASTBINSUB:
+ case ASTBINXOR:
case ASTCDECL:
case ASTFN:
+ case ASTUNCMPL:
case ASTUNNEG:
i = ast.kids[i].rhs;
break;
@@ -263,6 +265,10 @@ parseexpratom(ast_t *ast, lexemes_t toks)
ast->kinds[i] = ASTUNNEG;
ast->kids[i].rhs = parseexpratom(ast, toks);
break;
+ case LEXTILDE:
+ ast->kinds[i] = ASTUNCMPL;
+ ast->kids[i].rhs = parseexpratom(ast, toks);
+ break;
default:
err("parser: Invalid expression leaf");
}
@@ -275,9 +281,10 @@ parseexprinc(ast_t *ast, lexemes_t toks, idx_t lhs, int minprec)
static const int prectbl[UINT8_MAX] = {
['+'] = 1,
['-'] = 1,
+ ['~'] = 1,
+ ['%'] = 2,
['*'] = 2,
['/'] = 2,
- ['%'] = 2,
};
uint8_t op = toks.kinds[toksidx];
@@ -378,18 +385,18 @@ isfunc(lexemes_t toks)
if (toks.kinds[toksidx + 1] == LEXRPAR)
return true;
- for (size_t i = toksidx + 1, nst = 1;; i++) {
+ for (size_t i = toksidx + 1;; i++) {
switch (toks.kinds[i]) {
- case LEXLPAR:
- nst++;
- break;
- case LEXRPAR:
- if (--nst == 0)
- return false;
- break;
case LEXCOLON:
return true;
case LEXEOF:
+ case LEXLPAR:
+ case LEXMINUS:
+ case LEXPERC:
+ case LEXPLUS:
+ case LEXRPAR:
+ case LEXSLASH:
+ case LEXSTAR:
return false;
}
}