finally add real logical operators

This commit is contained in:
2025-12-26 11:52:23 +01:00
parent 270386da95
commit db2e639cc8
16 changed files with 96 additions and 49 deletions

View File

@@ -27,7 +27,7 @@ func main[] : i64
if !memory[p]
i = i + 1
let opened = 0
while i < src_len & !(src[i] == ']' & !opened)
while i < src_len && !(src[i] == ']' && !opened)
if src[i] == '['
opened = opened + 1
else if src[i] == ']'
@@ -37,7 +37,7 @@ func main[] : i64
if memory[p]
i = i - 1
let closed = 0
while i >= 0 & !(src[i] == '[' & !closed)
while i >= 0 && !(src[i] == '[' && !closed)
if src[i] == ']'
closed = closed + 1
else if src[i] == '['

View File

@@ -41,14 +41,14 @@ func main[argc: i64, argv: ptr] : i64
let found: bool = false
let end_index: i64 = -1
while !found & header_size < 8192
while !found && header_size < 8192
let n: i64 = net.read(s, header_buf + header_size, 8192 - header_size)
if n <= 0
break
let current_size: i64 = header_size + n
i = 0
while i <= current_size - 4
if header_buf[i] == 13 & header_buf[i + 1] == 10 & header_buf[i + 2] == 13 & header_buf[i + 3] == 10
if header_buf[i] == 13 && header_buf[i + 1] == 10 && header_buf[i + 2] == 13 && header_buf[i + 3] == 10
found = true
end_index = i + 4
break

View File

@@ -2,13 +2,13 @@ func check[report: array] : bool
let increasing: bool = array.nth(report, 0) < array.nth(report, 1)
for i in 0..array.size(report)-1
if array.nth(report, i) > array.nth(report, i + 1) & increasing
if array.nth(report, i) > array.nth(report, i + 1) && increasing
return false
if array.nth(report, i) < array.nth(report, i + 1) & !increasing
if array.nth(report, i) < array.nth(report, i + 1) && !increasing
return false
let diff: i64 = math.abs(array.nth(report, i) - array.nth(report, i + 1))
if diff < 1 | diff > 3
if diff < 1 || diff > 3
return false
return true

View File

@@ -1,5 +1,5 @@
func check[lines: array, x: i64, y: i64, dx: i64, dy: i64] : bool
if x + dx * 3 < 0 | x + dx * 3 >= array.size(lines) | y + dy * 3 < 0 | y + dy * 3 >= str.len(array.nth(lines, 0))
if x + dx * 3 < 0 || x + dx * 3 >= array.size(lines) || y + dy * 3 < 0 || y + dy * 3 >= str.len(array.nth(lines, 0))
return false
if array.nth(lines, x)[y] != 'X'
@@ -50,7 +50,7 @@ func part2[lines: array] : void
str.set(s, 3, array.nth(lines, x - 1)[y + 1])
str.set(s, 4, 0)
if str.equal(s, "MSSM") | str.equal(s, "SMMS") | str.equal(s, "MMSS") | str.equal(s, "SSMM")
if str.equal(s, "MSSM") || str.equal(s, "SMMS") || str.equal(s, "MMSS") || str.equal(s, "SSMM")
out = out + 1
io.println_i64(out)

View File

@@ -1,6 +1,6 @@
func rule_exists[rules_left: array, rules_right: array, a: i64, b: i64] : bool
for k in 0..array.size(rules_left)
if array.nth(rules_left, k) == a & array.nth(rules_right, k) == b
if array.nth(rules_left, k) == a && array.nth(rules_right, k) == b
return true
return false

View File

@@ -2,6 +2,6 @@ func main[] : i64
let sum = 0
for i in 0..1000
if i % 5 == 0 | i % 3 == 0
if i % 5 == 0 || i % 3 == 0
sum = sum + i
io.println_i64(sum)

View File

@@ -1,10 +1,10 @@
func days[y: i64, m: i64] : i64
if m == 2
if (((y % 4 == 0) & (y % 100 != 0)) | (y % 400 == 0))
if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
return 29
else
return 28
else if (m == 4) | (m == 6) | (m == 9) | (m == 11)
else if (m == 4) || (m == 6) || (m == 9) || (m == 11)
return 30
else
return 31

