modulus operator
This commit is contained in:
18
parser.v
18
parser.v
@@ -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 {[]}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user