1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package jTrolog.parser;
23
24 import java.io.Serializable;
25
26
27
28
29 @SuppressWarnings({ "serial" })
30 class Token implements Serializable {
31
32 String seq;
33
34 int type;
35
36 static final int ATOM = 'A';
37 static final int SQ_SEQUENCE = 'S';
38 static final int DQ_SEQUENCE = 'D';
39 static final int OPERATOR = 'O';
40 static final int FUNCTOR = 'F';
41
42 static final int ATOM_OPERATOR = 'B';
43 static final int ATOM_FUNCTOR = 'a';
44 static final int OPERATOR_FUNCTOR = 'p';
45 static final int SQ_FUNCTOR = 's';
46
47 static final int VARIABLE = 'v';
48 static final int EOF = 'e';
49 static final int INTEGER = 'i';
50 static final int FLOAT = 'f';
51
52 public Token(String s, int t) {
53 seq = s.intern();
54 type = t;
55 }
56
57 public String getValue() {
58 return seq;
59 }
60
61 public boolean isOperator(boolean commaIsEndMarker) {
62 if (commaIsEndMarker && ",".equals(seq))
63 return false;
64 return type == OPERATOR || type == ATOM_OPERATOR || type == OPERATOR_FUNCTOR;
65 }
66
67 public boolean isFunctor() {
68 return type == FUNCTOR || type == ATOM_FUNCTOR || type == SQ_FUNCTOR || type == OPERATOR_FUNCTOR;
69 }
70
71 public boolean isNumber() {
72 return type == INTEGER || type == FLOAT;
73 }
74
75 boolean isEOF() {
76 return type == EOF;
77 }
78
79 boolean isType(int type) {
80 return this.type == type;
81 }
82
83 boolean isAtom() {
84 return type == ATOM || type == ATOM_OPERATOR || type == ATOM_FUNCTOR || type == SQ_FUNCTOR || type == SQ_SEQUENCE || type == DQ_SEQUENCE;
85 }
86 }