View File

@@ -15,7 +15,7 @@ func main[] : i64
for i in 2..10000
let d: i64 = divisors_sum(i)
if i < d & i == divisors_sum(d)
if i < d && i == divisors_sum(d)
sum = sum + i + d
io.println_i64(sum)

View File

@@ -11,7 +11,7 @@ func rule110_step[state: array] : array
if i + 1 < state_len
right = array.nth(state, i + 1)
array.push(new_state, !((!left & !center & !right) | (left & !center & !right) | (left & center & right)))
array.push(new_state, !((!left && !center && !right) || (left && !center && !right) || (left && center && right)))
return new_state

View File

@@ -50,11 +50,11 @@ func handle_indentation[tokens: array, current: ptr, column: ptr, line: i64, sou
array.push(indent_stack, new_indent)
add_token_with_lexeme("Indent", tokens, "", line, mem.read64(column))
else if new_indent < mem.read64(current_indent)
while array.size(indent_stack) > 1 & array.nth(indent_stack, array.size(indent_stack) - 1) > new_indent
while array.size(indent_stack) > 1 && array.nth(indent_stack, array.size(indent_stack) - 1) > new_indent
array.pop(indent_stack)
add_token_with_lexeme("Dedent", tokens, "", line, mem.read64(column))
if array.size(indent_stack) == 0 | array.nth(indent_stack, array.size(indent_stack) - 1) != new_indent
if array.size(indent_stack) == 0 || array.nth(indent_stack, array.size(indent_stack) - 1) != new_indent
zern_error(filename, line, mem.read64(column), "invalid indentation")
mem.write64(current_indent, new_indent)
@@ -75,14 +75,14 @@ func scan_number[current: ptr, column: ptr, source: str, source_len: i64] : void
while str.is_hex_digit(peek(mem.read64(current), source, source_len))
advance(current, column, source, source_len)
else if match_char('o', current, column, source, source_len)
while peek(mem.read64(current), source, source_len) >= '0' & peek(mem.read64(current), source, source_len) <= '7'
while peek(mem.read64(current), source, source_len) >= '0' && peek(mem.read64(current), source, source_len) <= '7'
advance(current, column, source, source_len)
else
while str.is_digit(peek(mem.read64(current), source, source_len))
advance(current, column, source, source_len)
func scan_identifier[tokens: array, current: ptr, column: ptr, start: i64, line: i64, source: str, source_len: i64] : void
while str.is_alphanumeric(peek(mem.read64(current), source, source_len)) | peek(mem.read64(current), source, source_len) == '_' | peek(mem.read64(current), source, source_len) == '.'
while str.is_alphanumeric(peek(mem.read64(current), source, source_len)) || peek(mem.read64(current), source, source_len) == '_' || peek(mem.read64(current), source, source_len) == '.'
advance(current, column, source, source_len)
let len: i64 = mem.read64(current) - start
@@ -216,7 +216,7 @@ func scan_token[tokens: array, current: ptr, line: ptr, column: ptr, source: str
zern_error(filename, mem.read64(line), mem.read64(column), "unterminated string")
advance(current, column, source, source_len)
add_token("String", tokens, source, start, mem.read64(current), mem.read64(line), mem.read64(column))
else if c == ' ' | c == 13 // \r
else if c == ' ' || c == 13 // \r
return 0
else if c == 10 // \n
mem.write64(line, mem.read64(line) + 1)
@@ -225,7 +225,7 @@ func scan_token[tokens: array, current: ptr, line: ptr, column: ptr, source: str
else if str.is_digit(c)
scan_number(current, column, source, source_len)
add_token("Number", tokens, source, start, mem.read64(current), mem.read64(line), mem.read64(column))
else if str.is_letter(c) | c == '_'
else if str.is_letter(c) || c == '_'
scan_identifier(tokens, current, column, start, mem.read64(line), source, source_len)
else
zern_error(filename, mem.read64(line), mem.read64(column), "unexpected character")