blob: 947f1de5f26c0f7a2a3fcc82e4dce367492314bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
using System;
namespace ALGA {
public class Operand : Expression {
private char operand;
private Expression left, right;
public Operand(char operand, Expression left, Expression right) {
this.operand = operand;
this.left = left;
this.right = right;
}
public override int evaluate() {
int a = left.evaluate();
int b = right.evaluate();
switch (operand) {
case '+': return a + b;
case '*': return a * b;
}
throw new NotImplementedException();
}
public override string ToString() {
return $"({left.ToString()}{operand}{right.ToString()})";
}
}
}
|