Компиляторы 4 лаба (7) Token (все)

 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
public enum DomainTag {
IDENT, NUMBER, OPER, END_OF_PROGRAM
}
public class Fragment {
private Position starting, following;
public Fragment (Position starting , Position following)
{
this.starting = starting;
this.following = following;
}
public String toString()
{
return starting + " - " + following;
}
}
public abstract class Token {
private DomainTag tag;
private Fragment coords;
protected Token(DomainTag tag, Position starting, Position following) {
this.tag = tag;
coords = new Fragment(starting, following);
}
public DomainTag Tag() { return tag; }
public Fragment Coords() { return coords; }
}
public class IdentToken extends Token {
public String Code;
public IdentToken(String code, Position starting, Position following){
super(DomainTag.IDENT, starting, following);
Code = code;
}
}
public class NumberToken extends Token {
public long Value;
public NumberToken(long val, Position starting, Position following){
super(DomainTag.NUMBER, starting, following);
Value = val;
}
}
class SpecToken extends Token {
public SpecToken(DomainTag tag , Position starting , Position following ){
super( tag , starting , following );
}
}
public class OperToken extends Token {
public String Num;
public OperToken(String num, Position starting, Position following){
super(DomainTag.OPER, starting, following);
Num = num;
}
}