diff --git a/lib/base.neon b/lib/base.neon index 0bfea23971..603eb37848 100644 --- a/lib/base.neon +++ b/lib/base.neon @@ -23,7 +23,7 @@ EXPORT FUNCTION from(base: Number, digits: String): NumberResult CHECK d ISA string.FindResult.index ELSE RETURN NumberResult.error("invalid digit: \(c) at index \(i)") END CHECK - r := r * base + d.index + r := (r * base) + d.index END FOREACH RETURN NumberResult.value(r) END FUNCTION diff --git a/lib/bigint.neon b/lib/bigint.neon index 92b0ea94ee..d6241b14c8 100644 --- a/lib/bigint.neon +++ b/lib/bigint.neon @@ -186,7 +186,7 @@ FUNCTION sub(x, y: BigInt): BigInt VAR i: Number := 0 VAR borrow: Number := 0 WHILE i < x.digits.size() DO - r.digits[i] := (IF i < x.digits.size() THEN x.digits[i] ELSE 0) - (IF i < y.digits.size() THEN y.digits[i] ELSE 0) - borrow + r.digits[i] := ((IF i < x.digits.size() THEN x.digits[i] ELSE 0) - (IF i < y.digits.size() THEN y.digits[i] ELSE 0)) - borrow IF r.digits[i] < 0 THEN r.digits[i] := r.digits[i] + Base borrow := 1 @@ -216,7 +216,7 @@ FUNCTION mul(x, y: BigInt): BigInt VAR p: BigInt := Zero VAR carry: Number := 0 FOR j := 0 TO x.digits.size()-1 DO - LET z: Number := (IF j < x.digits.size() THEN x.digits[j] ELSE 0) * y.digits[i] + carry + LET z: Number := ((IF j < x.digits.size() THEN x.digits[j] ELSE 0) * y.digits[i]) + carry p.digits[i+j] := z MOD Base carry := math.floor(z / Base) END FOR diff --git a/lib/complex.neon b/lib/complex.neon index f1ea5b82e3..7f7ba5a380 100644 --- a/lib/complex.neon +++ b/lib/complex.neon @@ -100,7 +100,7 @@ FUNCTION acos(a: Complex): Complex LET s2: Complex := make(1 + a.re, a.im).sqrt() LET r1: Number := 2 * math.atan2(s1.re, s2.re) VAR i1: Number := (s2.re*s1.im) - (s2.im*s1.re) - i1 := sign(i1) * math.log(math.abs(i1) + math.sqrt(i1*i1 + 1)) + i1 := sign(i1) * math.log(math.abs(i1) + math.sqrt((i1*i1) + 1)) RETURN make(r1, i1) END FUNCTION @@ -115,7 +115,7 @@ FUNCTION acosh(a: Complex): Complex LET s1: Complex := make(a.re - 1, a.im).sqrt() LET s2: Complex := make(a.re + 1, a.im).sqrt() VAR r1: Number := (s1.re*s2.re) + (s1.im*s2.im) - r1 := sign(r1) * math.log(math.abs(r1) + math.sqrt(r1*r1 + 1)) + r1 := sign(r1) * math.log(math.abs(r1) + math.sqrt((r1*r1) + 1)) LET i1: Number := 2 * math.atan2(s1.im, s2.re) RETURN make(r1, i1) END FUNCTION @@ -128,7 +128,7 @@ END FUNCTION * http://mathworld.wolfram.com/AbsoluteValue.html */ FUNCTION abs(a: Complex): Number - RETURN math.sqrt(a.re^2 + a.im^2) + RETURN math.sqrt((a.re^2) + (a.im^2)) END FUNCTION /* Function: add @@ -164,7 +164,7 @@ FUNCTION asin(a: Complex): Complex LET s1: Complex := make(1 + a.re, a.im).sqrt() LET s2: Complex := make(1 - a.re, -a.im).sqrt() VAR r1: Number := (s1.re*s2.im) - (s2.re*s1.im) - r1 := sign(r1) * math.log(math.abs(r1) + math.sqrt(r1*r1 + 1)) + r1 := sign(r1) * math.log(math.abs(r1) + math.sqrt((r1*r1) + 1)) LET i1: Number := math.atan2(a.re, (s1.re*s2.re) - (s1.im*s2.im)) RETURN make(i1, -r1) END FUNCTION @@ -180,7 +180,7 @@ FUNCTION asinh(a: Complex): Complex LET s1: Complex := make(1 + a.im, -a.re).sqrt() LET s2: Complex := make(1 - a.im, a.re).sqrt() VAR r1: Number := (s1.re * s2.im) - (s2.re * s1.im) - r1 := sign(r1) * math.log(math.abs(r1) + math.sqrt(r1 * r1 + 1)) + r1 := sign(r1) * math.log(math.abs(r1) + math.sqrt((r1 * r1) + 1)) LET i1: Number := math.atan2(a.im, (s1.re * s2.re) - (s1.im * s2.im)) RETURN make(r1, i1) END FUNCTION @@ -250,8 +250,8 @@ END FUNCTION * http://mathworld.wolfram.com/ComplexDivision.html */ FUNCTION div(a, b: Complex): Complex - LET d: Number := b.re^2 + b.im^2 - RETURN make((a.re*b.re + a.im*b.im) / d, (a.im*b.re - a.re*b.im) / d) + LET d: Number := (b.re^2) + (b.im^2) + RETURN make(((a.re*b.re) + (a.im*b.im)) / d, ((a.im*b.re) - (a.re*b.im)) / d) END FUNCTION /* Function: exp @@ -287,7 +287,7 @@ END FUNCTION * http://mathworld.wolfram.com/MultiplicativeInverse.html */ FUNCTION inv(a: Complex): Complex - LET d: Number := a.re*a.re + a.im*a.im + LET d: Number := (a.re*a.re) + (a.im*a.im) RETURN make(a.re/d, -a.im/d) END FUNCTION @@ -299,7 +299,7 @@ END FUNCTION * http://mathworld.wolfram.com/Logarithm.html */ FUNCTION log(a: Complex): Complex - RETURN make(math.log(a.re*a.re + a.im*a.im)/2, a.arg()) + RETURN make(math.log((a.re*a.re) + (a.im*a.im))/2, a.arg()) END FUNCTION /* Function: log10 @@ -322,7 +322,7 @@ END FUNCTION * http://mathworld.wolfram.com/ComplexMultiplication.html */ FUNCTION mul(a, b: Complex): Complex - RETURN make(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re) + RETURN make((a.re * b.re) - (a.im * b.im), (a.re * b.im) + (a.im * b.re)) END FUNCTION /* Function: pow @@ -335,8 +335,8 @@ END FUNCTION FUNCTION pow(a, b: Complex): Complex LET p: Number := a.arg() LET m: Number := a.abs() - LET r: Number := m^b.re * math.exp(-b.im * p) - LET t: Number := b.re * p + b.im * math.log(m) + LET r: Number := (m^b.re) * math.exp(-b.im * p) + LET t: Number := (b.re * p) + (b.im * math.log(m)) RETURN make(r * math.cos(t), r * math.sin(t)) END FUNCTION @@ -390,7 +390,7 @@ END FUNCTION * Complex square (a^2). */ FUNCTION square(a: Complex): Complex - RETURN make(a.re*a.re - a.im*a.im, 2*a.re*a.im) + RETURN make((a.re*a.re) - (a.im*a.im), 2*a.re*a.im) END FUNCTION /* Function: tan diff --git a/lib/datetime.neon b/lib/datetime.neon index a4c27263f3..3fe426353f 100644 --- a/lib/datetime.neon +++ b/lib/datetime.neon @@ -193,7 +193,7 @@ FUNCTION makeFromInstant(inst: Number): DateTime year WITH 1900 + tm.tm_year, month WITH 1 + tm.tm_mon, day WITH tm.tm_mday, - weekday WITH 1 + (tm.tm_wday + 6) MOD 7, + weekday WITH 1 + ((tm.tm_wday + 6) MOD 7), hour WITH tm.tm_hour, minute WITH tm.tm_min, second WITH tm.tm_sec, @@ -256,10 +256,10 @@ END FUNCTION FUNCTION DateTime.plusPeriod(self: DateTime, period: Period): DateTime VAR dt: DateTime := self dt.year := dt.year + period.years - LET m: Number := dt.month - 1 + period.months + LET m: Number := (dt.month - 1) + period.months dt.year := dt.year + math.floor(m / 12) dt.month := 1 + (m MOD 12) - RETURN makeFromParts(dt).plusDuration(86400*period.days + 3600*period.hours + 60*period.minutes + period.seconds) + RETURN makeFromParts(dt).plusDuration((86400*period.days) + (3600*period.hours) + (60*period.minutes) + period.seconds) END FUNCTION /* Function: DateTime.toString diff --git a/lib/json.neon b/lib/json.neon index fcc8606033..c51c59176b 100644 --- a/lib/json.neon +++ b/lib/json.neon @@ -122,11 +122,11 @@ FUNCTION decodePart(json: String, INOUT index: Number): JsonResult VAR char: Number := 0 FOR i := 1 TO 4 DO IF "0" <= json[index+i] <= "9" THEN - char := char * 0x10 + (string.toCodePoint(json[index+i]) - string.toCodePoint("0")) + char := (char * 0x10) + (string.toCodePoint(json[index+i]) - string.toCodePoint("0")) ELSIF "a" <= json[index+i] <= "f" THEN - char := char * 0x10 + (string.toCodePoint(json[index+i]) - string.toCodePoint("a")) + char := (char * 0x10) + (string.toCodePoint(json[index+i]) - string.toCodePoint("a")) ELSIF "A" <= json[index+i] <= "F" THEN - char := char * 0x10 + (string.toCodePoint(json[index+i]) - string.toCodePoint("A")) + char := (char * 0x10) + (string.toCodePoint(json[index+i]) - string.toCodePoint("A")) ELSE RETURN JsonResult.error(DecodeError(message WITH "invalid hex character", index WITH index+i)) END IF diff --git a/lib/regex.neon b/lib/regex.neon index d51c8b68d0..23e79d1acc 100644 --- a/lib/regex.neon +++ b/lib/regex.neon @@ -362,7 +362,7 @@ FUNCTION ExprGroup.compile(self: VALID POINTER TO ExprGroup, INOUT regex: Regex) IF self->capture THEN regex.append(Opcode.save(2*self->index)) self->expr->compile(INOUT regex) - regex.append(Opcode.save(2*self->index+1)) + regex.append(Opcode.save((2*self->index)+1)) ELSE self->expr->compile(INOUT regex) END IF diff --git a/lib/string.neon b/lib/string.neon index ff7e6a398c..6341bb4397 100644 --- a/lib/string.neon +++ b/lib/string.neon @@ -146,7 +146,7 @@ FUNCTION format(s: String, fmt: String): String ELSIF align IN [">", "="] THEN r := repeat(fill, space) & r ELSIF align = "^" THEN - r := repeat(fill, space INTDIV 2) & r & repeat(fill, space - space INTDIV 2) + r := repeat(fill, space INTDIV 2) & r & repeat(fill, space - (space INTDIV 2)) END IF END IF END IF @@ -220,7 +220,7 @@ FUNCTION padLeft(s: String, pad: String, width: Number): String CHECK n > 0 ELSE RETURN s END CHECK - RETURN repeat(pad, n INTDIV pad.length()) & pad[0 TO n MOD pad.length() - 1] & s + RETURN repeat(pad, n INTDIV pad.length()) & pad[0 TO (n MOD pad.length()) - 1] & s END FUNCTION /* @@ -234,7 +234,7 @@ FUNCTION padRight(s: String, pad: String, width: Number): String CHECK n > 0 ELSE RETURN s END CHECK - RETURN s & pad[LAST - (n MOD pad.length() - 1) TO LAST] & repeat(pad, n INTDIV pad.length()) + RETURN s & pad[LAST - ((n MOD pad.length()) - 1) TO LAST] & repeat(pad, n INTDIV pad.length()) END FUNCTION /* Function: quoted diff --git a/neon/lexer.neon b/neon/lexer.neon index 8706b1f54d..0890d60ae0 100644 --- a/neon/lexer.neon +++ b/neon/lexer.neon @@ -474,12 +474,12 @@ FUNCTION tokenize_fragment(source_path: String, INOUT line: Number, column_start EXIT LOOP END IF IF d <> "_" THEN - LET x: Number := (IF "0" <= d <= "9" THEN string.toCodePoint(d) - string.toCodePoint("0") ELSE (IF "a" <= d <= "z" THEN string.toCodePoint(d) - string.toCodePoint("a") + 10 ELSE -1)) + LET x: Number := (IF "0" <= d <= "9" THEN string.toCodePoint(d) - string.toCodePoint("0") ELSE (IF "a" <= d <= "z" THEN (string.toCodePoint(d) - string.toCodePoint("a")) + 10 ELSE -1)) IF x < 0 OR x >= base THEN error(1005, t, "invalid digit for given base") END IF -- TODO decimal - value := value * base + x + value := (value * base) + x END IF INC i END LOOP @@ -586,7 +586,7 @@ FUNCTION tokenize_fragment(source_path: String, INOUT line: Number, column_start IF NOT hex_char(d) THEN error(1013, t, "invalid hex character") END IF - x := x * 16 + (IF "0" <= d <= "9" THEN string.toCodePoint(d) - string.toCodePoint("0") ELSE (IF "a" <= d <= "z" THEN string.toCodePoint(d) - string.toCodePoint("a") + 10 ELSE -1)) + x := (x * 16) + (IF "0" <= d <= "9" THEN string.toCodePoint(d) - string.toCodePoint("0") ELSE (IF "a" <= d <= "z" THEN (string.toCodePoint(d) - string.toCodePoint("a")) + 10 ELSE -1)) END FOR c := string.fromCodePoint(x) i := i + len diff --git a/samples/benchmark/dhrystone.neon b/samples/benchmark/dhrystone.neon index 723e30ed84..bda11d135e 100644 --- a/samples/benchmark/dhrystone.neon +++ b/samples/benchmark/dhrystone.neon @@ -690,7 +690,7 @@ FUNCTION main() Bool_Glob := NOT Func_2 (Str_1_Loc, Str_2_Loc) -- Bool_Glob == 1 WHILE Int_1_Loc < Int_2_Loc DO -- loop body executed once - Int_3_Loc := 5 * Int_1_Loc - Int_2_Loc + Int_3_Loc := (5 * Int_1_Loc) - Int_2_Loc -- Int_3_Loc == 7 Proc_7 (Int_1_Loc, Int_2_Loc, OUT Int_3_Loc) -- Int_3_Loc == 7 @@ -715,7 +715,7 @@ FUNCTION main() -- Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 Int_2_Loc := Int_2_Loc * Int_1_Loc Int_1_Loc := math.floor(Int_2_Loc / Int_3_Loc) - Int_2_Loc := 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc + Int_2_Loc := (7 * (Int_2_Loc - Int_3_Loc)) - Int_1_Loc -- Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 Proc_2 (INOUT Int_1_Loc) -- Int_1_Loc == 5 diff --git a/samples/benchmark/whetstone.neon b/samples/benchmark/whetstone.neon index 525f6514f6..db555033e9 100644 --- a/samples/benchmark/whetstone.neon +++ b/samples/benchmark/whetstone.neon @@ -74,8 +74,8 @@ FUNCTION pa(INOUT e: Array) j := 0 WHILE j < 6 DO e[1] := ( e[1] + e[2] + e[3] - e[4]) * t - e[2] := ( e[1] + e[2] - e[3] + e[4]) * t - e[3] := ( e[1] - e[2] + e[3] + e[4]) * t + e[2] := ((e[1] + e[2] - e[3])+ e[4]) * t + e[3] := ((e[1] - e[2])+ e[3] + e[4]) * t e[4] := (-e[1] + e[2] + e[3] + e[4]) / T2 j := j + 1 END WHILE @@ -189,8 +189,8 @@ C FOR i := 1 TO N1 DO X1 := (X1 + X2 + X3 - X4) * t - X2 := (X1 + X2 - X3 + X4) * t - X3 := (X1 - X2 + X3 + X4) * t + X2 := ((X1 + X2 - X3) + X4) * t + X3 := ((X1 - X2) + X3 + X4) * t X4 := (-X1+ X2 + X3 + X4) * t END FOR --#ifdef PRINTOUT @@ -209,8 +209,8 @@ C FOR i := 1 TO N2 DO E1[1] := ( E1[1] + E1[2] + E1[3] - E1[4]) * t - E1[2] := ( E1[1] + E1[2] - E1[3] + E1[4]) * t - E1[3] := ( E1[1] - E1[2] + E1[3] + E1[4]) * t + E1[2] := ((E1[1] + E1[2] - E1[3])+ E1[4]) * t + E1[3] := ((E1[1] - E1[2])+ E1[3] + E1[4]) * t E1[4] := (-E1[1] + E1[2] + E1[3] + E1[4]) * t END FOR @@ -274,7 +274,7 @@ C FOR i := 1 TO N6 DO j := j * (k-j) * (l-k) - k := l * k - (l-j) * k + k := (l * k) - ((l-j) * k) l := (l-k) * (k+j) E1[l-1] := j + k + l E1[k-1] := j * k * l @@ -350,7 +350,7 @@ C j := j + k k := j + k j := k - j - k := k - j - j + k := (k - j) - j END FOR --#ifdef PRINTOUT diff --git a/samples/cal/cal.neon b/samples/cal/cal.neon index a10a4af06b..b1d180f1f5 100644 --- a/samples/cal/cal.neon +++ b/samples/cal/cal.neon @@ -110,7 +110,7 @@ FUNCTION main(args: Array) FOR line := 0 TO 7 DO VAR s: String := "" FOR col := 0 TO 2 DO - s.append(months[3*row+col][line] & " ") + s.append(months[(3*row)+col][line] & " ") END FOR print(s) END FOR diff --git a/samples/editor/editor.neon b/samples/editor/editor.neon index 543fe7fdf3..b5457ff950 100644 --- a/samples/editor/editor.neon +++ b/samples/editor/editor.neon @@ -42,7 +42,7 @@ FUNCTION highlight(s: String): String ELSE EXIT WHILE END IF - r[i+m.match[n].first TO i+m.match[n].last] := string.repeat(h, m.match[n].last-m.match[n].first+1) + r[i+m.match[n].first TO i+m.match[n].last] := string.repeat(h, (m.match[n].last-m.match[n].first)+1) i := i + m.match[n].last + 1 END WHILE RETURN r diff --git a/samples/forth/forth.neon b/samples/forth/forth.neon index c1e68e0c36..3e1dab7811 100644 --- a/samples/forth/forth.neon +++ b/samples/forth/forth.neon @@ -430,7 +430,7 @@ FUNCTION run_instruction(instr: Number, INOUT ip: Number) WHEN CORE_NUMBER DO LET ud1h: Number := stack.pop() LET ud1l: Number := stack.pop() - LET ud1: Number := ud1h * 0x100000000 + ud1l + LET ud1: Number := (ud1h * 0x100000000) + ud1l LET dig: Number := ud1 MOD storage[cell_base] LET ud2: Number := math.floor(ud1 / storage[cell_base]) stack.push(ud2 MOD 0x100000000) @@ -444,7 +444,7 @@ FUNCTION run_instruction(instr: Number, INOUT ip: Number) WHEN CORE_NUMBER_S DO LET ud1h: Number := stack.pop() LET ud1l: Number := stack.pop() - VAR ud1: Number := ud1h * 0x100000000 + ud1l + VAR ud1: Number := (ud1h * 0x100000000) + ud1l REPEAT LET dig: Number := ud1 MOD storage[cell_base] ud1 := math.floor(ud1 / storage[cell_base]) @@ -588,21 +588,21 @@ FUNCTION run_instruction(instr: Number, INOUT ip: Number) VAR addr: Number := stack.pop() LET ud1h: Number := stack.pop() LET ud1l: Number := stack.pop() - VAR ud1: Number := ud1h * 0x100000000 + ud1l + VAR ud1: Number := (ud1h * 0x100000000) + ud1l WHILE u > 0 DO LET char: String := string.fromCodePoint(storage[addr]) VAR dig: Number := 0 -- FIXME: shouldn't need init here IF "0" <= char <= "9" THEN dig := string.toCodePoint(char) - string.toCodePoint("0") ELSIF "A" <= char <= "Z" THEN - dig := string.toCodePoint(char) - string.toCodePoint("A") + 10 + dig := (string.toCodePoint(char) - string.toCodePoint("A")) + 10 ELSE EXIT WHILE END IF IF dig >= storage[cell_base] THEN EXIT WHILE END IF - ud1 := ud1 * storage[cell_base] + dig + ud1 := (ud1 * storage[cell_base]) + dig INC addr DEC u END WHILE @@ -760,7 +760,7 @@ FUNCTION run_instruction(instr: Number, INOUT ip: Number) LET n1: Number := signed32(stack.pop()) LET d1h: Number := signed32(stack.pop()) LET d1l: Number := stack.pop() - LET d1: Number := d1h * 0x100000000 + d1l + LET d1: Number := (d1h * 0x100000000) + d1l stack.push(d1 MOD n1) stack.push(math.floor(d1 / n1)) WHEN CORE_HERE DO @@ -867,7 +867,7 @@ FUNCTION run_instruction(instr: Number, INOUT ip: Number) LET n1: Number := signed32(stack.pop()) LET d1h: Number := signed32(stack.pop()) LET d1l: Number := stack.pop() - LET d1: Number := d1h * 0x100000000 + d1l + LET d1: Number := (d1h * 0x100000000) + d1l stack.push(d1 MOD n1) stack.push(math.floor(d1 / n1)) WHEN CORE_SOURCE DO @@ -912,7 +912,7 @@ FUNCTION run_instruction(instr: Number, INOUT ip: Number) LET u1: Number := stack.pop() LET udh: Number := stack.pop() LET udl: Number := stack.pop() - LET ud: Number := udh * 0x100000000 + udl + LET ud: Number := (udh * 0x100000000) + udl stack.push(ud MOD u1) stack.push(math.floor(ud / u1)) WHEN CORE_UM_MUL DO @@ -1258,7 +1258,7 @@ FUNCTION digit(char: String): Number IF "0" <= char <= "9" THEN RETURN string.toCodePoint(char) - string.toCodePoint("0") ELSIF "A" <= char <= "Z" THEN - RETURN string.toCodePoint(char) - string.toCodePoint("A") + 10 + RETURN (string.toCodePoint(char) - string.toCodePoint("A")) + 10 ELSE ASSERT FALSE -- invalid char END IF @@ -1273,7 +1273,7 @@ FUNCTION convert(word: String, base: Number): Number INC i END IF WHILE i < word.length() DO - n := n * base + digit(word[i]) + n := (n * base) + digit(word[i]) INC i END WHILE IF negative THEN diff --git a/samples/othello/othello.neon b/samples/othello/othello.neon index 81b1ff668c..0a0f937990 100644 --- a/samples/othello/othello.neon +++ b/samples/othello/othello.neon @@ -150,7 +150,7 @@ FUNCTION search(d, base, color, depth: Number, flag: Boolean, minscore, maxscore END IF BestPos := best IF d >= depth-1 THEN - RETURN bestscore + 8*n + RETURN bestscore + (8*n) ELSE RETURN bestscore END IF @@ -176,7 +176,7 @@ FUNCTION displayLabels(x, y: Number) curses.attrset(curses.COLOR_PAIR((IF y = i THEN 2 ELSE 0))) curses.mvaddstr((i-1)*3, 0, " " & string.fromCodePoint(string.toCodePoint("A") + i - 1) & " ") curses.attrset(curses.COLOR_PAIR((IF x = i THEN 2 ELSE 0))) - curses.mvaddstr(23, (i-1)*5+5, " " & string.fromCodePoint(string.toCodePoint("1") + i - 1) & " ") + curses.mvaddstr(23, ((i-1)*5)+5, " " & string.fromCodePoint(string.toCodePoint("1") + i - 1) & " ") END FOR END FUNCTION @@ -185,7 +185,7 @@ FUNCTION displayBoard(): Boolean VAR any: Boolean := FALSE FOR j := 0 TO 7 DO FOR i := 0 TO 7 DO - LET move: Number := 10*(j+1) + (i+1) + LET move: Number := (10*(j+1)) + (i+1) LET b: Number := Board[move] CASE b WHEN 0 DO @@ -199,7 +199,7 @@ FUNCTION displayBoard(): Boolean END CASE curses.attrset(curses.COLOR_PAIR(1+b)) FOR k := 0 TO 1 DO - curses.mvaddstr(3*j+k, 5*i+5, " ") + curses.mvaddstr((3*j)+k, (5*i)+5, " ") END FOR END FOR END FOR @@ -257,7 +257,7 @@ FUNCTION main() game_over := TRUE FOR j := 0 TO 7 DO FOR i := 0 TO 7 DO - IF validMove(0, 10*(j+1)+(i+1), 1, 100) THEN + IF validMove(0, (10*(j+1))+(i+1), 1, 100) THEN game_over := FALSE END IF END FOR @@ -273,9 +273,9 @@ FUNCTION main() IF k >= 0 THEN CASE string.fromCodePoint(k) WHEN "a" TO "h" DO - y := k - string.toCodePoint("a") + 1 + y := (k - string.toCodePoint("a")) + 1 WHEN "1" TO "8" DO - x := k - string.toCodePoint("1") + 1 + x := (k - string.toCodePoint("1")) + 1 WHEN "k" DO makeMove(kibitz()) EXIT WHILE @@ -295,7 +295,7 @@ FUNCTION main() END CASE END IF IF x <> 0 AND y <> 0 THEN - LET move: Number := 10*y + x + LET move: Number := (10*y) + x IF validMove(0, move, 2, 100) THEN makeMove(move) EXIT WHILE diff --git a/samples/rain/rain.neon b/samples/rain/rain.neon index badb121bf1..253e3a6caf 100644 --- a/samples/rain/rain.neon +++ b/samples/rain/rain.neon @@ -81,14 +81,14 @@ FUNCTION main() c := curses.Cols() - 4 FOR d := 4 TO 0 STEP -1 DO - xpos[d] := random.uint32() MOD c + 2 - ypos[d] := random.uint32() MOD r + 2 + xpos[d] := (random.uint32() MOD c) + 2 + ypos[d] := (random.uint32() MOD r) + 2 END FOR j := 0 LOOP - x := random.uint32() MOD c + 2 - y := random.uint32() MOD r + 2 + x := (random.uint32() MOD c) + 2 + y := (random.uint32() MOD r) + 2 curses.mvaddstr(y, x, ".") diff --git a/samples/sudoku/sudoku.neon b/samples/sudoku/sudoku.neon index f15b818088..c3b83d4e53 100644 --- a/samples/sudoku/sudoku.neon +++ b/samples/sudoku/sudoku.neon @@ -264,20 +264,20 @@ FUNCTION solveSudoku(INOUT grid: multiarray.ArrayNumber2D): Number IF g >= 0 THEN VAR row: Array := [] row.resize(324) - row[i*9+j] := TRUE - row[9*9+i*9+g] := TRUE - row[9*9*2+j*9+g] := TRUE - row[9*9*3+(math.floor(i/3)*3+math.floor(j/3))*9+g] := TRUE + row[(i*9)+j] := TRUE + row[(9*9)+(i*9)+g] := TRUE + row[(9*9*2)+(j*9)+g] := TRUE + row[(9*9*3)+(((math.floor(i/3)*3)+math.floor(j/3))*9)+g] := TRUE mat.append(row) rinfo.append([i, j, g+1]) ELSE FOR n := 0 TO 8 DO VAR row: Array := [] row.resize(324) - row[i*9+j] := TRUE - row[9*9+i*9+n] := TRUE - row[9*9*2+j*9+n] := TRUE - row[9*9*3+(math.floor(i/3)*3+math.floor(j/3))*9+n] := TRUE + row[(i*9)+j] := TRUE + row[(9*9)+(i*9)+n] := TRUE + row[(9*9*2)+(j*9)+n] := TRUE + row[(9*9*3)+(((math.floor(i/3)*3)+math.floor(j/3))*9)+n] := TRUE mat.append(row) rinfo.append([i, j, n+1]) END FOR @@ -343,7 +343,7 @@ END FUNCTION FUNCTION makePuzzle(solution: multiarray.ArrayNumber2D, filled: Number, callback: FUNCTION(n: Number)): multiarray.ArrayNumber2D VAR r: multiarray.ArrayNumber2D := solution VAR places: Array := [] - FOR i := 0 TO 9*9-1 DO + FOR i := 0 TO (9*9)-1 DO places[i] := i END FOR shuffle(INOUT places) @@ -406,13 +406,13 @@ FUNCTION findErrors(grid: multiarray.ArrayNumber2D): multiarray.ArrayBoolean2D END IF cols[j, n] := i -- Check for duplicate number in cell. - LET c: Number := math.floor(i / 3)*3 + math.floor(j / 3) + LET c: Number := (math.floor(i / 3)*3) + math.floor(j / 3) LET z: Number := cels[c, n] IF z >= 0 THEN r[i, j] := TRUE - r[math.floor(c / 3)*3 + math.floor(z / 3), (c MOD 3)*3 + (z MOD 3)] := TRUE + r[(math.floor(c / 3)*3) + math.floor(z / 3), ((c MOD 3)*3) + (z MOD 3)] := TRUE END IF - cels[c, n] := (i MOD 3)*3 + (j MOD 3) + cels[c, n] := ((i MOD 3)*3) + (j MOD 3) END IF END FOR END FOR @@ -447,9 +447,9 @@ FUNCTION draw_grid(grid: multiarray.ArrayNumber2D, cx, cy: Number) curses.mvaddch(0, 36, curses.ACS_URCORNER()) VAR any_errors: Boolean := FALSE FOR i := 0 TO 8 DO - curses.mvaddstr(1+2*i, 0, "| | | |") + curses.mvaddstr(1+(2*i), 0, "| | | |") FOR j := 0 TO 36 STEP 12 DO - curses.mvaddch(1+2*i, j, curses.ACS_VLINE()) + curses.mvaddch(1+(2*i), j, curses.ACS_VLINE()) END FOR FOR j := 0 TO 8 DO IF i = cy AND j = cx THEN @@ -459,33 +459,33 @@ FUNCTION draw_grid(grid: multiarray.ArrayNumber2D, cx, cy: Number) any_errors := TRUE END IF IF grid[i, j] > 0 THEN - curses.mvaddstr(1+2*i, 1+4*j, " \(grid[i, j]) ") + curses.mvaddstr(1+(2*i), 1+(4*j), " \(grid[i, j]) ") ELSE - curses.mvaddstr(1+2*i, 1+4*j, " ") + curses.mvaddstr(1+(2*i), 1+(4*j), " ") END IF curses.attrset(curses.A_NORMAL) END FOR IF i MOD 3 = 2 THEN IF i < 8 THEN - curses.mvhline(2+2*i, 0, curses.ACS_HLINE(), 37) - curses.mvaddch(2+2*i, 0, curses.ACS_LTEE()) + curses.mvhline(2+(2*i), 0, curses.ACS_HLINE(), 37) + curses.mvaddch(2+(2*i), 0, curses.ACS_LTEE()) FOR j := 4 TO 32 STEP 4 DO - curses.mvaddch(2+2*i, j, curses.ACS_PLUS()) + curses.mvaddch(2+(2*i), j, curses.ACS_PLUS()) END FOR - curses.mvaddch(2+2*i, 36, curses.ACS_RTEE()) + curses.mvaddch(2+(2*i), 36, curses.ACS_RTEE()) ELSE - curses.mvhline(2+2*i, 0, curses.ACS_HLINE(), 37) - curses.mvaddch(2+2*i, 0, curses.ACS_LLCORNER()) + curses.mvhline(2+(2*i), 0, curses.ACS_HLINE(), 37) + curses.mvaddch(2+(2*i), 0, curses.ACS_LLCORNER()) FOR j := 4 TO 32 STEP 4 DO - curses.mvaddch(2+2*i, j, curses.ACS_BTEE()) + curses.mvaddch(2+(2*i), j, curses.ACS_BTEE()) END FOR - curses.mvaddch(2+2*i, 36, curses.ACS_LRCORNER()) + curses.mvaddch(2+(2*i), 36, curses.ACS_LRCORNER()) END IF ELSE - curses.mvaddch(2+2*i, 0, curses.ACS_LTEE()) - curses.mvaddch(2+2*i, 12, curses.ACS_PLUS()) - curses.mvaddch(2+2*i, 24, curses.ACS_PLUS()) - curses.mvaddch(2+2*i, 36, curses.ACS_RTEE()) + curses.mvaddch(2+(2*i), 0, curses.ACS_LTEE()) + curses.mvaddch(2+(2*i), 12, curses.ACS_PLUS()) + curses.mvaddch(2+(2*i), 24, curses.ACS_PLUS()) + curses.mvaddch(2+(2*i), 36, curses.ACS_RTEE()) END IF END FOR IF NOT any_errors AND puzzleFilled(grid) THEN diff --git a/samples/tetris/tetris.neon b/samples/tetris/tetris.neon index b50ca7ee73..1fb76707ef 100644 --- a/samples/tetris/tetris.neon +++ b/samples/tetris/tetris.neon @@ -123,7 +123,7 @@ FUNCTION plot(on: Boolean, w: curses.Window, p, y, x, r: Number) FOR j := 0 TO 3 DO FOR i := 0 TO 3 DO IF q[j, i] <> 0 THEN - curses.mvwaddstr(w, y+j, 1+(x+i)*2, " ") + curses.mvwaddstr(w, y+j, 1+((x+i)*2), " ") END IF END FOR END FOR @@ -181,14 +181,14 @@ FUNCTION remove_rows(INOUT score, rows: Number) Board[k] := Board[k-1] FOR i := 0 TO BOARD_WIDTH-1 DO curses.wattrset(BoardWindow, curses.COLOR_PAIR(Board[k, i])) - curses.mvwaddstr(BoardWindow, k, 1+2*i, " ") + curses.mvwaddstr(BoardWindow, k, 1+(2*i), " ") END FOR END FOR ELSE DEC j END IF END WHILE - score := score + count*count + score := score + (count*count) rows := rows + count END FUNCTION @@ -207,7 +207,7 @@ FUNCTION init() curses.mvaddstr(13, 40, @" space - drop ") curses.refresh() - BoardWindow := curses.newwin(21, 2+2*10, 2, 5) + BoardWindow := curses.newwin(21, 2+(2*10), 2, 5) curses.wtimeout(BoardWindow, 100) NextWindow := curses.newwin(6, 10, 14, 30) @@ -252,7 +252,7 @@ FUNCTION main() END FOR VAR p, x, y, r: Number := 0 VAR rows, score: Number := 0 - VAR next: Number := 1 + random.uint32() MOD 7 + VAR next: Number := 1 + (random.uint32() MOD 7) VAR drop_time: Number := 1 VAR new_piece: Boolean := TRUE VAR last_drop: Number := 0 @@ -260,7 +260,7 @@ FUNCTION main() WHILE NOT game_over AND NOT quit DO IF new_piece THEN p := next - next := 1 + random.uint32() MOD 7 + next := 1 + (random.uint32() MOD 7) x := 3 y := 0 r := 0 diff --git a/src/parser.cpp b/src/parser.cpp index 7e92874012..2df7172fb0 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -43,9 +43,7 @@ class Parser { std::unique_ptr parseInterpolatedStringExpression(); std::unique_ptr parseAtom(); std::unique_ptr parseCompoundExpression(); - std::unique_ptr parseExponentiation(); - std::unique_ptr parseMultiplication(); - std::unique_ptr parseAddition(); + std::unique_ptr parseArithmetic(); std::unique_ptr parseComparison(); std::unique_ptr parseTypeTest(); std::unique_ptr parseMembership(); @@ -786,90 +784,106 @@ std::unique_ptr Parser::parseCompoundExpression() return expr; } -std::unique_ptr Parser::parseExponentiation() +std::unique_ptr Parser::parseArithmetic() { std::unique_ptr left = parseCompoundExpression(); - for (;;) { - auto &tok_op = tokens[i]; - if (tokens[i].type == EXP) { - ++i; - std::unique_ptr right = parseCompoundExpression(); - left.reset(new ExponentiationExpression(tok_op, std::move(left), std::move(right))); - } else { - return left; - } - } -} - -std::unique_ptr Parser::parseMultiplication() -{ - std::unique_ptr left = parseExponentiation(); - for (;;) { - auto &tok_op = tokens[i]; - switch (tokens[i].type) { - case TIMES: { - ++i; - std::unique_ptr right = parseExponentiation(); - left.reset(new MultiplicationExpression(tok_op, std::move(left), std::move(right))); - break; - } - case DIVIDE: { - ++i; - std::unique_ptr right = parseExponentiation(); - left.reset(new DivisionExpression(tok_op, std::move(left), std::move(right))); - break; - } - case INTDIV: { + auto &tok_op = tokens[i]; + switch (tokens[i].type) { + case PLUS: { + while (tokens[i].type == PLUS) { + auto &tok_op = tokens[i]; ++i; - std::unique_ptr right = parseExponentiation(); - left.reset(new IntegerDivisionExpression(tok_op, std::move(left), std::move(right))); - break; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new AdditionExpression(tok_op, std::move(left), std::move(right))); } - case MOD: { + if (tokens[i].type == MINUS) { + auto &tok_op = tokens[i]; ++i; - std::unique_ptr right = parseExponentiation(); - left.reset(new ModuloExpression(tok_op, std::move(left), std::move(right))); - break; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new SubtractionExpression(tok_op, std::move(left), std::move(right))); } - default: - return left; + break; } - } -} - -std::unique_ptr Parser::parseAddition() -{ - std::unique_ptr left = parseMultiplication(); - for (;;) { - auto &tok_op = tokens[i]; - switch (tokens[i].type) { - case PLUS: { + case CONCAT: { + while (tokens[i].type == CONCAT) { + auto &tok_op = tokens[i]; ++i; - std::unique_ptr right = parseMultiplication(); - left.reset(new AdditionExpression(tok_op, std::move(left), std::move(right))); - break; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new ConcatenationExpression(tok_op, std::move(left), std::move(right))); } - case MINUS: { + break; + } + case TIMES: { + while (tokens[i].type == TIMES) { + auto &tok_op = tokens[i]; ++i; - std::unique_ptr right = parseMultiplication(); - left.reset(new SubtractionExpression(tok_op, std::move(left), std::move(right))); - break; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new MultiplicationExpression(tok_op, std::move(left), std::move(right))); } - case CONCAT: { - ++i; - std::unique_ptr right = parseMultiplication(); - left.reset(new ConcatenationExpression(tok_op, std::move(left), std::move(right))); - break; + auto &tok_op = tokens[i]; + switch (tokens[i].type) { + case DIVIDE: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new DivisionExpression(tok_op, std::move(left), std::move(right))); + break; + } + case INTDIV: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new IntegerDivisionExpression(tok_op, std::move(left), std::move(right))); + break; + } + case MOD: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new ModuloExpression(tok_op, std::move(left), std::move(right))); + break; + } + default: + break; } - default: - return left; + break; } + case MINUS: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new SubtractionExpression(tok_op, std::move(left), std::move(right))); + break; + } + case DIVIDE: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new DivisionExpression(tok_op, std::move(left), std::move(right))); + break; + } + case INTDIV: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new IntegerDivisionExpression(tok_op, std::move(left), std::move(right))); + break; + } + case MOD: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new ModuloExpression(tok_op, std::move(left), std::move(right))); + break; + } + case EXP: { + ++i; + std::unique_ptr right = parseCompoundExpression(); + left.reset(new ExponentiationExpression(tok_op, std::move(left), std::move(right))); + break; + } + default: + return left; } + return left; } std::unique_ptr Parser::parseComparison() { - std::unique_ptr left = parseAddition(); + std::unique_ptr left = parseArithmetic(); std::vector> comps; Token tok_comp; while (tokens[i].type == EQUAL || tokens[i].type == NOTEQUAL @@ -881,7 +895,7 @@ std::unique_ptr Parser::parseComparison() } ComparisonExpression::Comparison comp = comparisonFromToken(tok_comp); ++i; - std::unique_ptr right = parseAddition(); + std::unique_ptr right = parseArithmetic(); comps.emplace_back(new ChainedComparisonExpression::Part(tok_comp, comp, std::move(right))); } if (comps.empty()) { diff --git a/t/arithmetic2.neon b/t/arithmetic2.neon index 5e83db1abb..a685487f17 100644 --- a/t/arithmetic2.neon +++ b/t/arithmetic2.neon @@ -7,5 +7,5 @@ print(str(a + a + a)) print(str(a * a * a)) --= 8 -print(str(a ^ a ^ a)) +print(str((a ^ a) ^ a)) --= 16 diff --git a/t/assert-fail.neon b/t/assert-fail.neon index b0761cd9ef..196030e9d8 100644 --- a/t/assert-fail.neon +++ b/t/assert-fail.neon @@ -1,9 +1,9 @@ -- SKIP LET n: Number := 5 -ASSERT (n - 2*(n+1)) = 0 -- failing assert +ASSERT (n - (2*(n+1))) = 0 -- failing assert --~ Assert failed \(t[\\/]assert-fail.neon line 3\): ---! ASSERT (n - 2*(n+1)) = 0 -- failing assert +--! ASSERT (n - (2*(n+1))) = 0 -- failing assert --! Assert expression dump: --! n is 5 --! n+1 is 6 diff --git a/t/interface.neon b/t/interface.neon index b397ed96aa..14cf4e4e42 100644 --- a/t/interface.neon +++ b/t/interface.neon @@ -23,7 +23,7 @@ TYPE Circle IS CLASS IMPLEMENTS Shape END CLASS FUNCTION Circle.area(self: VALID POINTER TO Circle): Number - RETURN Pi * self->radius^2 + RETURN Pi * (self->radius^2) END FUNCTION FUNCTION Circle.perimeter(self: VALID POINTER TO Circle): Number diff --git a/t/textio-random.neon b/t/textio-random.neon index 9f210b1483..d5645904b8 100644 --- a/t/textio-random.neon +++ b/t/textio-random.neon @@ -4,7 +4,7 @@ IMPORT textio VAR s := "" FOR i := 1 TO 100000 DO - s.append(string.fromCodePoint(32 + random.uint32() MOD 96)) + s.append(string.fromCodePoint(32 + (random.uint32() MOD 96))) END FOR VAR r: textio.OpenResult := textio.open("tmp/textio-test.tmp", textio.Mode.write) CHECK r ISA textio.OpenResult.file ELSE