modulus operator

This commit is contained in:
uan
2026-02-07 15:32:52 +01:00
parent 7fddf9ab30
commit 58f0dfa969
3 changed files with 19 additions and 5 deletions

View File

@@ -18,10 +18,10 @@ enum Precedence {
fn (p Parser) get_precedence(tok_type TokenType) Precedence {
return match tok_type {
.equals, .plus_eq, .minus_eq, .star_eq, .slash_eq { .assignment }
.equals, .plus_eq, .minus_eq, .star_eq, .slash_eq, .percent_eq { .assignment }
.eq_eq, .not_eq, .less_eq, .greater_eq, .less, .greater { .comparison }
.plus, .minus { .sum }
.star, .slash { .product }
.star, .slash, .percent { .product }
.dot { .access }
.increment, .decrement { .suffix }
else { .base}
@@ -467,12 +467,14 @@ fn (mut p Parser) parse_unary_left(op string) UnaryExpr {
fn (mut p Parser) parse_binary(left Expr, op string, prec Precedence) BinaryExpr {
if op in ['=', '+=', '-=', '*=', '/='] {
if op in ['=', '+=', '-=', '*=', '/=', '%='] {
if p.get_expr_is_immutable(left) {
parse_error("Cannot assign to immutable expression ${left}")
}
}
dump(op)
right := p.parse_expr(prec)
binary_expr := BinaryExpr{left, op, right}
@@ -572,7 +574,15 @@ fn (mut p Parser) get_expr_type(expr Expr) string {
fn (mut p Parser) is_op_valid_for_type(type string, op string) bool {
global := ['=', '==', '!=']
mut legal_ops := match type {
'int', 'real' {['+', '-', '*', '/', '<', '>', '<=', '>=', '++', '--', '+=', '-=', '*=', '/=', '++', '--']}
'int' {[
'+', '-', '*', '/', '%', '<', '>', '<=',
'>=', '++', '--', '+=', '-=', '*=', '/=',
'%='
]}
'real' {[
'+', '-', '*', '/', '<', '>', '<=', '>=',
'++', '--', '+=', '-=', '*=', '/=',
]}
'bool' {['=']}
else {[]}
}