-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeger.java
More file actions
146 lines (122 loc) · 5.25 KB
/
Deger.java
File metadata and controls
146 lines (122 loc) · 5.25 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import org.antlr.runtime.tree.*;
abstract class Deger {
public String tip() { throw new RuntimeException("unimplemented"); }
public String metin() { throw new RuntimeException("unimplemented"); }
public Deger topla(Deger deger) { throw new RuntimeException("unimplemented"); }
public Deger cikar(Deger deger) { throw new RuntimeException("unimplemented"); }
public Deger carp(Deger deger) { throw new RuntimeException("unimplemented"); }
public Deger bol(Deger deger) { throw new RuntimeException("unimplemented"); }
public Deger kalan(Deger deger) { throw new RuntimeException("unimplemented"); }
public Deger eksi() { throw new RuntimeException("unimplemented"); }
public DMantiksal esittir(Deger deger) { throw new RuntimeException("unimplemented"); }
public DMantiksal kucuktur(Deger deger) { throw new RuntimeException("unimplemented"); }
public DMantiksal buyuktur(Deger deger) { throw new RuntimeException("unimplemented"); }
public DMantiksal mantiksalDeger() { return mantiksal(true); }
static DMantiksal mantiksal(boolean b) {
return b ? DMantiksal.EVET : DMantiksal.HAYIR;
}
}
class DMantiksal extends Deger {
private boolean deger;
private DMantiksal(boolean deger) {
this.deger = deger;
}
public boolean deger() {
return deger;
}
public static final DMantiksal EVET = new DMantiksal(true);
public static final DMantiksal HAYIR = new DMantiksal(false);
public String tip() { return "Mantiksal"; }
public String metin() { return deger ? "evet" : "hayir"; }
public DMantiksal esittir(Deger deger) {
if (deger instanceof DMantiksal)
return mantiksal(this.deger == ((DMantiksal)deger).deger);
return mantiksal(false);
}
public DMantiksal mantiksalDeger() { return this; }
public static DMantiksal degil(Deger deger) {
return mantiksal(! deger.mantiksalDeger().deger);
}
public static DMantiksal ve(Deger sol, Deger sag) {
return mantiksal(sol.mantiksalDeger().deger && sag.mantiksalDeger().deger);
}
public static DMantiksal veya(Deger sol, Deger sag) {
return mantiksal(sol.mantiksalDeger().deger || sag.mantiksalDeger().deger);
}
}
class DTanimsiz extends Deger {
public static final DTanimsiz TANIMSIZ = new DTanimsiz();
private DTanimsiz() {}
public String tip() { return "Tanimsiz"; }
public String metin() { return "tanimsiz"; }
public DMantiksal mantiksalDeger() { return mantiksal(false); }
public DMantiksal esittir(Deger deger) { return mantiksal(deger==TANIMSIZ); }
}
class DTamSayi extends Deger {
private int sayi;
public DTamSayi(int sayi) {
this.sayi = sayi;
}
public int sayi() {
return sayi;
}
public String tip() { return "DTamSayi"; }
public String metin() { return "" + sayi; }
public Deger topla(Deger deger) {
if (deger instanceof DTamSayi)
return new DTamSayi(sayi + ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public Deger cikar(Deger deger) {
if (deger instanceof DTamSayi)
return new DTamSayi(sayi - ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public Deger carp(Deger deger) {
if (deger instanceof DTamSayi)
return new DTamSayi(sayi * ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public Deger bol(Deger deger) {
if (deger instanceof DTamSayi)
return new DTamSayi(sayi / ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public Deger kalan(Deger deger) {
if (deger instanceof DTamSayi)
return new DTamSayi(sayi % ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public Deger eksi() {
return new DTamSayi(-sayi);
}
public DMantiksal esittir(Deger deger) {
if (deger instanceof DTamSayi)
return mantiksal(sayi == ((DTamSayi)deger).sayi);
return mantiksal(false);
}
public DMantiksal kucuktur(Deger deger) {
if (deger instanceof DTamSayi)
return mantiksal(sayi < ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public DMantiksal buyuktur(Deger deger) {
if (deger instanceof DTamSayi)
return mantiksal(sayi > ((DTamSayi)deger).sayi);
throw new RuntimeException("gecersiz islem");
}
public DMantiksal mantiksalDeger() { return mantiksal(sayi != 0); }
}
class DFonksiyon extends Deger {
public CalismaOrtami ortam;
public Tree parametreIsimleri;
public Tree komutlar;
public DFonksiyon(CalismaOrtami ortam, Tree parametreIsimleri, Tree komutlar) {
this.ortam = ortam;
this.parametreIsimleri = parametreIsimleri;
this.komutlar = komutlar;
}
public String tip() { return "Fonksiyon"; }
public String metin() { return "[fonksiyon]"; }
public DMantiksal esittir(Deger deger) { return mantiksal(deger == this); }
}